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
3c9a4762
Commit
3c9a4762
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of kompiler.org:trs
parents
1a7cebab
805a9166
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/rules/fractions.py
+4
-3
4 additions, 3 deletions
src/rules/fractions.py
src/rules/numerics.py
+1
-1
1 addition, 1 deletion
src/rules/numerics.py
tests/test_node.py
+1
-0
1 addition, 0 deletions
tests/test_node.py
tests/test_rules_numerics.py
+1
-0
1 addition, 0 deletions
tests/test_rules_numerics.py
with
7 additions
and
4 deletions
src/rules/fractions.py
+
4
−
3
View file @
3c9a4762
...
...
@@ -140,9 +140,10 @@ MESSAGES[equalize_denominators] = _('Equalize the denominators of division'
def
add_nominators
(
root
,
args
):
"""
a / b + c / b -> (a + c) / b
a / -b + c / -b -> (a + c) / -b
a / -b - c / -b -> (a - c) / -b
a / b + c / b -> (a + c) / b
a / b - c / b -> (a - c) / b
-(a / b) + c / b -> -((a + c) / b)
-(a / b) - c / b -> (c - a) / -b
"""
# TODO: is 'add' Appropriate when rewriting to "(a + (-c)) / b"?
ab
,
cb
=
args
...
...
This diff is collapsed.
Click to expand it.
src/rules/numerics.py
+
1
−
1
View file @
3c9a4762
...
...
@@ -18,7 +18,7 @@ def add_numerics(root, args):
n0
,
n1
,
c0
,
c1
=
args
if
c0
.
is_op
(
OP_NEG
):
c0
=
(
-
c0
[
0
].
value
)
c0
=
-
c0
[
0
].
value
else
:
c0
=
c0
.
value
...
...
This diff is collapsed.
Click to expand it.
tests/test_node.py
+
1
−
0
View file @
3c9a4762
...
...
@@ -34,6 +34,7 @@ class TestNode(RulesTestCase):
self
.
assertTrue
(
N
(
'
+
'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertTrue
(
N
(
'
-
'
,
N
(
'
+
'
,
*
self
.
l
[:
2
])).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
N
(
'
-
'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
self
.
l
[
0
].
is_op_or_negated
(
OP_ADD
))
def
test_is_leaf
(
self
):
self
.
assertTrue
(
L
(
2
).
is_leaf
())
...
...
This diff is collapsed.
Click to expand it.
tests/test_rules_numerics.py
+
1
−
0
View file @
3c9a4762
...
...
@@ -17,6 +17,7 @@ class TestRulesNumerics(RulesTestCase):
def
test_add_numerics_negations
(
self
):
l0
,
a
,
l1
=
tree
(
'
1,a,2
'
)
self
.
assertEqual
(
add_numerics
(
-
l0
+
l1
,
(
-
l0
,
l1
,
-
L
(
1
),
L
(
2
))),
1
)
self
.
assertEqual
(
add_numerics
(
l0
+
-
l1
,
(
l0
,
-
l1
,
L
(
1
),
-
L
(
2
))),
-
1
)
self
.
assertEqual
(
add_numerics
(
l0
+
a
+
-
l1
,
(
l0
,
-
l1
,
L
(
1
),
-
L
(
2
))),
L
(
-
1
)
+
a
)
...
...
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