Commit e8ab5c1c authored by Taddeus Kroes's avatar Taddeus Kroes Committed by Taddeüs Kroes

Added standard radians for pi.

parent 69c3cd5d
......@@ -166,9 +166,9 @@ l0, l1, sq2, sq3 = L(0), L(1), sqrt(2), sqrt(3)
half = l1 / 2
CONSTANTS = {
OP_SIN: [l0, half, half * sq2, half * sq3, l1],
OP_COS: [l1, half * sq3, half * sq2, half, l0],
OP_TAN: [l0, l1 / 3 * sq3, l1, sq3]
OP_SIN: [l0, half, half * sq2, half * sq3, l1, l0],
OP_COS: [l1, half * sq3, half * sq2, half, l0, -l1],
OP_TAN: [l0, l1 / 3 * sq3, l1, sq3, l0]
}
......@@ -176,11 +176,11 @@ def match_standard_radian(node):
"""
Apply a direct constant calculation from the constants 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) | -
| 0 | pi / 6 | pi / 4 | pi / 3 | pi / 2 | pi
----+---+-----------+-----------+-----------+--------+---
sin | 0 | 1/2 | sqrt(2)/2 | sqrt(3)/2 | 1 | 0
cos | 1 | sqrt(3)/2 | sqrt(2)/2 | 1/2 | 0 | -1
tan | 0 | sqrt(3)/3 | 1 | sqrt(3) | - | 0
"""
assert node.type == TYPE_OPERATOR and node.op in (OP_SIN, OP_COS, OP_TAN)
......@@ -189,6 +189,9 @@ def match_standard_radian(node):
if t == 0:
return [P(node, standard_radian, (node.op, 0))]
if t == PI:
return [P(node, standard_radian, (node.op, 5))]
denoms = [6, 4, 3]
if node.op != OP_TAN:
......@@ -204,7 +207,7 @@ def match_standard_radian(node):
def standard_radian(root, args):
op, column = args
return CONSTANTS[op][column].clone()
return CONSTANTS[op][column].negate(root.negated)
MESSAGES[standard_radian] = _('Replace standard radian {0}.')
......@@ -109,10 +109,22 @@ class TestRulesGoniometry(RulesTestCase):
self.assertEqualPos(match_standard_radian(t), \
[P(t, standard_radian, (OP_TAN, 0))])
root = tree('cos pi')
self.assertEqualPos(match_standard_radian(root), \
[P(root, standard_radian, (OP_COS, 5))])
root = tree('cos x')
self.assertEqualPos(match_standard_radian(root), [])
def test_standard_radian(self):
l0, l1, sq3, pi6, pi4, pi2 = tree('0,1,sqrt(3),1/6*pi,1/4*pi,1/2*pi')
l0, l1, sq3, pi6, pi4, pi2, pi1 = tree('0,1,sqrt(3),1/6*pi,1/4*pi,1/2*pi,pi')
self.assertEqual(standard_radian(sin(pi6), (OP_SIN, 1)), l1 / 2)
self.assertEqual(standard_radian(sin(pi2), (OP_SIN, 4)), 1)
self.assertEqual(standard_radian(cos(l0), (OP_COS, 0)), 1)
self.assertEqual(standard_radian(tan(pi4), (OP_TAN, 3)), sq3)
self.assertEqual(standard_radian(sin(pi1), (OP_SIN, 5)), 0)
self.assertEqual(standard_radian(cos(pi1), (OP_COS, 5)), -1)
self.assertEqual(standard_radian(-cos(pi1), (OP_COS, 5)), --l1)
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