Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
9396116f
Commit
9396116f
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added negation checks to sinus + cosinus quadrants rule.
parent
8ce109d8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rules/goniometry.py
+18
-8
18 additions, 8 deletions
src/rules/goniometry.py
tests/test_rules_goniometry.py
+29
-5
29 additions, 5 deletions
tests/test_rules_goniometry.py
with
47 additions
and
13 deletions
src/rules/goniometry.py
+
18
−
8
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
----+---+-----------+-----------+-----------+-------
...
...
This diff is collapsed.
Click to expand it.
tests/test_rules_goniometry.py
+
29
−
5
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
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment