Skip to content

Commit 226f15e

Browse files
committed
Change F.symjify() method - evaluate after parsing by default
1 parent 837d057 commit 226f15e

File tree

2 files changed

+28
-7
lines changed
  • symja_android_library/matheclipse-core/src

2 files changed

+28
-7
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,7 +4395,7 @@ public static IAST Symmetric(final IExpr a0) {
43954395
}
43964396

43974397
/**
4398-
* Converts an arbitrary expression to a type that can be used inside Symja.
4398+
* Converts and evaluates arbitrary expressiona to a Symja type.
43994399
*
44004400
* <pre>
44014401
* Java Object -&gt; Symja object
@@ -4423,20 +4423,41 @@ public static IAST Symmetric(final IExpr a0) {
44234423
*
44244424
*/
44254425
public static IExpr symjify(final Object object) {
4426-
return Object2Expr.convert(object);
4426+
return symjify(object, true);
4427+
}
4428+
4429+
public static IExpr symjify(final Object object, boolean evaluate) {
4430+
IExpr temp = Object2Expr.convert(object);
4431+
return evaluate ? eval(temp) : temp;
4432+
}
4433+
4434+
/**
4435+
* Parses and evaluates a Java string to a Symja expression. May throw an SyntaxError exception, if the string couldn't be parsed.
4436+
*
4437+
* @param str
4438+
* the epression which should be parsed
4439+
* @return
4440+
* @throws SyntaxError
4441+
*/
4442+
public static IExpr symjify(final String str) throws SyntaxError {
4443+
return symjify(str, true);
44274444
}
44284445

44294446
/**
44304447
* Parses a Java string to a Symja expression. May throw an SyntaxError exception, if the string couldn't be parsed.
44314448
*
44324449
* @param str
44334450
* the epression which should be parsed
4451+
* @param evaluate
4452+
* if true evaluate the parsed string
44344453
* @return
44354454
* @throws SyntaxError
44364455
*/
4437-
public static IExpr symjify(final String str) throws SyntaxError {
4438-
ExprParser parser = new ExprParser(EvalEngine.get());
4439-
return parser.parse(str);
4456+
public static IExpr symjify(final String str, boolean evaluate) throws SyntaxError {
4457+
EvalEngine engine = EvalEngine.get();
4458+
ExprParser parser = new ExprParser(engine);
4459+
IExpr temp = parser.parse(str);
4460+
return evaluate ? engine.evaluate(temp) : temp;
44404461
}
44414462

44424463
public static IExpr symjify(final long value) {

symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SymjifyTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.matheclipse.core.interfaces.IExpr;
55

66
/**
7-
*
7+
* Test F.symjify()
88
*/
99
public class SymjifyTestCase extends AbstractTestCase {
1010
public SymjifyTestCase(String name) {
@@ -13,7 +13,7 @@ public SymjifyTestCase(String name) {
1313

1414
public void test001() {
1515
IExpr expr = F.symjify("(a+(b+c))");
16-
assertEquals(expr.fullFormString(), "Plus(a, Plus(b, c))");
16+
assertEquals(expr.fullFormString(), "Plus(a, b, c)");
1717
assertEquals(expr.toString(), "a+b+c");
1818
}
1919

0 commit comments

Comments
 (0)