Commit 279f4039 authored by Taddeus Kroes's avatar Taddeus Kroes

Added some goniometric matching functions.

parent 98445a0e
...@@ -12,7 +12,8 @@ from .fractions import match_constant_division, match_add_constant_fractions, \ ...@@ -12,7 +12,8 @@ from .fractions import match_constant_division, match_add_constant_fractions, \
from .negation import match_negated_factor, match_negate_polynome, \ from .negation import match_negated_factor, match_negate_polynome, \
match_negated_division match_negated_division
from .sort import match_sort_multiplicants from .sort import match_sort_multiplicants
from .goniometry import match_add_quadrants, match_negated_parameter from .goniometry import match_add_quadrants, match_negated_parameter, \
match_half_pi_subtraction
RULES = { RULES = {
OP_ADD: [match_add_numerics, match_add_constant_fractions, OP_ADD: [match_add_numerics, match_add_constant_fractions,
...@@ -27,6 +28,6 @@ RULES = { ...@@ -27,6 +28,6 @@ RULES = {
match_remove_negative_exponent, match_exponent_to_root, match_remove_negative_exponent, match_exponent_to_root,
match_extend_exponent, match_constant_exponent], match_extend_exponent, match_constant_exponent],
OP_NEG: [match_negate_polynome], OP_NEG: [match_negate_polynome],
OP_SIN: [match_negated_parameter], OP_SIN: [match_negated_parameter, match_half_pi_subtraction],
OP_COS: [match_negated_parameter], OP_COS: [match_negated_parameter, match_half_pi_subtraction],
} }
from .utils import is_fraction
from ..node import ExpressionNode as N, ExpressionLeaf as L, Scope, OP_ADD, \ from ..node import ExpressionNode as N, ExpressionLeaf as L, Scope, OP_ADD, \
OP_POW, OP_MUL, OP_SIN, OP_COS, OP_TAN OP_POW, OP_MUL, OP_SIN, OP_COS, OP_TAN, PI
from ..possibilities import Possibility as P, MESSAGES from ..possibilities import Possibility as P, MESSAGES
from ..translate import _ from ..translate import _
...@@ -82,3 +83,34 @@ def negated_cosinus_parameter(root, args): ...@@ -82,3 +83,34 @@ def negated_cosinus_parameter(root, args):
MESSAGES[negated_cosinus_parameter] = \ MESSAGES[negated_cosinus_parameter] = \
_('Remove the negation from the cosinus parameter {1}.') _('Remove the negation from the cosinus parameter {1}.')
def match_half_pi_subtraction(node):
"""
sin(pi / 2 - t) -> cos(t)
cos(pi / 2 - t) -> sin(t)
"""
assert node.is_op(OP_SIN) or node.is_op(OP_COS)
if node[0].is_op(OP_ADD):
half_pi, t = node[0]
if half_pi == L(PI) / 2:
if node.op == OP_SIN:
return [P(node, half_pi_subtraction_sinus, (t,))]
return []
def match_standard_radian(node):
"""
Apply a direct constant calculation from the following table.
| 0 | pi / 6 | pi / 4 | pi / 3 | pi / 2
----+---+-----------+-----------+-----------+-------
sin | 0 | 1/2 | sqrt(2)/2 | sqrt(3)/2 | 1
cos | 1 | sqrt(3)/2 | sqrt(2)/2 | 1/2 | 0
tan | 0 | sqrt(3)/3 | 1 | sqrt(3) | -
"""
# TODO: implement
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment