[Edu-sig] __init__ returning subclasses

Kirby Urner urnerk@qwest.net
Sun, 21 Oct 2001 22:36:10 -0700


>
>It's probably obvious from my examples that I'm interested in computer
>algebra.  I've found a few python CA systems: fewer than I'd expect,
>more than I'd like to evaluate one by one, none well documented enough
>for me to guess how easy to use/featureful they are.  Anybody got any
>advice/pointers for good, extensible computer algebra implementations
>under python?
>
>Thanks,
>Jay

Although by no means a full fledged CA system, I've done
some stuff with algebra in Python.  Here's an example
session:

  >>> from mathobjects import *

  >>> p = Poly([3,4,5])
  >>> p
  3*x**2 + 4*x + 5

  >>> q = Poly([1,2,3,4])
  >>> q
  x**3 + 2*x**2 + 3*x + 4
  >>> q.deriv()
  3*x**2 + 4*x + 3

  >>> p*q
  3*x**5 + 10*x**4 + 22*x**3 + 34*x**2 + 31*x + 20
  >>> p(10)
  345L

  >>> F = Fraction
  >>> f = F(1,2)
  >>> f
  (1/2)

  >>> f*p
  (3/2)*x**2 + 2*x + (5/2)

  >>> p.roots()
  [(-0.66666666666666663+1.1055415967851332j),
  (-0.66666666666666663-1.1055415967851332j)]

  >>> A = Sqmatrix([[F(1,2),1],[F(3/2),-2]])
  >>> A
  [(1/2), 1]
  [1, -2]
  >>> A.inverse()
  [1, (1/2)]
  [(1/2), (-1/4)]

[q.roots() caused an error -- used to work but I
started stripping out conversions to longs when 2.2
made this automatic, then putting back in when I
decided to keep 2.1.1 back compatibility, and
there's still something broken around here.  Hope
to fix it soon].

The current source code is at
http://www.oregon-tips.com/  under Curricula | Python.

There's also a bernoulli numbers piece.

Kirby