Fraction.js icon indicating copy to clipboard operation
Fraction.js copied to clipboard

math.Fraction.REDUCE doesn't work from mathjs 10.0.1

Open chrisbansart opened this issue 2 years ago • 3 comments

Hi, First of all, thanks for the fantastic work on fractions. I think I've figured out a bug with the flag math.Fraction.REDUCE allowing to reduce or not fractions automaticly. With mathjs 10.0.0 the code :

math.Fraction.REDUCE = false;
var f = math.Fraction(3, 6);
console.log(f); // gives {s: 1, n: 3, d: 6, …}

From mathjs 10.0.1 the code :

math.Fraction.REDUCE = false;
var f = math.Fraction(3, 6);
console.log(f); // gives {s: 1, n: 1, d: 2, …}

Thus, it seems that from mathjs 10.0.1 the REDUCE flag has no more effect. Thanks for your help. Chris

chrisbansart avatar Apr 16 '22 13:04 chrisbansart

Added comment : It seems that you have remove in 4.2.0 the Fraction['REDUCE'] tests.

Therefore, my workaround is to come back to mathjs 10.0.0 and install manually fraction.js version 4.1.1 npm install --save [email protected] and it works again.

chrisbansart avatar Apr 16 '22 14:04 chrisbansart

Yes, I removed this as it introduced overflow problems quickly and I did not like the implementation. It was added due to a bug report back then, but after running an operation on a fraction (like adding, multiplying, ...), the result can be something not expected, due to the way the operations are implemented internally. And from my perspective, and probably the standard definition, a fraction only is the ratio of numerator and denominator and thus makes much more sense to keep it in a reduced form. I searched for it in mathjs to not introduce a bug, but didn't know that people try to use it outside, like you did. Can you elaborate, what you're trying to do and why you need a not reduced fraction?

infusion avatar Apr 17 '22 20:04 infusion

Hello, actually I've figured out the use of the flag math.Fraction.REDUCE in an old message in this repo. Regarding my need, it's still a core feature that I implemented in the core of my project two years ago. I've been using it for educational purposes to offer learners the opportunity to work with non-reduced fractions as well as reduced fractions. For instance, I can generate non-reduced Fractions and ask learners to find their irreducible forms. Concretely I set Fraction.REDUCE globally to false to control manually the reduction of fractions. Depending on my needs, I can reduce them with the gcd operator or not. Without ability to disable automatic reduction, I cannot anymore manipulate unreduced fractions and I'm coerced to only use reduced fractions. Thus, It is a real issue for pedagogical purpose. Hope we could find a workaround...

chrisbansart avatar Apr 17 '22 21:04 chrisbansart