python 2.7 - How can you structure a script to identify like algebraic terms? -


i'm trying write script in way represents algebraic expressions, , i'm trying make general possible can accommodate, eventually, things multivariable expressions, e.g. xy^2 = z , other things trig functions. however, need script able simplify expressions, e.g. simplifying x^2 + 2x^2 = 3x^2 , in order need recognize terms. however, in order recognize terms need able tell me when 2 expressions identical, if don't same. instance need == defined in such way computer know (x^2)^2 x^4.

now far, way can see make computer know when 2 algebraic expressions identical this, try create kind of "normal form" expressions, , compare normal forms. instance, if distribute exponents on multiplication, multiply powers of sums, distribute multiplication on addition, , calculate simple expressions of numbers, might @ least close normal form. example normal form of (x^2)^2 x^4 , normal form of x^4 x^4. since have same normal form, computer can tell me they're equivalent expressions. normal form of (2x)^2+x^2 4x^2+x^2 , wouldn't recognize normal form same normal form of 5x^2, though.

i'm thinking, @ stage try define "weak" notion of equality, of equality of normal-form-components. use notion of equality, group terms in normal form, , me more universally correct normal form.

but of sounds absolute ton of work. far i've defined classes expressions, have subclasses of variables, sums, products, powers, , on, , right i'm 1/4 of way through defining function produce normal form of power object--i haven't begun on normal form sum or product class--and code many pages long, , i'm still not sure it'll work way want to.

so question is, how accomplish goal? current method work? know how software wolfram|alpha or sympy package accomplish functionality?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -