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
e8ab5c1c
Commit
e8ab5c1c
authored
Jun 22, 2012
by
Taddeus Kroes
Committed by
Taddeüs Kroes
Sep 13, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added standard radians for pi.
parent
69c3cd5d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
src/rules/goniometry.py
src/rules/goniometry.py
+12
-9
tests/test_rules_goniometry.py
tests/test_rules_goniometry.py
+13
-1
No files found.
src/rules/goniometry.py
View file @
e8ab5c1c
...
@@ -166,9 +166,9 @@ l0, l1, sq2, sq3 = L(0), L(1), sqrt(2), sqrt(3)
...
@@ -166,9 +166,9 @@ l0, l1, sq2, sq3 = L(0), L(1), sqrt(2), sqrt(3)
half
=
l1
/
2
half
=
l1
/
2
CONSTANTS
=
{
CONSTANTS
=
{
OP_SIN
:
[
l0
,
half
,
half
*
sq2
,
half
*
sq3
,
l1
],
OP_SIN
:
[
l0
,
half
,
half
*
sq2
,
half
*
sq3
,
l1
,
l0
],
OP_COS
:
[
l1
,
half
*
sq3
,
half
*
sq2
,
half
,
l0
],
OP_COS
:
[
l1
,
half
*
sq3
,
half
*
sq2
,
half
,
l0
,
-
l1
],
OP_TAN
:
[
l0
,
l1
/
3
*
sq3
,
l1
,
sq3
]
OP_TAN
:
[
l0
,
l1
/
3
*
sq3
,
l1
,
sq3
,
l0
]
}
}
...
@@ -176,11 +176,11 @@ def match_standard_radian(node):
...
@@ -176,11 +176,11 @@ 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
| 0 | pi / 6 | pi / 4 | pi / 3 | pi / 2
| pi
----+---+-----------+-----------+-----------+-------
----+---+-----------+-----------+-----------+-------
-+---
sin | 0 | 1/2 | sqrt(2)/2 | sqrt(3)/2 | 1
sin | 0 | 1/2 | sqrt(2)/2 | sqrt(3)/2 | 1
| 0
cos | 1 | sqrt(3)/2 | sqrt(2)/2 | 1/2 | 0
cos | 1 | sqrt(3)/2 | sqrt(2)/2 | 1/2 | 0
| -1
tan | 0 | sqrt(3)/3 | 1 | sqrt(3) | -
tan | 0 | sqrt(3)/3 | 1 | sqrt(3) | -
| 0
"""
"""
assert
node
.
type
==
TYPE_OPERATOR
and
node
.
op
in
(
OP_SIN
,
OP_COS
,
OP_TAN
)
assert
node
.
type
==
TYPE_OPERATOR
and
node
.
op
in
(
OP_SIN
,
OP_COS
,
OP_TAN
)
...
@@ -189,6 +189,9 @@ def match_standard_radian(node):
...
@@ -189,6 +189,9 @@ def match_standard_radian(node):
if
t
==
0
:
if
t
==
0
:
return
[
P
(
node
,
standard_radian
,
(
node
.
op
,
0
))]
return
[
P
(
node
,
standard_radian
,
(
node
.
op
,
0
))]
if
t
==
PI
:
return
[
P
(
node
,
standard_radian
,
(
node
.
op
,
5
))]
denoms
=
[
6
,
4
,
3
]
denoms
=
[
6
,
4
,
3
]
if
node
.
op
!=
OP_TAN
:
if
node
.
op
!=
OP_TAN
:
...
@@ -204,7 +207,7 @@ def match_standard_radian(node):
...
@@ -204,7 +207,7 @@ def match_standard_radian(node):
def
standard_radian
(
root
,
args
):
def
standard_radian
(
root
,
args
):
op
,
column
=
args
op
,
column
=
args
return
CONSTANTS
[
op
][
column
].
clone
(
)
return
CONSTANTS
[
op
][
column
].
negate
(
root
.
negated
)
MESSAGES
[
standard_radian
]
=
_
(
'Replace standard radian {0}.'
)
MESSAGES
[
standard_radian
]
=
_
(
'Replace standard radian {0}.'
)
tests/test_rules_goniometry.py
View file @
e8ab5c1c
...
@@ -109,10 +109,22 @@ class TestRulesGoniometry(RulesTestCase):
...
@@ -109,10 +109,22 @@ class TestRulesGoniometry(RulesTestCase):
self
.
assertEqualPos
(
match_standard_radian
(
t
),
\
self
.
assertEqualPos
(
match_standard_radian
(
t
),
\
[
P
(
t
,
standard_radian
,
(
OP_TAN
,
0
))])
[
P
(
t
,
standard_radian
,
(
OP_TAN
,
0
))])
root
=
tree
(
'cos pi'
)
self
.
assertEqualPos
(
match_standard_radian
(
root
),
\
[
P
(
root
,
standard_radian
,
(
OP_COS
,
5
))])
root
=
tree
(
'cos x'
)
self
.
assertEqualPos
(
match_standard_radian
(
root
),
[])
def
test_standard_radian
(
self
):
def
test_standard_radian
(
self
):
l0
,
l1
,
sq3
,
pi6
,
pi4
,
pi2
=
tree
(
'0,1,sqrt(3),1/6*pi,1/4*pi,1/2*
pi'
)
l0
,
l1
,
sq3
,
pi6
,
pi4
,
pi2
,
pi1
=
tree
(
'0,1,sqrt(3),1/6*pi,1/4*pi,1/2*pi,
pi'
)
self
.
assertEqual
(
standard_radian
(
sin
(
pi6
),
(
OP_SIN
,
1
)),
l1
/
2
)
self
.
assertEqual
(
standard_radian
(
sin
(
pi6
),
(
OP_SIN
,
1
)),
l1
/
2
)
self
.
assertEqual
(
standard_radian
(
sin
(
pi2
),
(
OP_SIN
,
4
)),
1
)
self
.
assertEqual
(
standard_radian
(
sin
(
pi2
),
(
OP_SIN
,
4
)),
1
)
self
.
assertEqual
(
standard_radian
(
cos
(
l0
),
(
OP_COS
,
0
)),
1
)
self
.
assertEqual
(
standard_radian
(
cos
(
l0
),
(
OP_COS
,
0
)),
1
)
self
.
assertEqual
(
standard_radian
(
tan
(
pi4
),
(
OP_TAN
,
3
)),
sq3
)
self
.
assertEqual
(
standard_radian
(
tan
(
pi4
),
(
OP_TAN
,
3
)),
sq3
)
self
.
assertEqual
(
standard_radian
(
sin
(
pi1
),
(
OP_SIN
,
5
)),
0
)
self
.
assertEqual
(
standard_radian
(
cos
(
pi1
),
(
OP_COS
,
5
)),
-
1
)
self
.
assertEqual
(
standard_radian
(
-
cos
(
pi1
),
(
OP_COS
,
5
)),
--
l1
)
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