Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
92f967d6
Commit
92f967d6
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added rule for removing constants from indefinite integrals.
parent
21c092de
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/rules/__init__.py
+2
-2
2 additions, 2 deletions
src/rules/__init__.py
src/rules/integrals.py
+32
-1
32 additions, 1 deletion
src/rules/integrals.py
tests/test_rules_integrals.py
+18
-1
18 additions, 1 deletion
tests/test_rules_integrals.py
with
52 additions
and
4 deletions
src/rules/__init__.py
+
2
−
2
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
],
}
This diff is collapsed.
Click to expand it.
src/rules/integrals.py
+
32
−
1
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.
'
)
This diff is collapsed.
Click to expand it.
tests/test_rules_integrals.py
+
18
−
1
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment