This is a tool to compute the coefficients of the products of multinomial expressions! The inspiration behind this is here
This code runs on python3 – maybe it runs on python2 but I haven't tested
There are three types of classes; Term
, MultiTerm
, and Expression
.
Term
represents something likex
ory^5
; it's a symbol raised to an exponentMultiTerm
represents a product ofTerm
objects, multiplied by a scalar such as23 * x * y^5
- You can represent a pure scalar with
MultiTerm
; theScalar
class is a synonym for an 'empty'MultiTerm
object
- You can represent a pure scalar with
Expression
is a sum ofMultiTerm
objects- The equation
1 + 3x + 2*x*y
looks like this Expression([Scalar(1), MultiTerm(Term("x"), 3), MultiTerm([Term("x"), Term("y")], 2)])
- The equation
You can compute the product of expressions and then find their coefficients via Expression.getCoefficient(MultiTerm)
. This is very useful in combinatorics problems
You can find some example usage here
Just run python -m unittest test/*
in the main directory
- Optimize
- If you only want to find the coefficient of a certain multiterm, you don't need to bother tracking multiterms with higher exponents
- If you find a set of similar expressions being multiplied together, you can use the multinomial theorem on them rather than find the coefficients by tediously multiplying them out
- This would need some abstraction around multiplying expressions together
- Make easier to use