mjkaufer / CoefficientCalculator

:1234::heavy_multiplication_x: Calculate coefficients of multinomials

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CoefficientCalculator

This is a tool to compute the coefficients of the products of multinomial expressions! The inspiration behind this is here

Usage

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 like x or y^5; it's a symbol raised to an exponent
  • MultiTerm represents a product of Term objects, multiplied by a scalar such as 23 * x * y^5
    • You can represent a pure scalar with MultiTerm; the Scalar class is a synonym for an 'empty' MultiTerm object
  • Expression is a sum of MultiTerm objects
    • The equation 1 + 3x + 2*x*y looks like this
    • Expression([Scalar(1), MultiTerm(Term("x"), 3), MultiTerm([Term("x"), Term("y")], 2)])

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

Testing

Just run python -m unittest test/* in the main directory

TODO

  • 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

About

:1234::heavy_multiplication_x: Calculate coefficients of multinomials


Languages

Language:Python 100.0%