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
c5624470
Commit
c5624470
authored
Mar 26, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rule to solve an indefinite integral.
parent
2ed4de97
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
8 deletions
+36
-8
src/rules/integrals.py
src/rules/integrals.py
+23
-4
src/rules/utils.py
src/rules/utils.py
+3
-2
tests/test_rules_integrals.py
tests/test_rules_integrals.py
+10
-2
No files found.
src/rules/integrals.py
View file @
c5624470
from
.utils
import
find_variables
,
first_sorted_variable
,
infinity
,
\
from
.utils
import
find_variables
,
infinity
,
replace_variable
,
find_variable
replace_variable
from
.logarithmic
import
ln
from
.logarithmic
import
ln
#from .goniometry import sin, cos
#from .goniometry import sin, cos
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_INT
,
\
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_INT
,
\
...
@@ -74,8 +73,28 @@ def solve_integral(integral, F):
...
@@ -74,8 +73,28 @@ def solve_integral(integral, F):
lower
=
integral
[
2
]
lower
=
integral
[
2
]
upper
=
infinity
()
if
len
(
integral
)
<
4
else
integral
[
3
]
upper
=
infinity
()
if
len
(
integral
)
<
4
else
integral
[
3
]
# TODO: add notation [F(x)]_a^b
# TODO: skip indefinite notation if anti-derivative has no impliciely
return
replace_variable
(
F
,
x
,
lower
)
-
replace_variable
(
F
,
x
,
upper
)
# identifiable parameter
return
indef
(
F
,
lower
,
upper
)
def
match_solve_indef
(
node
):
"""
[F(x)]_a^b -> F(b) - F(a)
"""
assert
node
.
is_op
(
OP_INT_INDEF
)
return
[
P
(
node
,
solve_indef
)]
def
solve_indef
(
root
,
args
):
"""
[F(x)]_a^b -> F(b) - F(a)
"""
Fx
,
a
,
b
=
root
x
=
find_variable
(
Fx
)
return
replace_variable
(
Fx
,
x
,
b
)
-
replace_variable
(
Fx
,
x
,
a
)
def
match_integrate_variable_power
(
node
):
def
match_integrate_variable_power
(
node
):
...
...
src/rules/utils.py
View file @
c5624470
from
..node
import
ExpressionLeaf
as
L
,
OP_MUL
,
OP_DIV
,
INFINITY
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_MUL
,
OP_DIV
,
\
INFINITY
def
greatest_common_divisor
(
a
,
b
):
def
greatest_common_divisor
(
a
,
b
):
...
@@ -124,4 +125,4 @@ def replace_variable(f, x, replacement):
...
@@ -124,4 +125,4 @@ def replace_variable(f, x, replacement):
children
=
map
(
lambda
c
:
replace_variable
(
c
,
x
,
replacement
),
f
)
children
=
map
(
lambda
c
:
replace_variable
(
c
,
x
,
replacement
),
f
)
return
N
(
f
,
*
children
)
return
N
(
f
.
op
,
*
children
)
tests/test_rules_integrals.py
View file @
c5624470
from
src.rules.integrals
import
choose_constant
,
\
from
src.rules.integrals
import
choose_constant
,
match_solve_indef
,
\
match_integrate_variable_power
,
integrate_variable_root
,
\
solve_indef
,
match_integrate_variable_power
,
integrate_variable_root
,
\
integrate_variable_exponent
integrate_variable_exponent
from
src.rules.logarithmic
import
ln
from
src.rules.logarithmic
import
ln
#from .goniometry import sin, cos
#from .goniometry import sin, cos
...
@@ -25,6 +25,14 @@ class TestRulesIntegrals(RulesTestCase):
...
@@ -25,6 +25,14 @@ class TestRulesIntegrals(RulesTestCase):
self
.
assertEqual
(
choose_constant
(
tree
(
'int x ^ c'
)),
a
)
self
.
assertEqual
(
choose_constant
(
tree
(
'int x ^ c'
)),
a
)
self
.
assertEqual
(
choose_constant
(
tree
(
'int a ^ c da'
)),
b
)
self
.
assertEqual
(
choose_constant
(
tree
(
'int a ^ c da'
)),
b
)
def
test_match_solve_indef
(
self
):
root
=
tree
(
'[x ^ 2]_a^b'
)
self
.
assertEqualPos
(
match_solve_indef
(
root
),
[
P
(
root
,
solve_indef
)])
def
test_solve_indef
(
self
):
root
,
expect
=
tree
(
'[x ^ 2]_a^b, b2 - a2'
)
self
.
assertEqual
(
solve_indef
(
root
,
()),
expect
)
def
test_match_integrate_variable_power
(
self
):
def
test_match_integrate_variable_power
(
self
):
for
root
in
tree
(
'int x ^ n, int x ^ n'
):
for
root
in
tree
(
'int x ^ n, int x ^ n'
):
self
.
assertEqualPos
(
match_integrate_variable_power
(
root
),
self
.
assertEqualPos
(
match_integrate_variable_power
(
root
),
...
...
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