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
17862fb9
Commit
17862fb9
authored
Mar 29, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rule for subtracting addition terms from both sides of an equation.
parent
d32ba062
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
src/rules/lineq.py
src/rules/lineq.py
+49
-0
tests/test_rules_lineq.py
tests/test_rules_lineq.py
+21
-0
No files found.
src/rules/lineq.py
0 → 100644
View file @
17862fb9
from
.utils
import
find_variable
from
..node
import
Scope
,
OP_EQ
,
OP_ADD
,
OP_MUL
,
eq
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
def
match_subtract_addition_term
(
node
):
"""
x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx
"""
assert
node
.
is_op
(
OP_EQ
)
x
=
find_variable
(
node
)
p
=
[]
left
,
right
=
node
if
left
.
is_op
(
OP_ADD
):
scope
=
Scope
(
left
)
for
n
in
scope
:
# Bring terms without x to the right
if
not
n
.
contains
(
x
):
p
.
append
(
P
(
node
,
subtract_addition_term
,
(
n
,)))
if
right
.
is_op
(
OP_ADD
):
scope
=
Scope
(
right
)
for
n
in
scope
:
# Bring terms with x to the left
if
n
.
contains
(
x
):
p
.
append
(
P
(
node
,
subtract_addition_term
,
(
n
,)))
return
p
def
subtract_addition_term
(
root
,
args
):
"""
x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx
"""
left
,
right
=
root
term
=
args
[
0
]
return
eq
(
left
-
term
,
right
-
term
)
MESSAGES
[
subtract_addition_term
]
=
\
_
(
'Subtract {1} from both sides of the equation.'
)
tests/test_rules_lineq.py
0 → 100644
View file @
17862fb9
from
src.rules.lineq
import
match_subtract_addition_term
,
\
subtract_addition_term
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
class
TestRulesLineq
(
RulesTestCase
):
def
test_match_subtract_addition_term
(
self
):
root
,
a
=
tree
(
'x + a = b, a'
)
self
.
assertEqualPos
(
match_subtract_addition_term
(
root
),
[
P
(
root
,
subtract_addition_term
,
(
a
,))])
root
,
cx
=
tree
(
'x = b + cx, cx'
)
self
.
assertEqualPos
(
match_subtract_addition_term
(
root
),
[
P
(
root
,
subtract_addition_term
,
(
cx
,))])
def
test_subtract_addition_term
(
self
):
root
,
a
,
expect
=
tree
(
'x + a = b, a, x + a - a = b - a'
)
self
.
assertEqual
(
subtract_addition_term
(
root
,
(
a
,)),
expect
)
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