Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
694854ae
Commit
694854ae
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Shortened rule name.
parent
17862fb9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/rules/__init__.py
+2
-2
2 additions, 2 deletions
src/rules/__init__.py
src/rules/lineq.py
+7
-12
7 additions, 12 deletions
src/rules/lineq.py
tests/test_rules_lineq.py
+9
-9
9 additions, 9 deletions
tests/test_rules_lineq.py
with
18 additions
and
23 deletions
src/rules/__init__.py
+
2
−
2
View file @
694854ae
...
...
@@ -27,7 +27,7 @@ from src.rules.logarithmic import match_constant_logarithm, \
from
src.rules.integrals
import
match_solve_indef
,
match_constant_integral
,
\
match_integrate_variable_power
,
match_factor_out_constant
,
\
match_division_integral
,
match_function_integral
from
src.rules.lineq
import
match_subtract_
addition_
term
from
src.rules.lineq
import
match_subtract_term
RULES
=
{
OP_ADD
:
[
match_add_numerics
,
match_add_constant_fractions
,
...
...
@@ -61,5 +61,5 @@ RULES = {
match_factor_out_constant
,
match_division_integral
,
match_function_integral
],
OP_INT_INDEF
:
[
match_solve_indef
],
OP_EQ
:
[
match_subtract_
addition_
term
],
OP_EQ
:
[
match_subtract_term
],
}
This diff is collapsed.
Click to expand it.
src/rules/lineq.py
+
7
−
12
View file @
694854ae
...
...
@@ -4,7 +4,7 @@ from ..possibilities import Possibility as P, MESSAGES
from
..translate
import
_
def
match_subtract_
addition_
term
(
node
):
def
match_subtract_term
(
node
):
"""
x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx
...
...
@@ -16,25 +16,21 @@ def match_subtract_addition_term(node):
left
,
right
=
node
if
left
.
is_op
(
OP_ADD
):
scope
=
Scope
(
left
)
for
n
in
scope
:
for
n
in
Scope
(
left
):
# Bring terms without x to the right
if
not
n
.
contains
(
x
):
p
.
append
(
P
(
node
,
subtract_
addition_
term
,
(
n
,)))
p
.
append
(
P
(
node
,
subtract_term
,
(
n
,)))
if
right
.
is_op
(
OP_ADD
):
scope
=
Scope
(
right
)
for
n
in
scope
:
for
n
in
Scope
(
right
):
# Bring terms with x to the left
if
n
.
contains
(
x
):
p
.
append
(
P
(
node
,
subtract_
addition_
term
,
(
n
,)))
p
.
append
(
P
(
node
,
subtract_term
,
(
n
,)))
return
p
def
subtract_
addition_
term
(
root
,
args
):
def
subtract_term
(
root
,
args
):
"""
x + a = b -> x + a - a = b - a
x = b + cx -> x + - cx = b + cx - cx
...
...
@@ -45,5 +41,4 @@ def subtract_addition_term(root, args):
return
eq
(
left
-
term
,
right
-
term
)
MESSAGES
[
subtract_addition_term
]
=
\
_
(
'
Subtract {1} from both sides of the equation.
'
)
MESSAGES
[
subtract_term
]
=
_
(
'
Subtract {1} from both sides of the equation.
'
)
This diff is collapsed.
Click to expand it.
tests/test_rules_lineq.py
+
9
−
9
View file @
694854ae
from
src.rules.lineq
import
match_subtract_
addition_
term
,
\
subtract_
addition_
term
from
src.rules.lineq
import
match_subtract_term
,
\
subtract_term
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -7,15 +7,15 @@ from tests.rulestestcase import RulesTestCase, tree
class
TestRulesLineq
(
RulesTestCase
):
def
test_match_subtract_
addition_
term
(
self
):
def
test_match_subtract_term
(
self
):
root
,
a
=
tree
(
'
x + a = b, a
'
)
self
.
assertEqualPos
(
match_subtract_
addition_
term
(
root
),
[
P
(
root
,
subtract_
addition_
term
,
(
a
,))])
self
.
assertEqualPos
(
match_subtract_term
(
root
),
[
P
(
root
,
subtract_term
,
(
a
,))])
root
,
cx
=
tree
(
'
x = b + cx, cx
'
)
self
.
assertEqualPos
(
match_subtract_
addition_
term
(
root
),
[
P
(
root
,
subtract_
addition_
term
,
(
cx
,))])
self
.
assertEqualPos
(
match_subtract_term
(
root
),
[
P
(
root
,
subtract_term
,
(
cx
,))])
def
test_subtract_
addition_
term
(
self
):
def
test_subtract_term
(
self
):
root
,
a
,
expect
=
tree
(
'
x + a = b, a, x + a - a = b - a
'
)
self
.
assertEqual
(
subtract_
addition_
term
(
root
,
(
a
,)),
expect
)
self
.
assertEqual
(
subtract_term
(
root
,
(
a
,)),
expect
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment