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
e8ab5c1c
Commit
e8ab5c1c
authored
12 years ago
by
Taddeus Kroes
Committed by
Taddeüs Kroes
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added standard radians for pi.
parent
69c3cd5d
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
+12
-9
12 additions, 9 deletions
src/rules/goniometry.py
tests/test_rules_goniometry.py
+13
-1
13 additions, 1 deletion
tests/test_rules_goniometry.py
with
25 additions
and
10 deletions
src/rules/goniometry.py
+
12
−
9
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}.
'
)
This diff is collapsed.
Click to expand it.
tests/test_rules_goniometry.py
+
13
−
1
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
)
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