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
6add540a
Commit
6add540a
authored
Apr 02, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed function name.
parent
b4b5542d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
src/rules/integrals.py
src/rules/integrals.py
+3
-3
src/rules/utils.py
src/rules/utils.py
+2
-2
tests/test_rules_utils.py
tests/test_rules_utils.py
+5
-5
No files found.
src/rules/integrals.py
View file @
6add540a
from
.utils
import
find_variables
,
replace_variabl
e
,
find_variable
from
.utils
import
find_variables
,
substitut
e
,
find_variable
from
..node
import
ExpressionLeaf
as
L
,
OP_INT
,
OP_INT_INDEF
,
OP_MUL
,
OP_DIV
,
\
OP_LOG
,
OP_SIN
,
OP_COS
,
Scope
,
sin
,
cos
,
ln
,
integral
,
indef
,
absolute
from
..possibilities
import
Possibility
as
P
,
MESSAGES
...
...
@@ -40,7 +40,7 @@ def solve_integral(integral, F):
x
,
lbnd
,
ubnd
=
integral
[
1
:
4
]
if
x
!=
find_variable
(
F
):
return
replace_variable
(
F
,
x
,
ubnd
)
-
replace_variabl
e
(
F
,
x
,
lbnd
)
return
substitute
(
F
,
x
,
ubnd
)
-
substitut
e
(
F
,
x
,
lbnd
)
return
indef
(
F
,
lbnd
,
ubnd
)
...
...
@@ -61,7 +61,7 @@ def solve_indef(root, args):
Fx
,
a
,
b
=
root
x
=
find_variable
(
Fx
)
return
replace_variable
(
Fx
,
x
,
b
)
-
replace_variabl
e
(
Fx
,
x
,
a
)
return
substitute
(
Fx
,
x
,
b
)
-
substitut
e
(
Fx
,
x
,
a
)
def
match_integrate_variable_power
(
node
):
...
...
src/rules/utils.py
View file @
6add540a
...
...
@@ -111,7 +111,7 @@ def find_variable(exp):
return
L
(
first_sorted_variable
(
variables
))
def
replace_variabl
e
(
f
,
x
,
replacement
):
def
substitut
e
(
f
,
x
,
replacement
):
"""
Replace all occurences of variable x in function f with the specified
replacement.
...
...
@@ -122,6 +122,6 @@ def replace_variable(f, x, replacement):
if
f
.
is_leaf
:
return
f
children
=
map
(
lambda
c
:
replace_variabl
e
(
c
,
x
,
replacement
),
f
)
children
=
map
(
lambda
c
:
substitut
e
(
c
,
x
,
replacement
),
f
)
return
N
(
f
.
op
,
*
children
)
tests/test_rules_utils.py
View file @
6add540a
from
src.rules
import
utils
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
find_variables
,
first_sorted_variable
,
find_variable
,
replace_variabl
e
find_variables
,
first_sorted_variable
,
find_variable
,
substitut
e
from
tests.rulestestcase
import
tree
,
RulesTestCase
...
...
@@ -50,10 +50,10 @@ class TestRulesUtils(RulesTestCase):
self
.
assertEqual
(
find_variable
(
tree
(
'1 + 2'
)),
x
)
self
.
assertEqual
(
find_variable
(
tree
(
'y ^ 2'
)),
y
)
def
test_
replace_variabl
e
(
self
):
def
test_
substitut
e
(
self
):
x
,
a
=
tree
(
'x, a'
)
self
.
assertEqual
(
replace_variabl
e
(
x
,
x
,
a
),
a
)
self
.
assertEqual
(
replace_variabl
e
(
tree
(
'x2'
),
x
,
a
),
tree
(
'a2'
))
self
.
assertEqual
(
replace_variabl
e
(
tree
(
'y + x + 1'
),
x
,
a
),
self
.
assertEqual
(
substitut
e
(
x
,
x
,
a
),
a
)
self
.
assertEqual
(
substitut
e
(
tree
(
'x2'
),
x
,
a
),
tree
(
'a2'
))
self
.
assertEqual
(
substitut
e
(
tree
(
'y + x + 1'
),
x
,
a
),
tree
(
'y + a + 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