Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# mjkaufer/countStudents.py

Last active Dec 19, 2018
Count the number of students in the example in my blog
 from CoefficientCalculator import Term, MultiTerm, Expression, Scalar # Some brief terminology (no pun intended) # A term is something like x, x^2, x^3, etc. # 1 can also be a term # A multiterm is the product of several terms. Something like x * y or x * z^2 is fine # Multiterms also have constants, so 5 * x * y^3 is also a valid multiterm # Expressions are several multiterms added together. Something like (1 + x) is an expression # create classes (as in school classes, not object oriented classes) x, y, z x = Term("x") y = Term("y") z = Term("z") # w is the "global" class w = Term("w") students = [] # student a students.append(MultiTerm([x, z, w])) # student b students.append(MultiTerm([x, w])) # student c students.append(MultiTerm([x, y, z, w])) # student d students.append(MultiTerm([x, y, w])) # student e students.append(MultiTerm([y, w])) # student f students.append(MultiTerm([y, w])) # student g students.append(MultiTerm([z, w])) # student h students.append(MultiTerm([z, w])) # add a "1 + " to the start of each student's multiterm, making it an expression studentExpressions = [Expression([Scalar(), s]) for s in students] # base expression of "1" e = Expression([Scalar()]) # take the product of all the expressions for s in studentExpressions: e *= s # get the coefficient for the Thanos problem e.getCoefficient(MultiTerm([Term("x", 2), Term("y", 2), Term("z", 2), Term("w", 4)]))
to join this conversation on GitHub. Already have an account? Sign in to comment