Пример #1
0
 def factorial_divide(self, p, q, digits):
     if p == q or not self.integer_check(p) or not self.integer_check(q):
         return
     x = int(p)
     y = int(q)
     if x < y:
         x, y = y, x
         p, q = q, p
     if x <= self.MAX_FACTORIAL or y <= 2 or x - y == 1 or (
         (x - y) * (math.log2(x) + math.log2(y)) > self.MAX_DIGITS << 1):
         return
     result = reduce(operator.mul, range(x, y, -1))
     p_factorial = Expression.factorial(p)
     q_factorial = Expression.factorial(q)
     self.check(self.constructor(result), digits,
                Expression.divide(p_factorial, q_factorial))
     if digits != self.max_depth and self.solutions[q][0] == 1:
         self.check(
             self.constructor(result - 1), digits + 1,
             Expression.divide(
                 Expression.subtract(p_factorial, q_factorial),
                 q_factorial))
         self.check(
             self.constructor(result + 1), digits + 1,
             Expression.divide(Expression.add(p_factorial, q_factorial),
                               q_factorial))
Пример #2
0
 def add(self, p, q, digits):
     result = p + q
     if result is not None:
         self.check(result, digits, Expression.add(p, q))
Пример #3
0
 def add(self, p, q, digits):
     self.check(p + q, digits, Expression.add(p, q))