Coolest Python recipe of all time

geremy condra debatem1 at gmail.com
Tue May 3 12:51:20 EDT 2011


On Tue, May 3, 2011 at 8:49 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> 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.

Or just use a gauss-jordan solver, which has the advantage of being
easy to explain and possible to verify by hand on small instances.

Geremy Condra



More information about the Python-list mailing list