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
08c982bb
Commit
08c982bb
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Changed negate() function to negate by reference by default (as a small optimization).
parent
f45d2751
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/node.py
+12
-7
12 additions, 7 deletions
src/node.py
src/rules/groups.py
+2
-2
2 additions, 2 deletions
src/rules/groups.py
src/rules/powers.py
+1
-1
1 addition, 1 deletion
src/rules/powers.py
with
15 additions
and
10 deletions
src/node.py
+
12
−
7
View file @
08c982bb
...
...
@@ -251,13 +251,13 @@ class ExpressionBase(object):
def
negate
(
self
,
n
=
1
):
"""
Negate the node n times.
"""
return
negate
(
self
,
self
.
negated
+
n
)
return
negate
(
self
,
self
.
negated
+
n
,
clone
=
True
)
def
contains
(
self
,
node
,
include_self
=
True
):
"""
Check if a node equal to the specified one exists within this node.
"""
if
include_self
and
negate
(
self
,
0
)
==
node
:
if
include_self
and
self
.
equals
(
node
,
ignore_negation
=
True
)
:
return
True
if
not
self
.
is_leaf
:
...
...
@@ -620,14 +620,19 @@ def get_scope(node):
return
scope
def
negate
(
node
,
n
=
1
):
"""
Negate the given node n times.
"""
def
negate
(
node
,
n
=
1
,
clone
=
False
):
"""
Negate the given node n times. If clone is set to true, return a new node
so that the original node is not altered.
"""
assert
n
>=
0
new_node
=
node
.
clone
()
new_node
.
negated
=
n
if
clone
:
node
=
node
.
clone
()
node
.
negated
=
n
return
new_
node
return
node
def
infinity
():
...
...
This diff is collapsed.
Click to expand it.
src/rules/groups.py
+
2
−
2
View file @
08c982bb
...
...
@@ -59,8 +59,8 @@ def match_combine_groups(node):
# Move negations to constants
c0
=
c0
.
negate
(
g0
.
negated
)
c1
=
c1
.
negate
(
g1
.
negated
)
g0
=
negate
(
g0
,
0
)
g1
=
negate
(
g1
,
0
)
g0
=
negate
(
g0
,
0
,
clone
=
True
)
g1
=
negate
(
g1
,
0
,
clone
=
True
)
p
.
append
(
P
(
node
,
combine_groups
,
(
scope
,
c0
,
g0
,
n0
,
c1
,
g1
,
n1
)))
...
...
This diff is collapsed.
Click to expand it.
src/rules/powers.py
+
1
−
1
View file @
08c982bb
...
...
@@ -24,7 +24,7 @@ def match_add_exponents(node):
# Order powers by their roots, e.g. a^p and a^q are put in the same
# list because of the mutual 'a'
if
n
.
is_identifier
():
s
=
negate
(
n
,
0
)
s
=
negate
(
n
,
0
,
clone
=
True
)
exponent
=
L
(
1
)
elif
n
.
is_op
(
OP_POW
):
s
,
exponent
=
n
...
...
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