Nuovo costruttore monomio

Ho ottimizzato il costruttore del monomio. Ora non vengono automaticamente incluse le incognite di grado minore o uguale a 0 e il valore dell’attributo “degree” indica il grado complessivo del monomio.

def __init__(self, coefficient, **kwargs):
    self.letteralPart = dict()
    for unknown in kwargs:
        # Doesn't include in the dictionary the unknowns with
        # degree < = 0
        if kwargs[unknown] > 0:
            self.letteralPart[unknown] = kwargs[unknown]

    self.coefficient = Rational(coefficient)

    # Calculates the degree of the monomial
    self.degree = 0
    for unknownDegree in self.letteralPart.values():
        self.degree += unknownDegree

Leave a Reply