def reduce(self, others): """ Reduce this number, along with a list of others so that all common factors are removed. """ if self == 0: if others: return [self] + others[0].reduce(others[1:]) else: return [self] common_denom = self.den for x in others: common_denom *= x.den self = self * common_denom others = [x * common_denom for x in others] gcd_ = self.num for x in others: gcd_ = gcd(gcd_, x.num) self = self.__div__(gcd_) others = [x / gcd_ for x in others] return [self] + others
def reduce(self, others): """ Reduce this number, along with a list of others so that all common factors are removed. """ if self == 0: if others: return [self] + others[0].reduce(others[1:]) else: return [self] common_denom = self.den for x in others: common_denom *= x.den self = self*common_denom others = [x*common_denom for x in others] gcd_ = self.num for x in others: gcd_ = gcd(gcd_, x.num) self = self.__div__(gcd_) others = [x/gcd_ for x in others] return [self] + others
def _reduce(self): """ Reduce the values to remove any common factors. """ gcd_ = gcd(self.num, self.den) self.num /= gcd_ self.den /= gcd_