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
92f967d6
Commit
92f967d6
authored
Apr 21, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rule for removing constants from indefinite integrals.
parent
21c092de
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
4 deletions
+52
-4
src/rules/__init__.py
src/rules/__init__.py
+2
-2
src/rules/integrals.py
src/rules/integrals.py
+32
-1
tests/test_rules_integrals.py
tests/test_rules_integrals.py
+18
-1
No files found.
src/rules/__init__.py
View file @
92f967d6
...
...
@@ -26,7 +26,7 @@ from .logarithmic import match_constant_logarithm, \
from
.integrals
import
match_solve_indef
,
match_constant_integral
,
\
match_integrate_variable_power
,
match_factor_out_constant
,
\
match_division_integral
,
match_function_integral
,
\
match_sum_rule_integral
match_sum_rule_integral
,
match_remove_indef_constant
from
.lineq
import
match_move_term
from
.absolute
import
match_factor_out_abs_term
...
...
@@ -62,7 +62,7 @@ RULES = {
OP_INT
:
[
match_integrate_variable_power
,
match_constant_integral
,
match_factor_out_constant
,
match_division_integral
,
match_function_integral
,
match_sum_rule_integral
],
OP_INT_INDEF
:
[
match_solve_indef
],
OP_INT_INDEF
:
[
match_
remove_indef_constant
,
match_
solve_indef
],
OP_EQ
:
[
match_move_term
],
OP_ABS
:
[
match_factor_out_abs_term
],
}
src/rules/integrals.py
View file @
92f967d6
...
...
@@ -319,7 +319,6 @@ def match_sum_rule_integral(node):
if
not
node
[
0
].
is_op
(
OP_ADD
):
return
[]
p
=
[]
scope
=
Scope
(
node
[
0
])
if
len
(
scope
)
==
2
:
...
...
@@ -341,3 +340,35 @@ def sum_rule_integral(root, args):
MESSAGES
[
sum_rule_integral
]
=
_
(
'Apply the sum rule to {0}.'
)
def
match_remove_indef_constant
(
node
):
"""
[f(x) + c]_a^b -> [f(x)]_a^b
"""
assert
node
.
is_op
(
OP_INT_INDEF
)
if
not
node
[
0
].
is_op
(
OP_ADD
):
return
[]
scope
=
Scope
(
node
[
0
])
x
=
find_variable
(
node
[
0
])
constants
=
[
n
for
n
in
scope
if
not
n
.
contains
(
x
)]
return
[
P
(
node
,
remove_indef_constant
,
(
scope
,
c
))
for
c
in
constants
]
def
remove_indef_constant
(
root
,
args
):
"""
[f(x) + c]_a^b -> [f(x)]_a^b
"""
scope
,
c
=
args
scope
.
remove
(
c
)
Fx
=
scope
.
as_nary_node
()
a
,
b
=
root
[
1
:]
return
indef
(
Fx
,
a
,
b
)
MESSAGES
[
remove_indef_constant
]
=
\
_
(
'Remove constant {2} from indefinite integral.'
)
tests/test_rules_integrals.py
View file @
92f967d6
...
...
@@ -6,7 +6,8 @@ from src.rules.integrals import indef, choose_constant, solve_integral, \
factor_out_constant
,
match_division_integral
,
division_integral
,
\
extend_division_integral
,
match_function_integral
,
\
logarithm_integral
,
sinus_integral
,
cosinus_integral
,
\
match_sum_rule_integral
,
sum_rule_integral
match_sum_rule_integral
,
sum_rule_integral
,
\
match_remove_indef_constant
,
remove_indef_constant
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
...
@@ -179,3 +180,19 @@ class TestRulesIntegrals(RulesTestCase):
tree
(
'int 3x dx + int 2x + 4x dx'
))
self
.
assertEqual
(
sum_rule_integral
(
root
,
(
Scope
(
root
[
0
]),
h
)),
tree
(
'int 4x dx + int 2x + 3x dx'
))
def
test_match_remove_indef_constant
(
self
):
Fx
,
a
,
b
=
root
=
tree
(
'[2x + c]_a^b'
)
self
.
assertEqualPos
(
match_remove_indef_constant
(
root
),
[
P
(
root
,
remove_indef_constant
,
(
Scope
(
Fx
),
Fx
[
1
]))])
Fx
,
a
,
b
=
root
=
tree
(
'[2x + x]_a^b'
)
self
.
assertEqualPos
(
match_remove_indef_constant
(
root
),
[])
Fx
,
a
,
b
=
root
=
tree
(
'[2x]_a^b'
)
self
.
assertEqualPos
(
match_remove_indef_constant
(
root
),
[])
def
test_remove_indef_constant
(
self
):
root
,
e
=
tree
(
'[2x + c]_a^b, [2x]_a^b'
)
Fx
=
root
[
0
]
self
.
assertEqual
(
remove_indef_constant
(
root
,
(
Scope
(
Fx
),
Fx
[
1
])),
e
)
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