Skip to content

Commit

Permalink
#225 use replaceRepeated() instead of replaceAll() to substitute the
Browse files Browse the repository at this point in the history
variables

-  now returns `{v2*v2+v2&,{v1->#1,v2->1+v1}}` for the example App
  • Loading branch information
axkr committed May 25, 2021
1 parent 6c0cd2f commit d22ac8d
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ public IASTMutable apply(IASTMutable t) {
*/
private static class ShareReplaceAll extends VisitorExpr {
final Function<IASTMutable, IASTMutable> fFunction;
public int fCounter;

public ShareReplaceAll(Function<IASTMutable, IASTMutable> function) {
super();
this.fFunction = function;
this.fCounter = 0;
}

@Override
Expand All @@ -113,7 +111,6 @@ public IExpr visit(IASTMutable ast) {
}
IExpr temp = fFunction.apply(ast);
if (temp.isPresent()) {
fCounter++;
return temp;
}
return visitAST(ast);
Expand Down Expand Up @@ -187,7 +184,7 @@ private static IExpr optimizeExpression(final IASTMutable ast) {
variableSubstitutions.append(F.Rule(reference, dummyVariable));
varCounter++;
}
sharedExpr = sharedExpr.replaceAll(variableSubstitutions);
sharedExpr = sharedExpr.replaceRepeated(variableSubstitutions);
if (sharedExpr.isPresent()) {
return F.List(sharedExpr, replaceList);
}
Expand Down

0 comments on commit d22ac8d

Please sign in to comment.