AUTHOR: Timothy Clemans, [email protected]

Support for elementary mathematics in SAGE is currently very limited. I have done little bit of work on supporting equations for Python. I want to create a pure Python library of classes around expressions and equations. This way it could be included in SAGE, [http://code.google.com/p/sympy/ Sympy], and a standalone web server package just for elementary mathematics education.

The lead implementer of basic symbolic computation in SAGE is Bobby Moretti. He will be giving a short [http://sage.math.washington.edu/home/moretti/days3/talks/calculus.pdf talk] on work in this area at SAGE Days 3. Neither SAGE nor Sympy support equations.

I started trying to support equations in SAGE using strings. That is a very bad idea and string input should be parsed at the interface level. Personally I think a Python Elementary Algebra package should be composed of several hundred classes. Examples of these classes could be variable, independent variable, dependent variable, coefficient, term, expression, equation, linear equation, equation_of_line, equation_of_line_in_slope_intercept_form, or quadratic equation class.

For example lets say you have the following system of linear equations that you want to solve using elimination:

- (equation1) 2*x + 3*y = 1
- (equation2) -x + y = -3

class line_equation_in_general_form(object): def __init__(self,A,B,C): self.A = A self.B = B self.C = C def __str__(self): return '%dx + %dy == %d' % (self.A,self.B,self.C) __repr__ = __str__ def __add__(self,other): return self.__class__(self.A+other.A,self.B+other.B,self.C+other.C) def __mul__(self,n): return self.__class__(self.A*n,self.B*n,self.C*n)

equation1 = line_equation_in_general_form(2,3,1) equation2 = line_equation_in_general_form(-1,1,-3) equation1 + equation2*2

0x + 5y == -5

Another example is about building terms, which could lead to expressions and in turn equations.

class Term(object): def __init__(self,coefficient,variable_degree_dictionary): self.coefficient = coefficient self.vdd_input = variable_degree_dictionary self.variable_degree_pairs = [] for each_variable_key in sorted(self.vdd_input): if self.vdd_input[each_variable_key] != 0: self.variable_degree_pairs.append((each_variable_key,self.vdd_input[each_variable_key])) def __str__(self): string = str(self.coefficient) for i in range(len(self.variable_degree_pairs)): if self.variable_degree_pairs[i][1] == 1: string += '*%s' % (str(self.variable_degree_pairs[i][0])) else: string += '*%s**%s' % (str(self.variable_degree_pairs[i][0]),str(self.variable_degree_pairs[i][1])) return string __repr__ = __str__ def __add__(self,other): if self.variable_degree_pairs == other.variable_degree_pairs: if type(self.coefficient) == int or type(self.coefficient) == float: if type(other.coefficient) == int or type(other.coefficient) == float: return Term(self.coefficient + other.coefficient,self.vdd_input)

term1 = Term(3,{'y':3,'x':1}); term1

3*x*y**3

term2 = Term(7,{'x':1,'y':3}); term2

7*x*y**3

term1 + term2

10*x*y**3

So I'm trying to build a Python elementary mathematics package not a SAGE package. I will probably look at supporting classification of numbers by natural, integer, rational, real, and complex in a subset setup allowing the teacher to restrict her students by grade level.