Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
9396116f
Commit
9396116f
authored
Mar 28, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added negation checks to sinus + cosinus quadrants rule.
parent
8ce109d8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
13 deletions
+47
-13
src/rules/goniometry.py
src/rules/goniometry.py
+18
-8
tests/test_rules_goniometry.py
tests/test_rules_goniometry.py
+29
-5
No files found.
src/rules/goniometry.py
View file @
9396116f
from
itertools
import
permutations
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_ADD
,
OP_MUL
,
\
OP_DIV
,
OP_SIN
,
OP_COS
,
OP_TAN
,
OP_SQRT
,
PI
,
TYPE_OPERATOR
,
sin
,
cos
OP_DIV
,
OP_SIN
,
OP_COS
,
OP_TAN
,
OP_SQRT
,
PI
,
TYPE_OPERATOR
,
sin
,
cos
,
\
Scope
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
...
...
@@ -11,13 +14,16 @@ def match_add_quadrants(node):
assert
node
.
is_op
(
OP_ADD
)
p
=
[]
s
in_q
,
cos_q
=
node
s
cope
=
Scope
(
node
)
if
sin_q
.
is_power
(
2
)
and
cos_q
.
is_power
(
2
):
sinus
,
cosinus
=
sin_q
[
0
],
cos_q
[
0
]
for
sin_q
,
cos_q
in
permutations
(
scope
,
2
):
if
sin_q
.
is_power
(
2
)
and
cos_q
.
is_power
(
2
)
\
and
not
sin_q
.
negated
and
not
cos_q
.
negated
:
s
,
c
=
sin_q
[
0
],
cos_q
[
0
]
if
sinus
.
is_op
(
OP_SIN
)
and
cosinus
.
is_op
(
OP_COS
):
p
.
append
(
P
(
node
,
add_quadrants
,
()))
if
s
.
is_op
(
OP_SIN
)
and
c
.
is_op
(
OP_COS
)
and
not
s
.
negated
\
and
not
c
.
negated
and
s
[
0
]
==
c
[
0
]:
p
.
append
(
P
(
node
,
add_quadrants
,
(
scope
,
sin_q
,
cos_q
)))
return
p
...
...
@@ -26,7 +32,11 @@ def add_quadrants(root, args):
"""
sin(t) ^ 2 + cos(t) ^ 2 -> 1
"""
return
L
(
1
)
scope
,
s
,
c
=
args
scope
.
replace
(
s
,
L
(
1
))
scope
.
remove
(
c
)
return
scope
.
as_nary_node
()
MESSAGES
[
add_quadrants
]
=
_
(
'Add the sinus and cosinus quadrants to 1.'
)
...
...
@@ -130,7 +140,7 @@ CONSTANTS = {
def
match_standard_radian
(
node
):
"""
Apply a direct constant calculation from the constants table
.
Apply a direct constant calculation from the constants table
:
| 0 | pi / 6 | pi / 4 | pi / 3 | pi / 2
----+---+-----------+-----------+-----------+-------
...
...
tests/test_rules_goniometry.py
View file @
9396116f
...
...
@@ -2,7 +2,7 @@
from
src.rules.goniometry
import
match_add_quadrants
,
add_quadrants
,
\
match_negated_parameter
,
negated_sinus_parameter
,
is_pi_frac
,
\
negated_cosinus_parameter
,
match_standard_radian
,
standard_radian
from
src.node
import
PI
,
OP_SIN
,
OP_COS
,
OP_TAN
,
sin
,
cos
,
tan
from
src.node
import
PI
,
OP_SIN
,
OP_COS
,
OP_TAN
,
sin
,
cos
,
tan
,
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
from
src.rules
import
goniometry
...
...
@@ -15,12 +15,36 @@ class TestRulesGoniometry(RulesTestCase):
self
.
assertEqual
(
doctest
.
testmod
(
m
=
goniometry
)[
0
],
0
)
def
test_match_add_quadrants
(
self
):
root
=
tree
(
'sin(t) ^ 2 + cos(t) ^ 2'
)
possibilities
=
match_add_quadrants
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
add_quadrants
,
())])
s
,
c
=
root
=
tree
(
'sin(t) ^ 2 + cos(t) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[
P
(
root
,
add_quadrants
,
(
Scope
(
root
),
s
,
c
))])
c
,
s
=
root
=
tree
(
'cos(t) ^ 2 + sin(t) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[
P
(
root
,
add_quadrants
,
(
Scope
(
root
),
s
,
c
))])
(
s
,
a
),
c
=
root
=
tree
(
'sin(t) ^ 2 + a + cos(t) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[
P
(
root
,
add_quadrants
,
(
Scope
(
root
),
s
,
c
))])
(
s
,
c0
),
c1
=
root
=
tree
(
'sin(t) ^ 2 + cos(t) ^ 2 + cos(t) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[
P
(
root
,
add_quadrants
,
(
Scope
(
root
),
s
,
c0
)),
P
(
root
,
add_quadrants
,
(
Scope
(
root
),
s
,
c1
))])
root
=
tree
(
'sin(t) ^ 2 + cos(y) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[])
root
=
tree
(
'sin(t) ^ 2 - cos(t) ^ 2'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[])
def
test_add_quadrants
(
self
):
self
.
assertEqual
(
add_quadrants
(
None
,
()),
1
)
s
,
c
=
root
=
tree
(
'sin(t) ^ 2 + cos(t) ^ 2'
)
self
.
assertEqual
(
add_quadrants
(
root
,
(
Scope
(
root
),
s
,
c
)),
1
)
root
,
expect
=
tree
(
'cos(t) ^ 2 + a + sin(t) ^ 2, a + 1'
)
(
c
,
a
),
s
=
root
self
.
assertEqual
(
add_quadrants
(
root
,
(
Scope
(
root
),
s
,
c
)),
expect
)
def
test_match_negated_parameter
(
self
):
s
,
c
=
tree
(
'sin -t, cos -t'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment