expandAll error

Issue #122 resolved
oden dengaku created an issue

when I tried to expand below expression, error occured

( ( ( X3 - X1_c) * ( ( X1 + ( ( X4_c * X3 ) + X5_c)) + X3_b)) * ( ( X3 - X1 ) + ( X3_c + X5 )))

and error is

Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeHi(TimSort.java:899) at java.util.TimSort.mergeAt(TimSort.java:516) at java.util.TimSort.mergeCollapse(TimSort.java:441) at java.util.TimSort.sort(TimSort.java:245) at java.util.Arrays.sort(Arrays.java:1512) at org.matheclipse.core.eval.Range.sort(Range.java:764) at org.matheclipse.core.eval.EvalAttributes.sort(EvalAttributes.java:187) at org.matheclipse.core.eval.EvalEngine.evalFlatOrderlessAttributesRecursive(EvalEngine.java:926) at org.matheclipse.core.eval.PlusOp.plus(PlusOp.java:271) at org.matheclipse.core.reflection.system.Expand$Expander.expandPlusTimesPlus(Expand.java:299) at org.matheclipse.core.reflection.system.Expand$Expander.expandTimesBinary(Expand.java:272) at org.matheclipse.core.reflection.system.Expand$Expander.expandTimes(Expand.java:256) at org.matheclipse.core.reflection.system.Expand$Expander.expandAST(Expand.java:63) at org.matheclipse.core.reflection.system.Expand.expand(Expand.java:425) at org.matheclipse.core.reflection.system.ExpandAll.expandAll(ExpandAll.java:78) at org.matheclipse.core.reflection.system.ExpandAll.evaluate(ExpandAll.java:27) at org.matheclipse.core.eval.EvalEngine.evalASTBuiltinFunction(EvalEngine.java:721) at org.matheclipse.core.eval.EvalEngine.evalASTArg1(EvalEngine.java:655) at org.matheclipse.core.eval.EvalEngine.evalAttributes(EvalEngine.java:751) at org.matheclipse.core.eval.EvalEngine.evalAST(EvalEngine.java:588) at org.matheclipse.core.expression.AbstractAST.evaluate(AbstractAST.java:659) at org.matheclipse.core.eval.EvalEngine.evalLoop(EvalEngine.java:997) at org.matheclipse.core.eval.EvalEngine.evalWithoutNumericReset(EvalEngine.java:1396) at org.matheclipse.core.eval.EvalEngine.evaluate(EvalEngine.java:1341) at org.matheclipse.core.eval.ExprEvaluator.evaluate(ExprEvaluator.java:205) at org.matheclipse.core.eval.ExprEvaluator.evaluate(ExprEvaluator.java:225)

I know in some case Timsort cause this type of error (A<B and B<A in one eval), but I dont know why error occurs in this evalation. Is there any restriction on variable name?

Thanks.

Comments (11)

  1. Axel Kramer repo owner

    Some variable names are parsed as patterns Is this intended?

    If not, don't use '_' (underscores) in variable names.

    For example x1_c:

    2016-07-15 18_15_22-Debug-java.util.TimSort.png

  2. oden dengaku reporter

    No, X1_c is a one variable,so I don't want to separate it. Should I name variables in one character? I wonder this error occurs rarely.

  3. Axel Kramer repo owner

    x1_c is parsed as pattern "x1_" with condition "c". You can use the '$' sign as a special character in symbol names.

    Nethertheless this is a bug, which has to be solved.

  4. oden dengaku reporter

    I tried both, but the result was same.

    This is the code trying to expand.


        String fExpInOrder; //fExpInOrder is expression I want to expand.
        ExprEvaluator util = new ExprEvaluator(true, 0);
        IExpr result = util.evaluate("ExpandAll(" + fExpInOrder + ")");
        fExpandFomula = result.toString();
    

    These are the expressions error occur.

    ( ( $X2_c + ( $X2 - ( $X3_a - $X1 ) ) ) * ( $X2 + ( ( ( $X1_c + $X1 ) + ( ( $X1_a + ( ( $X4_a + $X1_c ) + $X2 ) ) - $X3_b ) ) + ( $X5_b + ( ( ( ( $X2_b + $X5 ) * ( $X2_b - $X4 ) ) * $X3 ) + $X1 ) ) ) ) )

    ( ( ( ( ( X3$_b - X1$_c ) - ( X3 - ( ( X2$_a + X3$_c ) - X5$_a ) ) ) - X1 ) - X5 ) * ( X4 + ( ( X3 * ( X1$_b - X1 ) ) + X1$_c ) ) )

    below is a sample expression that is expanded corrctly.

    ( X5 - ( ( ( X1$_c - ( ( X5$_b + X3$_c ) + X1 ) ) + X3 ) * ( ( X4$_a + ( ( ( X1 - X3$_b ) * X5$_b ) + X2$_a ) ) - X5$_c ) ) )

    to

    x5+x1x2$_a-x3x2$_a-x1$_cx2$_a+x2$_ax3$_c+x1x4$_a-x3x4$_a-x1$_cx4$_a+x3$_cx4$_a-x1x3x5$_b-x1x1$_cx5$_b+x2$_ax5$_b-x1x3$_bx5$_b+x3x3$_bx5$_b+x1$_cx3$_bx5$_b+x1x3$_cx5$_b-x3$_bx3$_cx5$_b+x4$_ax5$_b-x1x5$_c+x3x5$_c+x1$_cx5$_c-x3$_cx5$_c-x5$_bx5$_c+x5$_bx1^2+x1x5$_b^2-x3$_bx5$_b^2

  5. Axel Kramer repo owner

    I meant: ExpandAll(( ( ( X3 - X1$c) * ( ( X1 + ( ( X4$c * X3 ) + X5$c)) + X3$b)) * ( ( X3 - X1 ) + ( X3$c + X5 ))))

  6. Axel Kramer repo owner

    I fixed the exception with commit: de90402

    The fix still needs some additional clean up for output of special cases like:

    a+b-Infinity
    
  7. Log in to comment