goniometry.py 734 B

1234567891011121314151617181920212223242526272829303132
  1. from ..node import ExpressionNode as N, ExpressionLeaf as L, Scope, \
  2. OP_ADD, OP_POW, OP_MUL, OP_SIN, OP_COS, OP_TAN
  3. from ..possibilities import Possibility as P, MESSAGES
  4. from ..translate import _
  5. def match_add_quadrants(node):
  6. """
  7. sin(x) ^ 2 + cos(x) ^ 2 -> 1
  8. """
  9. assert node.is_op(OP_ADD)
  10. p = []
  11. sin_q, cos_q = node
  12. if sin_q.is_power(2) and cos_q.is_power(2):
  13. sin, cos = sin_q[0], cos_q[0]
  14. if sin.is_op(OP_SIN) and cos.is_op(OP_COS):
  15. p.append(P(node, add_quadrants, ()))
  16. return p
  17. def add_quadrants(root, args):
  18. """
  19. sin(x) ^ 2 + cos(x) ^ 2 -> 1
  20. """
  21. return L(1)
  22. MESSAGES[add_quadrants] = _('Add the sinus and cosinus quadrants to 1.')