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
f846f9e7
Commit
f846f9e7
authored
Mar 26, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Source cleanup.
parent
7e891986
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
42 deletions
+31
-42
src/rules/integrals.py
src/rules/integrals.py
+23
-34
tests/test_rules_integrals.py
tests/test_rules_integrals.py
+8
-8
No files found.
src/rules/integrals.py
View file @
f846f9e7
...
@@ -7,41 +7,30 @@ from ..possibilities import Possibility as P, MESSAGES
...
@@ -7,41 +7,30 @@ from ..possibilities import Possibility as P, MESSAGES
from
..translate
import
_
from
..translate
import
_
def
integral
(
f
,
x
=
None
,
lbnd
=
None
,
ubnd
=
None
):
def
integral
(
f
,
*
args
):
"""
"""
Anti-derivativ
e.
Create an integral nod
e.
"""
"""
params
=
[
f
]
return
N
(
OP_INT
,
*
((
f
,)
+
args
))
if
x
:
params
.
append
(
x
)
#def integral_params(integral):
# """
if
lbnd
:
# Get integral parameters:
params
.
append
(
lbnd
)
# - If f(x) and x are both specified, return them.
# - If only f(x) is specified, find x.
if
ubnd
:
# """
params
.
append
(
ubnd
)
# if len(integral) > 1:
# assert integral[1].is_identifier()
return
N
(
OP_INT
,
*
params
)
# return tuple(integral[:2])
#
# f = integral[0]
def
integral_params
(
integral
):
# variables = find_variables(integral)
"""
#
Get integral parameters:
# if not len(variables):
- If f(x) and x are both specified, return them.
# return f, None
- If only f(x) is specified, find x.
#
"""
# return f, L(first_sorted_variable(variables))
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
):
def
choose_constant
(
integral
):
...
@@ -88,7 +77,7 @@ def match_integrate_variable_power(node):
...
@@ -88,7 +77,7 @@ def match_integrate_variable_power(node):
"""
"""
assert
node
.
is_op
(
OP_INT
)
assert
node
.
is_op
(
OP_INT
)
f
,
x
=
integral_params
(
node
)
f
,
x
=
node
if
f
.
is_power
():
if
f
.
is_power
():
root
,
exponent
=
f
root
,
exponent
=
f
...
...
tests/test_rules_integrals.py
View file @
f846f9e7
from
src.rules.integrals
import
integral_params
,
choose_constant
,
\
from
src.rules.integrals
import
choose_constant
,
\
match_integrate_variable_power
,
integrate_variable_root
,
\
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
...
@@ -9,15 +9,15 @@ from tests.rulestestcase import RulesTestCase, tree
...
@@ -9,15 +9,15 @@ from tests.rulestestcase import RulesTestCase, tree
class
TestRulesIntegrals
(
RulesTestCase
):
class
TestRulesIntegrals
(
RulesTestCase
):
def
test_integral_params
(
self
):
#
def test_integral_params(self):
f
,
x
=
root
=
tree
(
'int fx dx'
)
#
f, x = root = tree('int fx dx')
self
.
assertEqual
(
integral_params
(
root
),
(
f
,
x
))
#
self.assertEqual(integral_params(root), (f, x))
root
=
tree
(
'int fx'
)
#
root = tree('int fx')
self
.
assertEqual
(
integral_params
(
root
),
(
f
,
x
))
#
self.assertEqual(integral_params(root), (f, x))
root
=
tree
(
'int 3'
)
#
root = tree('int 3')
self
.
assertEqual
(
integral_params
(
root
),
(
3
,
x
))
#
self.assertEqual(integral_params(root), (3, x))
def
test_choose_constant
(
self
):
def
test_choose_constant
(
self
):
a
,
b
,
c
=
tree
(
'a, b, c'
)
a
,
b
,
c
=
tree
(
'a, b, 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