[Edu-sig] Algebra + Python

Kirby Urner pdx4d@teleport.com
Tue, 01 May 2001 08:05:53 -0700


One change I've already made to the Polynomial code 
(and uploaded):  compute the string version only once,
upon initialization, and then have __call__ simply 
evaluate that string, like this:

    def __init__(self, coeffs):
        self.coeffs = []
        # ... skip some lines

        self.strview = self.express() # <-- new
 
    def __call__(self,x):
        return eval(self.strview)  # short!

    def __repr__(self):
        return self.strview        # no need to recompute
    
    def express(self):
        """
        Represent self as an algebraic expression
        """
        ...

Kirby