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
31dc5ca0
Commit
31dc5ca0
authored
Feb 17, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the first goniometry rewrite rule.
parent
28644d89
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
src/rules/goniometry.py
src/rules/goniometry.py
+32
-0
tests/test_rules_goniometry.py
tests/test_rules_goniometry.py
+15
-0
No files found.
src/rules/goniometry.py
0 → 100644
View file @
31dc5ca0
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
Scope
,
\
OP_ADD
,
OP_POW
,
OP_MUL
,
OP_SIN
,
OP_COS
,
OP_TAN
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
def
match_add_quadrants
(
node
):
"""
sin(x) ^ 2 + cos(x) ^ 2 -> 1
"""
assert
node
.
is_op
(
OP_ADD
)
p
=
[]
sin_q
,
cos_q
=
node
if
sin_q
.
is_power
(
2
)
and
cos_q
.
is_power
(
2
):
sin
,
cos
=
sin_q
[
0
],
cos_q
[
0
]
if
sin
.
is_op
(
OP_SIN
)
and
cos
.
is_op
(
OP_COS
):
p
.
append
(
P
(
node
,
add_quadrants
,
()))
return
p
def
add_quadrants
(
root
,
args
):
"""
sin(x) ^ 2 + cos(x) ^ 2 -> 1
"""
return
L
(
1
)
MESSAGES
[
add_quadrants
]
=
_
(
'Add the sinus and cosinus quadrants to 1.'
)
tests/test_rules_goniometry.py
0 → 100644
View file @
31dc5ca0
from
src.rules.goniometry
import
match_add_quadrants
,
add_quadrants
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
class
TestRulesGoniometry
(
RulesTestCase
):
def
test_match_add_quadrants
(
self
):
root
=
tree
(
'sin(x) ^ 2 + cos(x) ^ 2'
)
possibilities
=
match_add_quadrants
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
add_quadrants
,
())])
def
test_add_quadrants
(
self
):
root
=
tree
(
'sin(x) ^ 2 + cos(x) ^ 2'
)
self
.
assertEqual
(
add_quadrants
(
root
,
()),
1
)
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