Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression rationalization gets stuck or takes too long (it worked in V9.5.1) #3351

Open
OndrejBukovsky opened this issue Jan 16, 2025 · 5 comments

Comments

@OndrejBukovsky
Copy link

Describe the bug
Recently, I updated Math.js from version 9.5.1 to the latest version, and an expression rationalization that worked before doesn't work anymore. (see To Reproduce)

To Reproduce

import * as mathjs from 'mathjs';

const aa = mathjs.parse("6285.67^5/(s+6285.67)^5");
const bb = mathjs.rationalize(aa, {}, false); // It gets stuck here

console.log(bb.toString());
@josdejong
Copy link
Owner

Thanks for reporting. I played around with it and simplied the example case a bit:

math.rationalize("(x + 1)^4") // slow
math.rationalize("(x + 1)^5") // takes forever

I guess the function expands the expression into (x + 1) * (x + 1) * (x + 1) * (x + 1) * (x + 1) and then goes over all possibilities, which grows exponentially the larger the exponent is. Not sure though, just a wild guess.

Help debugging and understanding what's going on here would be welcome.

@josdejong
Copy link
Owner

Since this worked in v9.5.1, a first step can be to understand the changes in rationalize since then.

@OndrejBukovsky
Copy link
Author

Thank you for your response. If I have time, I will try to help with the investigation.

@josdejong
Copy link
Owner

Thanks!

@gwhitney
Copy link
Collaborator

Can confirm, this now prevents the doc tests from running at all in #3375, as it attempts to rationalize (2x+1)^6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants