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
b4b5542d
Commit
b4b5542d
authored
Mar 29, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended equation multiplication rule to apply for a negated left side.
parent
24dc157d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
src/rules/lineq.py
src/rules/lineq.py
+7
-1
tests/test_rules_lineq.py
tests/test_rules_lineq.py
+16
-1
No files found.
src/rules/lineq.py
View file @
b4b5542d
from
.utils
import
find_variable
from
.utils
import
find_variable
from
..node
import
Scope
,
OP_EQ
,
OP_ADD
,
OP_MUL
,
OP_DIV
,
eq
from
..node
import
ExpressionLeaf
as
L
,
Scope
,
OP_EQ
,
OP_ADD
,
OP_MUL
,
OP_DIV
,
\
eq
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
from
..translate
import
_
...
@@ -22,6 +23,7 @@ def match_move_term(node):
...
@@ -22,6 +23,7 @@ def match_move_term(node):
# Multiplication
# Multiplication
x / a = b -> x / a * a = b * a # =>* x = a * b
x / a = b -> x / a * a = b * a # =>* x = a * b
a / x = b -> a / x * x = b * x # =>* x = a / b
a / x = b -> a / x * x = b * x # =>* x = a / b
-x = b -> -x * -1 = b * -1 # =>* x = -b
"""
"""
assert
node
.
is_op
(
OP_EQ
)
assert
node
.
is_op
(
OP_EQ
)
...
@@ -56,6 +58,10 @@ def match_move_term(node):
...
@@ -56,6 +58,10 @@ def match_move_term(node):
if
left
.
is_op
(
OP_DIV
):
if
left
.
is_op
(
OP_DIV
):
p
.
append
(
P
(
node
,
multiply_term
,
(
left
[
1
],)))
p
.
append
(
P
(
node
,
multiply_term
,
(
left
[
1
],)))
# Remove any negation from the left side of the equation
if
left
.
negated
:
p
.
append
(
P
(
node
,
multiply_term
,
(
-
L
(
1
),)))
return
p
return
p
...
...
tests/test_rules_lineq.py
View file @
b4b5542d
...
@@ -37,6 +37,10 @@ class TestRulesLineq(RulesTestCase):
...
@@ -37,6 +37,10 @@ class TestRulesLineq(RulesTestCase):
self
.
assertEqualPos
(
match_move_term
(
root
),
self
.
assertEqualPos
(
match_move_term
(
root
),
[
P
(
root
,
multiply_term
,
(
x
,))])
[
P
(
root
,
multiply_term
,
(
x
,))])
root
,
l1
=
tree
(
'-x = b, -1'
)
self
.
assertEqualPos
(
match_move_term
(
root
),
[
P
(
root
,
multiply_term
,
(
l1
,))])
def
test_swap_sides
(
self
):
def
test_swap_sides
(
self
):
root
,
expect
=
tree
(
'a = bx, bx = a'
)
root
,
expect
=
tree
(
'a = bx, bx = a'
)
self
.
assertEqual
(
swap_sides
(
root
,
()),
expect
)
self
.
assertEqual
(
swap_sides
(
root
,
()),
expect
)
...
@@ -53,7 +57,7 @@ class TestRulesLineq(RulesTestCase):
...
@@ -53,7 +57,7 @@ class TestRulesLineq(RulesTestCase):
root
,
a
,
expect
=
tree
(
'x / a = b, a, x / a * a = b * a'
)
root
,
a
,
expect
=
tree
(
'x / a = b, a, x / a * a = b * a'
)
self
.
assertEqual
(
multiply_term
(
root
,
(
a
,)),
expect
)
self
.
assertEqual
(
multiply_term
(
root
,
(
a
,)),
expect
)
def
test_match_move_term_chain
(
self
):
def
test_match_move_term_chain
_negation
(
self
):
self
.
assertRewrite
([
self
.
assertRewrite
([
'2x + 3 = -3x - 2'
,
'2x + 3 = -3x - 2'
,
'2x + 3 - 3 = -3x - 2 - 3'
,
'2x + 3 - 3 = -3x - 2 - 3'
,
...
@@ -74,3 +78,14 @@ class TestRulesLineq(RulesTestCase):
...
@@ -74,3 +78,14 @@ class TestRulesLineq(RulesTestCase):
'x = -5 / 5'
,
'x = -5 / 5'
,
'x = -1'
,
'x = -1'
,
])
])
def
test_match_move_term_chain_advanced
(
self
):
self
.
assertRewrite
([
'-x = a'
,
'-x * -1 = a * -1'
,
'--x * 1 = a * -1'
,
'x * 1 = a * -1'
,
'x = a * -1'
,
'x = -a * 1'
,
'x = -a'
,
])
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