question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canonical rules for fraction numerators

See original GitHub issue

Hi all! I’m super interested in MathJSON, and I’m trying to set up MathLive/Compute in a personal project.

I was working on comparing linear equations with simplify/evaluate/canonical and found that I couldn’t get a consistent representation for (-7/4)x+10

const answerbox="\\frac{-7x}{4}+10"

const answer = [  "Add", [ "Multiply", [ "Divide", -7, 4 ], "x" ], 10]

  match(
    ce.evaluate(ce.parse(answerbox)),
    ce.evaluate(answer)
  )
);

Is this a case where I need to use additional rewrite rules to coerce this into a unique ‘canonical’ form for comparison, or is this within the scope of the canonical function?

image image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
stefnotchcommented, Nov 11, 2021

Here is the relevant sympy documentation. Typing the following into the sympy live shell (bottom right of the documentation page) does demonstrate that behavior:

expr = x/y
srepr(expr)

image

Of course if that turns out to be more trouble than it’s worth, that’s an entirely valid reason for not including it.

2reactions
arnogcommented, Nov 10, 2021

It feels a bit weird to me to not have division in the canonical form (admittedly, an earlier version of the Compute Engine did just that). That also makes some simplification rules more difficult to write since instead of detecting patterns of the form a/b you now have to pick up a*c*d where c (or d) is of the form b^-1.

Can you tell me more about Sympy’s expectations in that regard? Do you have a pointer in the documentation that discusses this and perhaps a rationale for it?

On a broader note, I intend in an upcoming revision, to have clearer lines between ‘formatting’ (i.e. putting into a canonical form) and ‘simplifying’. Formatting will not account for any calculations (i.e. multiply by 1), but will focus on sorting arguments of commutative functions, and reducing associative, idempotent and involutory functions. Simplify on the other hand will apply more rules, including ones depending on the numerical values of the arguments, and other ‘assumptions’ about arguments (for example whether an argument is a positive real, or a complex number, etc…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Continued fraction - Wikipedia
In mathematics, a continued fraction is an expression obtained through an iterative process ... It is generally assumed that the numerator of all...
Read more >
Fraction Rules: Algebraic rules for working with fractions.
Fraction rules are a set of algebraic rules for working with fractions. A fraction has a numerator and a denominator. A fraction represents...
Read more >
How to set up fractions III - canonical forms via the Euclidean ...
In order to deal with fractions smoothly, young students need to learn about canonical forms for fractions --where the numerators and ...
Read more >
A simple canonical representation of rational numbers
We describe the relation between this representation of numbers and the representation as fractions of non-zero natural numbers. The usual operations of.
Read more >
How to Add Fractions with Different Denominators - dummies
Start out by multiplying the numerator of the first fraction by the denominators of all the other fractions. · Do the same with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found