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
985b588e
Commit
985b588e
authored
Mar 26, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Source/comments cleanup.
parent
75ad53c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
37 deletions
+10
-37
src/rules/integrals.py
src/rules/integrals.py
+10
-27
tests/test_rules_integrals.py
tests/test_rules_integrals.py
+0
-10
No files found.
src/rules/integrals.py
View file @
985b588e
...
...
@@ -21,25 +21,6 @@ def indef(*args):
return
N
(
OP_INT_INDEF
,
*
args
)
#def integral_params(integral):
# """
# Get integral parameters:
# - If f(x) and x are both specified, return them.
# - If only f(x) is specified, find x.
# """
# if len(integral) > 1:
# assert integral[1].is_identifier()
# return tuple(integral[:2])
#
# f = integral[0]
# variables = find_variables(integral)
#
# if not len(variables):
# return f, None
#
# return f, L(first_sorted_variable(variables))
def
choose_constant
(
integral
):
"""
Choose a constant to be added to the antiderivative.
...
...
@@ -61,21 +42,23 @@ def solve_integral(integral, F):
Solve an integral given its anti-derivative F:
- First, finish the anti-derivative by adding a constant.
- If no bounds are specified, return the anti-derivative.
- If only a lower bound is specified, set the upper bound to infinity.
- Given a lower bound a and upper bound b, the solution is F(b) - F(a).
- Given a lower bound a and upper bound b, the solution is the indefinite
integral [F(x)]_a^b. If F(x) contains multiple variables so that the 'x'
is not identified by 'find_variable(F)' (which is used by the indefinite
integral), skip the reduction of the indefinite integral and return the
solution F(b) - F(a).
"""
F
+=
choose_constant
(
integral
)
if
len
(
integral
)
<
3
:
return
F
x
=
integral
[
1
]
lower
=
integral
[
2
]
upper
=
infinity
()
if
len
(
integral
)
<
4
else
integral
[
3
]
x
,
lbnd
,
ubnd
=
integral
[
1
:
4
]
if
x
!=
find_variable
(
F
):
return
replace_variable
(
F
,
x
,
b
)
-
replace_variable
(
F
,
x
,
a
)
# TODO: skip indefinite notation if anti-derivative has no impliciely
# identifiable parameter
return
indef
(
F
,
lower
,
upper
)
return
indef
(
F
,
lbnd
,
ubnd
)
def
match_solve_indef
(
node
):
...
...
tests/test_rules_integrals.py
View file @
985b588e
...
...
@@ -9,16 +9,6 @@ from tests.rulestestcase import RulesTestCase, tree
class
TestRulesIntegrals
(
RulesTestCase
):
#def test_integral_params(self):
# f, x = root = tree('int fx dx')
# self.assertEqual(integral_params(root), (f, x))
# root = tree('int fx')
# self.assertEqual(integral_params(root), (f, x))
# root = tree('int 3')
# self.assertEqual(integral_params(root), (3, x))
def
test_choose_constant
(
self
):
a
,
b
,
c
=
tree
(
'a, b, c'
)
self
.
assertEqual
(
choose_constant
(
tree
(
'int x ^ n'
)),
c
)
...
...
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