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
9419b2b1
Commit
9419b2b1
authored
Feb 16, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some messages and comments to negation rules.
parent
8b4634e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
src/rules/negation.py
src/rules/negation.py
+10
-3
tests/test_rules_negation.py
tests/test_rules_negation.py
+4
-0
No files found.
src/rules/negation.py
View file @
9419b2b1
...
...
@@ -16,6 +16,9 @@ def match_negated_factor(node):
p
=
[]
scope
=
Scope
(
node
)
# FIXME: The negation that is brought outside is assigned to the first
# element in the scope during the next parsing step:
# -ab -> -(ab), but -(ab) is printed as -ab
for
factor
in
scope
:
if
factor
.
negated
:
p
.
append
(
P
(
node
,
negated_factor
,
(
scope
,
factor
)))
...
...
@@ -33,6 +36,10 @@ def negated_factor(root, args):
return
-
scope
.
as_nary_node
()
MESSAGES
[
negated_factor
]
=
\
_
(
'Bring negation of {2} to the outside of the multiplication.'
)
def
match_negate_polynome
(
node
):
"""
--a -> a
...
...
@@ -60,7 +67,7 @@ def double_negation(root, args):
return
root
.
reduce_negation
(
2
)
MESSAGES
[
double_negation
]
=
_
(
'Remove double negation in {
1
}.'
)
MESSAGES
[
double_negation
]
=
_
(
'Remove double negation in {
0
}.'
)
def
negate_polynome
(
root
,
args
):
...
...
@@ -76,7 +83,7 @@ def negate_polynome(root, args):
return
+
scope
.
as_nary_node
()
MESSAGES
[
negate_polynome
]
=
_
(
'Apply negation to the polynome {
1
}.'
)
MESSAGES
[
negate_polynome
]
=
_
(
'Apply negation to the polynome {
0
}.'
)
#def negate_group(root, args):
...
...
@@ -140,7 +147,7 @@ def double_negated_division(root, args):
MESSAGES
[
double_negated_division
]
=
\
_
(
'Eliminate top and bottom negation in {
1
}.'
)
_
(
'Eliminate top and bottom negation in {
0
}.'
)
# TODO: negated multiplication: -a * -b = ab
tests/test_rules_negation.py
View file @
9419b2b1
...
...
@@ -46,6 +46,10 @@ class TestRulesNegation(RulesTestCase):
[
P
(
root
,
double_negation
,
(
b
,)),
P
(
root
,
negate_polynome
,
())])
def
test_double_negation
(
self
):
root
=
tree
(
'--a'
)
self
.
assertEqualNodes
(
double_negation
(
root
,
()),
++
root
)
def
test_negate_polynome
(
self
):
a
,
b
=
root
=
tree
(
'-(a + b)'
)
self
.
assertEqualNodes
(
negate_polynome
(
root
,
()),
-
a
+
-
b
)
...
...
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