Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
df52ff73
Unverified
Commit
df52ff73
authored
Jun 04, 2019
by
peastman
Committed by
GitHub
Jun 04, 2019
Browse files
Merge pull request #2312 from peastman/sqrt
Algebraic optimizations
parents
5a244b5c
0bf7b063
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
libraries/lepton/src/ParsedExpression.cpp
libraries/lepton/src/ParsedExpression.cpp
+10
-0
tests/TestParser.cpp
tests/TestParser.cpp
+2
-0
No files found.
libraries/lepton/src/ParsedExpression.cpp
View file @
df52ff73
...
@@ -271,6 +271,16 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
...
@@ -271,6 +271,16 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio
return
ExpressionTreeNode
(
new
Operation
::
MultiplyConstant
(
-
dynamic_cast
<
const
Operation
::
MultiplyConstant
*>
(
&
node
.
getOperation
())
->
getValue
()),
children
[
0
].
getChildren
()[
0
]);
return
ExpressionTreeNode
(
new
Operation
::
MultiplyConstant
(
-
dynamic_cast
<
const
Operation
::
MultiplyConstant
*>
(
&
node
.
getOperation
())
->
getValue
()),
children
[
0
].
getChildren
()[
0
]);
break
;
break
;
}
}
case
Operation
::
SQRT
:
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQUARE
)
// sqrt(square(x)) = abs(x)
return
ExpressionTreeNode
(
new
Operation
::
Abs
(),
children
[
0
].
getChildren
()[
0
]);
}
case
Operation
::
SQUARE
:
{
if
(
children
[
0
].
getOperation
().
getId
()
==
Operation
::
SQRT
)
// square(sqrt(x)) = x
return
children
[
0
].
getChildren
()[
0
];
}
default:
default:
{
{
// If operation ID is not one of the above,
// If operation ID is not one of the above,
...
...
tests/TestParser.cpp
View file @
df52ff73
...
@@ -266,6 +266,8 @@ int main() {
...
@@ -266,6 +266,8 @@ int main() {
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.3
,
2.0
,
1.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.3
,
2.0
,
1.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.0
,
2.0
,
2.0
);
verifyEvaluation
(
"select(x, 1.0, y)"
,
0.0
,
2.0
,
2.0
);
verifyEvaluation
(
"atan2(x, y)"
,
3.0
,
1.5
,
std
::
atan
(
2.0
));
verifyEvaluation
(
"atan2(x, y)"
,
3.0
,
1.5
,
std
::
atan
(
2.0
));
verifyEvaluation
(
"sqrt(x^2)"
,
-
2.2
,
0.0
,
2.2
);
verifyEvaluation
(
"sqrt(x)^2"
,
2.2
,
0.0
,
2.2
);
verifyInvalidExpression
(
"1..2"
);
verifyInvalidExpression
(
"1..2"
);
verifyInvalidExpression
(
"1*(2+3"
);
verifyInvalidExpression
(
"1*(2+3"
);
verifyInvalidExpression
(
"5++4"
);
verifyInvalidExpression
(
"5++4"
);
...
...
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