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
7a9605a7
Commit
7a9605a7
authored
Apr 11, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commenced some chanches to fraction rules (unit tests are still failing).
parent
42662f45
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
381 additions
and
247 deletions
+381
-247
src/rules/__init__.py
src/rules/__init__.py
+5
-6
src/rules/fractions.py
src/rules/fractions.py
+204
-157
src/rules/utils.py
src/rules/utils.py
+22
-1
tests/test_rules_fractions.py
tests/test_rules_fractions.py
+139
-82
tests/test_rules_utils.py
tests/test_rules_utils.py
+11
-1
No files found.
src/rules/__init__.py
View file @
7a9605a7
...
...
@@ -9,9 +9,9 @@ from .powers import match_add_exponents, match_subtract_exponents, \
from
.numerics
import
match_add_numerics
,
match_divide_numerics
,
\
match_multiply_numerics
,
match_multiply_zero
,
match_multiply_one
,
\
match_raise_numerics
from
.fractions
import
match_constant_division
,
match_add_
constant_
fractions
,
\
match_
expand_and_add_fractions
,
match_multiply
_fractions
,
\
match_
divide_fractions
,
match_
equal_fraction_parts
from
.fractions
import
match_constant_division
,
match_add_fractions
,
\
match_
multiply_fractions
,
match_divide
_fractions
,
\
match_equal_fraction_parts
from
.negation
import
match_negated_factor
,
match_negate_polynome
,
\
match_negated_division
from
.sort
import
match_sort_multiplicants
...
...
@@ -30,12 +30,11 @@ from src.rules.integrals import match_solve_indef, match_constant_integral, \
from
src.rules.lineq
import
match_move_term
RULES
=
{
OP_ADD
:
[
match_add_numerics
,
match_add_
constant_
fractions
,
OP_ADD
:
[
match_add_numerics
,
match_add_fractions
,
match_combine_groups
,
match_add_quadrants
,
match_add_logarithms
],
OP_MUL
:
[
match_multiply_numerics
,
match_expand
,
match_add_exponents
,
match_expand_and_add_fractions
,
match_multiply_zero
,
match_negated_factor
,
match_multiply_one
,
match_multiply_zero
,
match_negated_factor
,
match_multiply_one
,
match_sort_multiplicants
,
match_multiply_fractions
,
match_factor_in_multiplicant
],
OP_DIV
:
[
match_subtract_exponents
,
match_divide_numerics
,
...
...
src/rules/fractions.py
View file @
7a9605a7
This diff is collapsed.
Click to expand it.
src/rules/utils.py
View file @
7a9605a7
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_MUL
,
OP_DIV
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_MUL
,
OP_DIV
,
\
OP_ADD
,
OP_POW
,
OP_SQRT
def
greatest_common_divisor
(
a
,
b
):
...
...
@@ -132,3 +133,23 @@ def divides(m, n):
Check if m | n (m divides n).
"""
return
not
divmod
(
n
,
m
)[
1
]
def
is_numeric_node
(
node
):
"""
Check if a node is numeric.
"""
return
node
.
is_numeric
()
def
evals_to_numeric
(
node
):
"""
Check if a node will eventually evaluate to a numeric value, by checking if
all leaves are numeric and there are only operators that can be
considerered a constant or will evaluate to one (+, *, /, ^, sqrt).
"""
if
node
.
is_leaf
:
return
node
.
is_numeric
()
return
node
.
op
in
(
OP_ADD
,
OP_MUL
,
OP_DIV
,
OP_POW
,
OP_SQRT
)
\
and
all
(
map
(
evals_to_numeric
,
node
))
tests/test_rules_fractions.py
View file @
7a9605a7
This diff is collapsed.
Click to expand it.
tests/test_rules_utils.py
View file @
7a9605a7
from
src.rules
import
utils
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
find_variables
,
first_sorted_variable
,
find_variable
,
substitute
,
\
divides
divides
,
evals_to_numeric
from
tests.rulestestcase
import
tree
,
RulesTestCase
...
...
@@ -65,3 +65,13 @@ class TestRulesUtils(RulesTestCase):
self
.
assertTrue
(
divides
(
7
,
21
))
self
.
assertFalse
(
divides
(
4
,
2
))
self
.
assertFalse
(
divides
(
2
,
3
))
def
test_evals_to_numeric
(
self
):
self
.
assertTrue
(
evals_to_numeric
(
tree
(
'1'
)))
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'a'
)))
self
.
assertTrue
(
evals_to_numeric
(
tree
(
'1 + 2'
)))
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'1 + a'
)))
self
.
assertTrue
(
evals_to_numeric
(
tree
(
'1 + 2 / 2 * 9'
)))
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'int 1'
)))
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'int a'
)))
self
.
assertTrue
(
evals_to_numeric
(
tree
(
'sqrt 1'
)))
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