# What makes Rational.reduce?

#1

What makes Rational.reduce?
For example:

``````let expr = "(x^2 - 25)/(5*x - x^2)" |> Infix.parseOrUndefined

expr
|> Infix.format
|> printfn "%s"

expr
|> Rational.reduce
|> Infix.format
|> printfn "%s"
``````

Print:

``````(-25 + x^2)/(5*x - x^2)
(-25 + x^2)/(5*x - x^2)
``````

although I expected reduction

(Christoph Rüegg) #2

Maybe the name is a bit misleading. `Rational.reduce` tries removing factors common to all terms (monomial) of a rational expression, involving among others computing polynomial GCDs. It is used in `Rational.expand`.

Simple example: In `(8*a*x + 6*a*x**2)/(4*x*a)` all monomials share the common factor `2*a*x`. The expression auto-simplifies to `((1/4)*(8*a*x + 6*a*x^2))/(a*x)` which still includes this factor, even though a bit hidden. `Rational.reduce` recognizes and removes this factor, resulting in `(1/2)*(4 + 3*x)`.

(Christoph Rüegg) #3

What result would you have expected?

(Christoph Rüegg) #4

`Rational.expand` does not expand this further; I think we should extend it to call `Algebraic.expand` as last step if the result at this point has a denominator of 1, so it would return `2 + (3/2)*x`.

#5

Thank you, now everything is clear.

I expected to get:
`-(5 + x)/x`
the same as when Rational.simplify