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
961c70a7
Commit
961c70a7
authored
May 02, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rules for removing double conjunction/disjunction cases.
parent
71bb5823
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
6 deletions
+57
-6
src/rules/__init__.py
src/rules/__init__.py
+4
-3
src/rules/lineq.py
src/rules/lineq.py
+33
-2
tests/test_rules_lineq.py
tests/test_rules_lineq.py
+20
-1
No files found.
src/rules/__init__.py
View file @
961c70a7
from
..node
import
OP_ADD
,
OP_MUL
,
OP_DIV
,
OP_POW
,
OP_NEG
,
OP_SIN
,
OP_COS
,
\
OP_TAN
,
OP_DER
,
OP_LOG
,
OP_INT
,
OP_INT_INDEF
,
OP_EQ
,
OP_ABS
,
OP_SQRT
,
\
OP_AND
OP_AND
,
OP_OR
from
.groups
import
match_combine_groups
from
.factors
import
match_expand
from
.powers
import
match_add_exponents
,
match_subtract_exponents
,
\
...
...
@@ -28,7 +28,7 @@ from .integrals import match_solve_indef, match_constant_integral, \
match_integrate_variable_power
,
match_factor_out_constant
,
\
match_division_integral
,
match_function_integral
,
\
match_sum_rule_integral
,
match_remove_indef_constant
from
.lineq
import
match_move_term
,
match_multiple_equations
from
.lineq
import
match_move_term
,
match_multiple_equations
,
match_double_case
from
.absolute
import
match_factor_out_abs_term
from
.sqrt
import
match_reduce_sqrt
...
...
@@ -68,5 +68,6 @@ RULES = {
OP_EQ
:
[
match_move_term
],
OP_ABS
:
[
match_factor_out_abs_term
],
OP_SQRT
:
[
match_reduce_sqrt
],
OP_AND
:
[
match_multiple_equations
],
OP_AND
:
[
match_multiple_equations
,
match_double_case
],
OP_OR
:
[
match_double_case
],
}
src/rules/lineq.py
View file @
961c70a7
from
itertools
import
permutations
from
itertools
import
permutations
,
combinations
from
.utils
import
find_variable
,
evals_to_numeric
,
substitute
from
..node
import
ExpressionLeaf
as
L
,
Scope
,
OP_EQ
,
OP_ADD
,
OP_MUL
,
OP_DIV
,
\
eq
,
OP_ABS
,
OP_AND
eq
,
OP_ABS
,
OP_AND
,
OP_OR
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
...
...
@@ -194,3 +194,34 @@ def substitute_variable(root, args):
MESSAGES
[
substitute_variable
]
=
_
(
'Substitute {2} with {3} in {4}.'
)
def
match_double_case
(
node
):
"""
a ^^ a -> a
a vv a -> a
"""
assert
node
.
is_op
(
OP_AND
,
OP_OR
)
scope
=
Scope
(
node
)
p
=
[]
for
a
,
b
in
combinations
(
scope
,
2
):
if
a
==
b
:
p
.
append
(
P
(
node
,
double_case
,
(
scope
,
a
,
b
)))
return
p
def
double_case
(
root
,
args
):
"""
a ^^ a -> a
a vv a -> a
"""
scope
,
a
,
b
=
args
scope
.
remove
(
b
)
return
scope
.
as_nary_node
()
MESSAGES
[
double_case
]
=
_
(
'Remove double occurence of {2}.'
)
tests/test_rules_lineq.py
View file @
961c70a7
from
src.rules.lineq
import
match_move_term
,
swap_sides
,
subtract_term
,
\
divide_term
,
multiply_term
,
split_absolute_equation
,
\
match_multiple_equations
,
substitute_variable
match_multiple_equations
,
substitute_variable
,
match_double_case
,
\
double_case
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -116,8 +117,26 @@ class TestRulesLineq(RulesTestCase):
self
.
assertEqualPos
(
match_multiple_equations
(
root
),
[
P
(
root
,
substitute_variable
,
(
Scope
(
root
),
x
,
2
,
eq1
))])
root
=
tree
(
'x + y = 2 ^^ ay + x = 3'
)
self
.
assertEqualPos
(
match_multiple_equations
(
root
),
[])
root
=
tree
(
'x + y ^^ ay + x = 3'
)
self
.
assertEqualPos
(
match_multiple_equations
(
root
),
[])
def
test_substitute_variable
(
self
):
root
,
expect
=
tree
(
'x = 2 ^^ ay + x = 3, x = 2 ^^ ay + 2 = 3'
)
(
x
,
l2
),
eq
=
root
self
.
assertEqual
(
substitute_variable
(
root
,
((
Scope
(
root
),
x
,
l2
,
eq
))),
expect
)
def
test_match_double_case
(
self
):
a
,
b
=
root
=
tree
(
'x = 2 vv x = 2'
)
self
.
assertEqualPos
(
match_double_case
(
root
),
[
P
(
root
,
double_case
,
(
Scope
(
root
),
a
,
b
))])
root
=
tree
(
'x = 2 vv x = -2'
)
self
.
assertEqualPos
(
match_double_case
(
root
),
[])
def
test_double_case
(
self
):
a
,
b
=
root
=
tree
(
'x = 2 vv x = 2, x = 2'
)
self
.
assertEqual
(
double_case
(
root
,
(
Scope
(
root
),
a
,
b
)),
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