Non-canonical form does not consistently parse fractions (Rational vs. Divide)
See original GitHub issueEither I don’t understand how this is supposed to work, or there is a bug here. Canonical form is explained in the documentation. The example shown is:
ce.parse("\\frac{3}{-5}")
// ➔ ["Rational", -3, 5]
ce.parse("\\frac{3}{-5}", {canonical: false})
// ➔ ["Divide", 3, -5]
However, it doesn’t really seem like setting canonical
to false
really does anything. Rather, it seems that fractions with positive numerators and denominators are parsed as Rational
while putting anything else in the numerator and denominator (including simply adding a -
) will result in a Divide
.
Example in this CodePen:
Sod the question is two-fold:
- Does setting
{canonical:false}
do anything in this context? I can’t seem to get it to work. - Aren’t fractions supposed to be interpreted as
Divide
rather thanRational
in the non-canonical parsing mode?
Thanks @arnog!
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Canonical Form - CortexJS
It is not always “the simplest” way to represent an expression. ... this is // interpreted as a regular fraction ("Divide"), not a...
Read more >fractions — Rational numbers — Python 3.11.1 documentation
The fractions module provides support for rational number arithmetic. A Fraction instance can be constructed from a pair of integers, from another rational...
Read more >Implementation of rational number arithmetic for .NET ... - GitHub
Reducing fractions, canonical form To reduce a fraction, you can use the CanonicalForm property. That returns a rational number that's irreducible, and where ......
Read more >The Real Numbers: Not All Decimals Are Fractions - Frontiers
A rational number is any number that we can write as a fraction a b of two integers (whole numbers or their negatives),...
Read more >c# - Convert a text fraction to a decimal - Stack Overflow
Try splitting it on the space and slash, something like: double FractionToDouble(string fraction) { double result; if(double.TryParse(fraction, out result)) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. Yeah, I think I understand that better now. I’m kinda new to issues (all of mine so far have been interactions with you) so thanks for your patience.
I tried your suggestion and that worked. Thank you so much!
The CodePen could be more useful if it demonstrated what the problem you are talking about is. It’s a fairly generic code that doesn’t demonstrate specifically the problem (I still have to know what I’m supposed to type in the field in order to see what the problem is), and it includes a lot of things that are not necessary to demonstrate the issue (some CSS, some UI, some event handling).
Since you ask, here’s what would have made it easier:
This is code that I can copy and paste to verify I get the same result, and I can clearly see what you are getting vs what you are expecting.
That said, to answer you question, if you want to avoid
Rational
in the json output, you can use this:The
exclude
JSON serialization option can be used to indicate identifiers that should be avoided and replaced by an equivalent form when possible. In this case,Rational
will be replaced with aDivide
.