mathjs: `simplify()` returns `RangeError: Maximum call stack size exceeded` for certain expressions containing `n`

Not OK

The n mixed with - or / seems to be an issue.

math.simplify('2n - 1').toString();
math.simplify('16n - 1').toString();
math.simplify('16n / 1').toString();
math.simplify('8 / 5n').toString();
math.simplify('8n - 4n').toString();

OK

math.simplify('n - 1').toString();
math.simplify('1n - 1').toString();
math.simplify('2n + 1').toString();
math.simplify('2z - 1').toString();
math.simplify('2n -- 1').toString();

Workaround

math.simplify('2n - 1',[]).toString();

[]: no rules applied.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Resolved by #950

Ok. I will try to take a closer look tonight.

On Sep 30, 2017 8:11 AM, “Jos de Jong” notifications@github.com wrote:

there shouldn’t be a direct string comparison between a pattern and an input expression

that sounds even better than my suggestions…

The issue does not occur with symbols that are not used in the rules:

math.simplify(‘2x - 1’).toString(); // OKmath.simplify(‘2n - 1’).toString(); // NOT OK (infinite loop)math.simplify(‘2n1 - 1’).toString(); // NOT OK (returns 1)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/948#issuecomment-333311118, or mute the thread https://github.com/notifications/unsubscribe-auth/AGDTkQyZgFe0EYJy6-VlftNF3RiEeiynks5snkwZgaJpZM4PmtFi .