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
74d5caf1
Commit
74d5caf1
authored
Mar 26, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added short notation for absolute values as only function parameter.
parent
56256eb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
src/node.py
src/node.py
+14
-3
tests/test_node.py
tests/test_node.py
+4
-0
No files found.
src/node.py
View file @
74d5caf1
...
...
@@ -282,17 +282,22 @@ class ExpressionNode(Node, ExpressionBase):
return
'd/d%s (%s)'
%
(
children
[
1
],
f
)
if
self
.
op
==
OP_LOG
:
if
self
[
0
].
is_op
(
OP_ABS
):
content
=
children
[
0
]
else
:
content
=
'('
+
children
[
0
]
+
')'
# log(a, e) -> ln(a)
if
self
[
1
].
is_identifier
(
E
):
return
'ln
(%s)'
%
children
[
0
]
return
'ln
%s'
%
content
# log(a, 10) -> log(a)
if
self
[
1
]
==
10
:
return
'log
(%s)'
%
children
[
0
]
return
'log
%s'
%
content
# log(a, 2) -> log_2(a)
if
children
[
1
].
isdigit
():
return
'log_%s
(%s)'
%
(
children
[
1
],
children
[
0
]
)
return
'log_%s
%s'
%
(
children
[
1
],
content
)
if
self
.
op
==
OP_INT
:
# Make sure that any needed parentheses around f(x) are generated,
...
...
@@ -324,6 +329,12 @@ class ExpressionNode(Node, ExpressionBase):
if self.op == OP_ABS:
return '
|%
s
|
' % children[0]
# Function with absolute value as only parameter does not need
# parentheses
if self.op in TOKEN_MAP and TOKEN_MAP[self.op] == '
FUNCTION
'
\
and len(self) == 1 and self[0].is_op(OP_ABS):
return self.title() + children[0]
def __str__(self): # pragma: nocover
return generate_line(self)
...
...
tests/test_node.py
View file @
74d5caf1
...
...
@@ -245,3 +245,7 @@ class TestNode(RulesTestCase):
self
.
assertEqual
(
str
(
tree
(
'[x ^ 2]_a^b'
)),
'[x ^ 2]_a^b'
)
self
.
assertEqual
(
str
(
tree
(
'[x ^ 2]_(a-b)^(a+b)'
)),
'[x ^ 2]_(a - b)^(a + b)'
)
def
test_construct_function_absolute_child
(
self
):
self
.
assertEqual
(
str
(
tree
(
'ln(|x|)'
)),
'ln|x|'
)
self
.
assertEqual
(
str
(
tree
(
'sin(|x|)'
)),
'sin|x|'
)
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