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
ad790a21
Commit
ad790a21
authored
Jan 08, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
duplicate_exponent now supports n-ary multiplication.
parent
44cbdd93
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
src/rules/powers.py
src/rules/powers.py
+9
-4
tests/test_rules_powers.py
tests/test_rules_powers.py
+8
-4
No files found.
src/rules/powers.py
View file @
ad790a21
...
...
@@ -85,7 +85,7 @@ def match_duplicate_exponent(node):
left
,
right
=
node
if
left
.
is_op
(
OP_MUL
):
return
[
P
(
node
,
duplicate_exponent
,
tuple
(
left
)
+
(
right
,
))]
return
[
P
(
node
,
duplicate_exponent
,
(
left
.
get_scope
(),
right
))]
return
[]
...
...
@@ -158,10 +158,15 @@ def multiply_exponents(root, args):
def
duplicate_exponent
(
root
,
args
):
"""
(ab)^p -> a^p * b^p
(abc)^p -> a^p * b^p * c^p
"""
a
,
b
,
p
=
args
ab
,
p
=
args
result
=
ab
[
0
]
**
p
return
a
**
p
*
b
**
p
for
b
in
ab
[
1
:]:
result
*=
b
**
p
return
result
def
remove_negative_exponent
(
root
,
args
):
...
...
tests/test_rules_powers.py
View file @
ad790a21
...
...
@@ -77,7 +77,7 @@ class TestRulesPowers(RulesTestCase):
possibilities
=
match_duplicate_exponent
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
duplicate_exponent
,
(
a
,
b
,
p
))])
[
P
(
root
,
duplicate_exponent
,
(
[
a
,
b
]
,
p
))])
def
test_match_remove_negative_exponent
(
self
):
a
,
p
=
tree
(
'a,p'
)
...
...
@@ -121,12 +121,16 @@ class TestRulesPowers(RulesTestCase):
a
**
(
p
*
q
))
def
test_duplicate_exponent
(
self
):
a
,
b
,
p
=
tree
(
'a,b,p'
)
root
=
(
a
*
b
)
**
p
a
,
b
,
c
,
p
=
tree
(
'a,b,c,p'
)
self
.
assertEqualNodes
(
duplicate_exponent
(
root
,
(
a
,
b
,
p
)),
root
=
(
a
*
b
)
**
p
self
.
assertEqualNodes
(
duplicate_exponent
(
root
,
([
a
,
b
],
p
)),
a
**
p
*
b
**
p
)
root
=
(
a
*
b
*
c
)
**
p
self
.
assertEqualNodes
(
duplicate_exponent
(
root
,
([
a
,
b
,
c
],
p
)),
a
**
p
*
b
**
p
*
c
**
p
)
def
test_remove_negative_exponent
(
self
):
a
,
p
,
l1
=
tree
(
'a,p,1'
)
root
=
a
**
-
p
...
...
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