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
7f4097c6
Commit
7f4097c6
authored
Jan 05, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified combine_polynomes by using magic methods.
parent
4d698f36
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
27 deletions
+11
-27
src/rules/poly.py
src/rules/poly.py
+11
-27
No files found.
src/rules/poly.py
View file @
7f4097c6
...
...
@@ -114,40 +114,24 @@ def combine_polynomes(root, args):
"""
Combine two multiplications of any polynome in an n-ary plus.
Example
:
c
* a ^ b + d * a ^ b -> (c + d
) * a ^ b
Synopsis
:
c
0 * a ^ b + c1 * a ^ b -> (c0 + c1
) * a ^ b
"""
left
,
right
=
args
nl
,
pl
=
left
nr
,
pr
=
right
# TODO: verify that the two commented expression below are invalid and the
# following two expressions are right.
c0
,
r0
,
e0
=
pl
c1
,
r1
,
e1
=
pr
#if r0.is_numeric() and r1.is_numeric() and e0 == e1 == 1:
# new_root = Leaf(r0.value + r1.value)
#else:
# new_root = r0
if
pl
[
3
]
or
pr
[
3
]:
# literal a ^ 1 -> a ^ 1
power
=
Node
(
'^'
,
pl
[
0
],
pl
[
1
])
else
:
# nonliteral a ^ 1 -> a
power
=
pl
[
0
]
# replacement: (c + d) * a ^ b
n0
,
n1
,
c0
,
c1
,
r
,
e
=
args
# a ^ 1 -> a
power
=
r
if
e
==
1
else
r
^
e
# replacement: (c0 + c1) * a ^ b
# a, b and c are from 'left', d is from 'right'.
replacement
=
Node
(
'*'
,
Node
(
'+'
,
pl
[
2
],
pr
[
2
]),
power
)
replacement
=
(
c0
+
c1
)
*
power
scope
=
root
.
get_scope
()
# Replace the left node with the new expression
scope
[
scope
.
index
(
n
l
)]
=
replacement
scope
[
scope
.
index
(
n
0
)]
=
replacement
# Remove the right node
scope
.
remove
(
n
r
)
scope
.
remove
(
n
1
)
return
nary_node
(
'+'
,
scope
)
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