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
4c4344ae
Commit
4c4344ae
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added rule that generates a quadrants addition.
parent
9396116f
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
+24
-4
24 additions, 4 deletions
src/rules/goniometry.py
tests/test_rules_goniometry.py
+12
-2
12 additions, 2 deletions
tests/test_rules_goniometry.py
with
36 additions
and
6 deletions
src/rules/goniometry.py
+
24
−
4
View file @
4c4344ae
...
...
@@ -17,13 +17,18 @@ def match_add_quadrants(node):
scope
=
Scope
(
node
)
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
:
if
sin_q
.
is_power
(
2
)
and
cos_q
.
is_power
(
2
):
s
,
c
=
sin_q
[
0
],
cos_q
[
0
]
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
]:
if
not
s
.
is_op
(
OP_SIN
)
or
not
c
.
is_op
(
OP_COS
)
or
s
.
negated
\
or
c
.
negated
or
s
[
0
]
!=
c
[
0
]:
continue
if
not
sin_q
.
negated
and
not
cos_q
.
negated
:
p
.
append
(
P
(
node
,
add_quadrants
,
(
scope
,
sin_q
,
cos_q
)))
elif
sin_q
.
negated
==
1
and
cos_q
.
negated
==
1
:
p
.
append
(
P
(
node
,
factor_out_quadrant_negation
,
(
scope
,
sin_q
,
cos_q
)))
return
p
...
...
@@ -42,6 +47,21 @@ def add_quadrants(root, args):
MESSAGES
[
add_quadrants
]
=
_
(
'
Add the sinus and cosinus quadrants to 1.
'
)
def
factor_out_quadrant_negation
(
root
,
args
):
"""
-sin(t) ^ 2 - cos(t) ^ 2 -> -(sin(t) ^ 2 + cos(t) ^ 2) # -> -1
"""
scope
,
s
,
c
=
args
scope
.
replace
(
s
,
-
(
+
s
+
+
c
))
scope
.
remove
(
c
)
return
scope
.
as_nary_node
()
MESSAGES
[
factor_out_quadrant_negation
]
=
_
(
'
Factor out the negations of {2}
'
\
'
and {3} to be able to reduce the quadrant addition to 1.
'
)
def
match_negated_parameter
(
node
):
"""
sin(-t) -> -sin(t)
...
...
This diff is collapsed.
Click to expand it.
tests/test_rules_goniometry.py
+
12
−
2
View file @
4c4344ae
# vim: set fileencoding=utf-8 :
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
factor_out_quadrant_negation
,
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
,
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -38,6 +39,10 @@ class TestRulesGoniometry(RulesTestCase):
root
=
tree
(
'
sin(t) ^ 2 - cos(t) ^ 2
'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[])
s
,
c
=
root
=
tree
(
'
-sin(t) ^ 2 - cos(t) ^ 2
'
)
self
.
assertEqualPos
(
match_add_quadrants
(
root
),
[
P
(
root
,
factor_out_quadrant_negation
,
(
Scope
(
root
),
s
,
c
))])
def
test_add_quadrants
(
self
):
s
,
c
=
root
=
tree
(
'
sin(t) ^ 2 + cos(t) ^ 2
'
)
self
.
assertEqual
(
add_quadrants
(
root
,
(
Scope
(
root
),
s
,
c
)),
1
)
...
...
@@ -46,6 +51,11 @@ class TestRulesGoniometry(RulesTestCase):
(
c
,
a
),
s
=
root
self
.
assertEqual
(
add_quadrants
(
root
,
(
Scope
(
root
),
s
,
c
)),
expect
)
def
test_factor_out_quadrant_negation
(
self
):
r
,
e
=
tree
(
'
-sin(t) ^ 2 - cos(t) ^ 2, -(sin(t) ^ 2 + cos(t) ^ 2)
'
)
s
,
c
=
r
self
.
assertEqual
(
factor_out_quadrant_negation
(
r
,
(
Scope
(
r
),
s
,
c
)),
e
)
def
test_match_negated_parameter
(
self
):
s
,
c
=
tree
(
'
sin -t, cos -t
'
)
t
=
s
[
0
]
...
...
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