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
08c982bb
Commit
08c982bb
authored
May 05, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed negate() function to negate by reference by default (as a small optimization).
parent
f45d2751
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
10 deletions
+15
-10
src/node.py
src/node.py
+12
-7
src/rules/groups.py
src/rules/groups.py
+2
-2
src/rules/powers.py
src/rules/powers.py
+1
-1
No files found.
src/node.py
View file @
08c982bb
...
@@ -251,13 +251,13 @@ class ExpressionBase(object):
...
@@ -251,13 +251,13 @@ class ExpressionBase(object):
def
negate
(
self
,
n
=
1
):
def
negate
(
self
,
n
=
1
):
"""Negate the node n times."""
"""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
):
def
contains
(
self
,
node
,
include_self
=
True
):
"""
"""
Check if a node equal to the specified one exists within this node.
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
return
True
if
not
self
.
is_leaf
:
if
not
self
.
is_leaf
:
...
@@ -620,14 +620,19 @@ def get_scope(node):
...
@@ -620,14 +620,19 @@ def get_scope(node):
return scope
return scope
def negate(node, n=1):
def negate(node, n=1, clone=False):
"""Negate the given node n times."""
"""
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
assert n >= 0
new_node = node.clone()
if clone:
new_node.negated = n
node = node.clone()
node.negated = n
return n
ew_n
ode
return node
def infinity():
def infinity():
...
...
src/rules/groups.py
View file @
08c982bb
...
@@ -59,8 +59,8 @@ def match_combine_groups(node):
...
@@ -59,8 +59,8 @@ def match_combine_groups(node):
# Move negations to constants
# Move negations to constants
c0
=
c0
.
negate
(
g0
.
negated
)
c0
=
c0
.
negate
(
g0
.
negated
)
c1
=
c1
.
negate
(
g1
.
negated
)
c1
=
c1
.
negate
(
g1
.
negated
)
g0
=
negate
(
g0
,
0
)
g0
=
negate
(
g0
,
0
,
clone
=
True
)
g1
=
negate
(
g1
,
0
)
g1
=
negate
(
g1
,
0
,
clone
=
True
)
p
.
append
(
P
(
node
,
combine_groups
,
(
scope
,
c0
,
g0
,
n0
,
c1
,
g1
,
n1
)))
p
.
append
(
P
(
node
,
combine_groups
,
(
scope
,
c0
,
g0
,
n0
,
c1
,
g1
,
n1
)))
...
...
src/rules/powers.py
View file @
08c982bb
...
@@ -24,7 +24,7 @@ def match_add_exponents(node):
...
@@ -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
# Order powers by their roots, e.g. a^p and a^q are put in the same
# list because of the mutual 'a'
# list because of the mutual 'a'
if
n
.
is_identifier
():
if
n
.
is_identifier
():
s
=
negate
(
n
,
0
)
s
=
negate
(
n
,
0
,
clone
=
True
)
exponent
=
L
(
1
)
exponent
=
L
(
1
)
elif
n
.
is_op
(
OP_POW
):
elif
n
.
is_op
(
OP_POW
):
s
,
exponent
=
n
s
,
exponent
=
n
...
...
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