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
d2cfb91d
Commit
d2cfb91d
authored
Mar 08, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some utilities for finding variables in a node.
parent
adb38a1b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
src/rules/__init__.py
src/rules/__init__.py
+3
-1
tests/test_rules_utils.py
tests/test_rules_utils.py
+10
-1
No files found.
src/rules/__init__.py
View file @
d2cfb91d
from
..node
import
OP_ADD
,
OP_MUL
,
OP_DIV
,
OP_POW
,
OP_NEG
,
OP_SIN
,
OP_COS
,
\
from
..node
import
OP_ADD
,
OP_MUL
,
OP_DIV
,
OP_POW
,
OP_NEG
,
OP_SIN
,
OP_COS
,
\
OP_TAN
OP_TAN
,
OP_DERIV
from
.groups
import
match_combine_groups
from
.groups
import
match_combine_groups
from
.factors
import
match_expand
from
.factors
import
match_expand
from
.powers
import
match_add_exponents
,
match_subtract_exponents
,
\
from
.powers
import
match_add_exponents
,
match_subtract_exponents
,
\
...
@@ -17,6 +17,7 @@ from .negation import match_negated_factor, match_negate_polynome, \
...
@@ -17,6 +17,7 @@ from .negation import match_negated_factor, match_negate_polynome, \
from
.sort
import
match_sort_multiplicants
from
.sort
import
match_sort_multiplicants
from
.goniometry
import
match_add_quadrants
,
match_negated_parameter
,
\
from
.goniometry
import
match_add_quadrants
,
match_negated_parameter
,
\
match_half_pi_subtraction
,
match_standard_radian
match_half_pi_subtraction
,
match_standard_radian
from
src.rules.derivatives
import
match_constant_derivative
RULES
=
{
RULES
=
{
OP_ADD
:
[
match_add_numerics
,
match_add_constant_fractions
,
OP_ADD
:
[
match_add_numerics
,
match_add_constant_fractions
,
...
@@ -38,4 +39,5 @@ RULES = {
...
@@ -38,4 +39,5 @@ RULES = {
OP_COS
:
[
match_negated_parameter
,
match_half_pi_subtraction
,
OP_COS
:
[
match_negated_parameter
,
match_half_pi_subtraction
,
match_standard_radian
],
match_standard_radian
],
OP_TAN
:
[
match_standard_radian
],
OP_TAN
:
[
match_standard_radian
],
OP_DERIV
:
[
match_constant_derivative
],
}
}
tests/test_rules_utils.py
View file @
d2cfb91d
import
unittest
import
unittest
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
find_variables
from
tests.rulestestcase
import
tree
from
tests.rulestestcase
import
tree
...
@@ -22,3 +23,11 @@ class TestRulesUtils(unittest.TestCase):
...
@@ -22,3 +23,11 @@ class TestRulesUtils(unittest.TestCase):
def
test_partition
(
self
):
def
test_partition
(
self
):
self
.
assertEqual
(
partition
(
lambda
x
:
x
&
1
,
range
(
6
)),
self
.
assertEqual
(
partition
(
lambda
x
:
x
&
1
,
range
(
6
)),
([
1
,
3
,
5
],
[
0
,
2
,
4
]))
([
1
,
3
,
5
],
[
0
,
2
,
4
]))
def
test_find_variables
(
self
):
x
,
l2
,
add
,
mul0
,
mul1
=
tree
(
'x, 2, x + 2, 2x, xy'
)
self
.
assertSetEqual
(
find_variables
(
x
),
set
([
'x'
]))
self
.
assertSetEqual
(
find_variables
(
l2
),
set
())
self
.
assertSetEqual
(
find_variables
(
add
),
set
([
'x'
]))
self
.
assertSetEqual
(
find_variables
(
mul0
),
set
([
'x'
]))
self
.
assertSetEqual
(
find_variables
(
mul1
),
set
([
'x'
,
'y'
]))
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