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
c0ad3f03
"platforms/vscode:/vscode.git/clone" did not exist on "79ed6274f7750201c08dbc66da29c0890bae0ec6"
Commit
c0ad3f03
authored
Nov 20, 2009
by
Peter Eastman
Browse files
Improved display of expressions when printing them to a stream
parent
055e308a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
8 deletions
+34
-8
libraries/lepton/include/lepton/Operation.h
libraries/lepton/include/lepton/Operation.h
+21
-0
libraries/lepton/src/ParsedExpression.cpp
libraries/lepton/src/ParsedExpression.cpp
+13
-8
No files found.
libraries/lepton/include/lepton/Operation.h
View file @
c0ad3f03
...
@@ -96,6 +96,12 @@ public:
...
@@ -96,6 +96,12 @@ public:
* @param variable the variable with respect to which the derivate should be taken
* @param variable the variable with respect to which the derivate should be taken
*/
*/
virtual
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
=
0
;
virtual
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
=
0
;
/**
* Get whether this operation should be displayed with infix notation.
*/
virtual
bool
isInfixOperator
()
const
{
return
false
;
}
virtual
bool
operator
!=
(
const
Operation
&
op
)
const
{
virtual
bool
operator
!=
(
const
Operation
&
op
)
const
{
return
op
.
getId
()
!=
getId
();
return
op
.
getId
()
!=
getId
();
}
}
...
@@ -264,6 +270,9 @@ public:
...
@@ -264,6 +270,9 @@ public:
return
args
[
0
]
+
args
[
1
];
return
args
[
0
]
+
args
[
1
];
}
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
};
class
Operation
::
Subtract
:
public
Operation
{
class
Operation
::
Subtract
:
public
Operation
{
...
@@ -286,6 +295,9 @@ public:
...
@@ -286,6 +295,9 @@ public:
return
args
[
0
]
-
args
[
1
];
return
args
[
0
]
-
args
[
1
];
}
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
};
class
Operation
::
Multiply
:
public
Operation
{
class
Operation
::
Multiply
:
public
Operation
{
...
@@ -308,6 +320,9 @@ public:
...
@@ -308,6 +320,9 @@ public:
return
args
[
0
]
*
args
[
1
];
return
args
[
0
]
*
args
[
1
];
}
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
};
class
Operation
::
Divide
:
public
Operation
{
class
Operation
::
Divide
:
public
Operation
{
...
@@ -330,6 +345,9 @@ public:
...
@@ -330,6 +345,9 @@ public:
return
args
[
0
]
/
args
[
1
];
return
args
[
0
]
/
args
[
1
];
}
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
};
class
Operation
::
Power
:
public
Operation
{
class
Operation
::
Power
:
public
Operation
{
...
@@ -352,6 +370,9 @@ public:
...
@@ -352,6 +370,9 @@ public:
return
std
::
pow
(
args
[
0
],
args
[
1
]);
return
std
::
pow
(
args
[
0
],
args
[
1
]);
}
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
};
class
Operation
::
Negate
:
public
Operation
{
class
Operation
::
Negate
:
public
Operation
{
...
...
libraries/lepton/src/ParsedExpression.cpp
View file @
c0ad3f03
...
@@ -239,15 +239,20 @@ ExpressionProgram ParsedExpression::createProgram() const {
...
@@ -239,15 +239,20 @@ ExpressionProgram ParsedExpression::createProgram() const {
}
}
ostream
&
Lepton
::
operator
<<
(
ostream
&
out
,
const
ExpressionTreeNode
&
node
)
{
ostream
&
Lepton
::
operator
<<
(
ostream
&
out
,
const
ExpressionTreeNode
&
node
)
{
out
<<
node
.
getOperation
().
getName
();
if
(
node
.
getOperation
().
isInfixOperator
()
&&
node
.
getChildren
().
size
()
==
2
)
{
if
(
node
.
getChildren
().
size
()
>
0
)
{
out
<<
"("
<<
node
.
getChildren
()[
0
]
<<
")"
<<
node
.
getOperation
().
getName
()
<<
"("
<<
node
.
getChildren
()[
1
]
<<
")"
;
out
<<
"("
;
}
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
().
size
();
i
++
)
{
else
{
if
(
i
>
0
)
out
<<
node
.
getOperation
().
getName
();
out
<<
", "
;
if
(
node
.
getChildren
().
size
()
>
0
)
{
out
<<
node
.
getChildren
()[
i
];
out
<<
"("
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
().
size
();
i
++
)
{
if
(
i
>
0
)
out
<<
", "
;
out
<<
node
.
getChildren
()[
i
];
}
out
<<
")"
;
}
}
out
<<
")"
;
}
}
return
out
;
return
out
;
}
}
...
...
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