Coolest Python recipe of all time

Terry Reedy tjreedy at udel.edu
Tue May 3 11:49:01 EDT 2011


On 5/3/2011 2:29 AM, Gregory Ewing wrote:
> Terry Reedy wrote:
>> The trick is that replacing x with j and evaluating therefore causes
>> (in Python) all the coefficients of x (now j) to be added together
>> separately from all the constant terms to reduce the linear equation
>> to a*x+b (= 0 implied).
>
> Hmmm... so if we used quaternions, could we solve systems
> of linear equations in 3 variables?

Yes and no. The use of 1*j merely collected and added together all the 
multipliers of 'x' (and all the constant terms). That is a fairly 
trivial matter of constant folding. Systems of linear equations are 
usually presented in that form already. The actual solution to the 
simple equation is in the formula x = -a/b (where a and b are the sums). 
The solution formula for three variables would be far more complex.

-- 
Terry Jan Reedy




More information about the Python-list mailing list