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
2ed4de97
Commit
2ed4de97
authored
Mar 26, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added notation for indefinite integrals.
parent
8600bb1f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
8 deletions
+26
-8
src/node.py
src/node.py
+1
-0
src/parser.py
src/parser.py
+8
-4
src/rules/integrals.py
src/rules/integrals.py
+11
-3
tests/test_parser.py
tests/test_parser.py
+6
-1
No files found.
src/node.py
View file @
2ed4de97
...
...
@@ -91,6 +91,7 @@ OP_MAP = {
OP_VALUE_MAP
=
dict
([(
v
,
k
)
for
k
,
v
in
OP_MAP
.
iteritems
()])
OP_MAP
[
'ln'
]
=
OP_LOG
OP_VALUE_MAP
[
OP_INT_INDEF
]
=
'indef'
TOKEN_MAP
=
{
OP_COMMA
:
'COMMA'
,
...
...
src/parser.py
View file @
2ed4de97
...
...
@@ -398,6 +398,7 @@ class Parser(BisonParser):
| bracket_derivative
| INTEGRAL exp
| integral_bounds TIMES exp %prec INTEGRAL
| LBRACKET exp RBRACKET lbnd ubnd
"""
if
option
==
0
:
# rule: NEG exp
...
...
@@ -460,14 +461,17 @@ class Parser(BisonParser):
return
Node
(
OP_INT
,
fx
,
x
,
lbnd
,
ubnd
)
if
option
==
7
:
# rule: LBRACKET exp RBRACKET lbnd ubnd
return
Node
(
OP_INT_INDEF
,
values
[
1
],
values
[
3
],
values
[
4
])
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
def
on_integral_bounds
(
self
,
target
,
option
,
names
,
values
):
"""
integral_bounds : INTEGRAL lbnd
r
bnd
integral_bounds : INTEGRAL lbnd
u
bnd
"""
if
option
==
0
:
# rule: INTEGRAL lbnd
r
bnd
if
option
==
0
:
# rule: INTEGRAL lbnd
u
bnd
return
values
[
1
],
values
[
2
]
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
...
...
@@ -483,9 +487,9 @@ class Parser(BisonParser):
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
def
on_
r
bnd
(
self
,
target
,
option
,
names
,
values
):
def
on_
u
bnd
(
self
,
target
,
option
,
names
,
values
):
"""
r
bnd : POW exp
u
bnd : POW exp
"""
if
option
==
0
:
# rule: POW exp
return
values
[
1
]
...
...
src/rules/integrals.py
View file @
2ed4de97
...
...
@@ -2,16 +2,24 @@ from .utils import find_variables, first_sorted_variable, infinity, \
replace_variable
from
.logarithmic
import
ln
#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
,
\
OP_INT_INDEF
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
def
integral
(
f
,
*
args
):
def
integral
(
*
args
):
"""
Create an integral node.
"""
return
N
(
OP_INT
,
*
((
f
,)
+
args
))
return
N
(
OP_INT
,
*
args
)
def
indef
(
*
args
):
"""
Create an indefinite integral node.
"""
return
N
(
OP_INT_INDEF
,
*
args
)
#def integral_params(integral):
...
...
tests/test_parser.py
View file @
2ed4de97
...
...
@@ -9,7 +9,7 @@ from tests.rulestestcase import tree
from
src.rules.goniometry
import
sin
,
cos
from
src.rules.derivatives
import
der
from
src.rules.logarithmic
import
log
,
ln
from
src.rules.integrals
import
integral
from
src.rules.integrals
import
integral
,
indef
class
TestParser
(
unittest
.
TestCase
):
...
...
@@ -111,3 +111,8 @@ class TestParser(unittest.TestCase):
self
.
assertEqual
(
tree
(
'int_a^b x2 dy'
),
integral
(
x
**
2
,
y
,
a
,
b
))
self
.
assertEqual
(
tree
(
'int_(a-b)^(a+b) x2'
),
integral
(
x
**
2
,
x
,
a
-
b
,
a
+
b
))
def
test_indefinite_integral
(
self
):
x2
,
a
,
b
=
tree
(
'x ^ 2, a, b'
)
self
.
assertEqual
(
tree
(
'[x ^ 2]_a^b'
),
indef
(
x2
,
a
,
b
))
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