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
c7a9125f
Commit
c7a9125f
authored
Feb 16, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied usage of Scope.replace method and fixed some failing unit tests.
parent
b63b5130
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
12 deletions
+17
-12
src/rules/factors.py
src/rules/factors.py
+2
-2
src/rules/fractions.py
src/rules/fractions.py
+10
-5
src/rules/groups.py
src/rules/groups.py
+1
-1
src/rules/numerics.py
src/rules/numerics.py
+2
-2
src/rules/poly.py
src/rules/poly.py
+1
-1
src/rules/powers.py
src/rules/powers.py
+1
-1
No files found.
src/rules/factors.py
View file @
c7a9125f
...
@@ -45,7 +45,7 @@ def expand_single(root, args):
...
@@ -45,7 +45,7 @@ def expand_single(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace 'a' with the new expression
# Replace 'a' with the new expression
scope
.
re
mov
e
(
a
,
a
*
b
+
a
*
c
)
scope
.
re
plac
e
(
a
,
a
*
b
+
a
*
c
)
# Remove the addition
# Remove the addition
scope
.
remove
(
bc
)
scope
.
remove
(
bc
)
...
@@ -66,7 +66,7 @@ def expand_double(root, args):
...
@@ -66,7 +66,7 @@ def expand_double(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace 'a + b' with the new expression
# Replace 'a + b' with the new expression
scope
.
re
mov
e
(
ab
,
a
*
c
+
a
*
d
+
b
*
c
+
b
*
d
)
scope
.
re
plac
e
(
ab
,
a
*
c
+
a
*
d
+
b
*
c
+
b
*
d
)
# Remove the right addition
# Remove the right addition
scope
.
remove
(
cd
)
scope
.
remove
(
cd
)
...
...
src/rules/fractions.py
View file @
c7a9125f
from
itertools
import
combinations
from
itertools
import
combinations
from
.utils
import
least_common_multiple
from
.utils
import
least_common_multiple
from
..node
import
ExpressionLeaf
as
L
,
Scope
,
OP_DIV
,
OP_ADD
,
OP_MUL
from
..node
import
ExpressionLeaf
as
L
,
Scope
,
negate
,
OP_DIV
,
OP_ADD
,
OP_MUL
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
from
..translate
import
_
...
@@ -112,9 +112,14 @@ def equalize_denominators(root, args):
...
@@ -112,9 +112,14 @@ def equalize_denominators(root, args):
mult
=
denom
/
d
.
value
mult
=
denom
/
d
.
value
if
mult
!=
1
:
if
mult
!=
1
:
n
=
L
(
n
.
value
*
mult
)
if
n
.
is_numeric
()
else
L
(
mult
)
*
n
if
n
.
is_numeric
():
n
=
L
(
n
.
value
*
mult
)
else
:
n
=
L
(
mult
)
*
n
scope
.
remove
(
fraction
,
negate
(
n
/
L
(
d
.
value
*
mult
),
#n = L(n.value * mult) if n.is_numeric() else L(mult) * n
scope
.
replace
(
fraction
,
negate
(
n
/
L
(
d
.
value
*
mult
),
fraction
.
negated
))
fraction
.
negated
))
return
scope
.
as_nary_node
()
return
scope
.
as_nary_node
()
...
@@ -137,7 +142,7 @@ def add_nominators(root, args):
...
@@ -137,7 +142,7 @@ def add_nominators(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace the left node with the new expression
# Replace the left node with the new expression
scope
.
re
move
(
ab
,
(
a
+
negate
(
cb
[
0
],
cb
.
negated
))
/
b
)
scope
.
re
place
(
ab
,
(
a
+
cb
[
0
].
negate
(
cb
.
negated
))
/
b
)
# Remove the right node
# Remove the right node
scope
.
remove
(
cb
)
scope
.
remove
(
cb
)
...
...
src/rules/groups.py
View file @
c7a9125f
...
@@ -59,7 +59,7 @@ def combine_groups(root, args):
...
@@ -59,7 +59,7 @@ def combine_groups(root, args):
c0
=
Leaf
(
c0
)
c0
=
Leaf
(
c0
)
# Replace the left node with the new expression
# Replace the left node with the new expression
scope
.
re
mov
e
(
n0
,
(
c0
+
c1
)
*
g0
)
scope
.
re
plac
e
(
n0
,
(
c0
+
c1
)
*
g0
)
# Remove the right node
# Remove the right node
scope
.
remove
(
n1
)
scope
.
remove
(
n1
)
...
...
src/rules/numerics.py
View file @
c7a9125f
...
@@ -19,7 +19,7 @@ def add_numerics(root, args):
...
@@ -19,7 +19,7 @@ def add_numerics(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace the left node with the new expression
# Replace the left node with the new expression
scope
.
re
mov
e
(
n0
,
Leaf
(
c0
.
actual_value
()
+
c1
.
actual_value
()))
scope
.
re
plac
e
(
n0
,
Leaf
(
c0
.
actual_value
()
+
c1
.
actual_value
()))
# Remove the right node
# Remove the right node
scope
.
remove
(
n1
)
scope
.
remove
(
n1
)
...
@@ -171,7 +171,7 @@ def multiply_numerics(root, args):
...
@@ -171,7 +171,7 @@ def multiply_numerics(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace the left node with the new expression
# Replace the left node with the new expression
scope
.
re
mov
e
(
n0
,
substitution
)
scope
.
re
plac
e
(
n0
,
substitution
)
# Remove the right node
# Remove the right node
scope
.
remove
(
n1
)
scope
.
remove
(
n1
)
...
...
src/rules/poly.py
View file @
c7a9125f
...
@@ -84,7 +84,7 @@ def combine_polynomes(root, args):
...
@@ -84,7 +84,7 @@ def combine_polynomes(root, args):
# Replace the left node with the new expression:
# Replace the left node with the new expression:
# (c0 + c1) * a ^ b
# (c0 + c1) * a ^ b
# a, b and c are from 'left', d is from 'right'.
# a, b and c are from 'left', d is from 'right'.
scope
.
re
mov
e
(
n0
,
(
c0
+
c1
)
*
power
)
scope
.
re
plac
e
(
n0
,
(
c0
+
c1
)
*
power
)
# Remove the right node
# Remove the right node
scope
.
remove
(
n1
)
scope
.
remove
(
n1
)
...
...
src/rules/powers.py
View file @
c7a9125f
...
@@ -54,7 +54,7 @@ def add_exponents(root, args):
...
@@ -54,7 +54,7 @@ def add_exponents(root, args):
scope
=
Scope
(
root
)
scope
=
Scope
(
root
)
# Replace the left node with the new expression
# Replace the left node with the new expression
scope
.
re
mov
e
(
n0
,
a
**
(
p
+
q
))
scope
.
re
plac
e
(
n0
,
a
**
(
p
+
q
))
# Remove the right node
# Remove the right node
scope
.
remove
(
n1
)
scope
.
remove
(
n1
)
...
...
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