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
4c4344ae
Commit
4c4344ae
authored
Mar 28, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rule that generates a quadrants addition.
parent
9396116f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
src/rules/goniometry.py
src/rules/goniometry.py
+24
-4
tests/test_rules_goniometry.py
tests/test_rules_goniometry.py
+12
-2
No files found.
src/rules/goniometry.py
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)
...
...
tests/test_rules_goniometry.py
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
]
...
...
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