Skip to content

Simplify inverts a quotient whose denominator has a negative factor #715

Description

@Rafael-SOWNet

Simplify returned the reciprocal of the right answer for a quotient whose denominator carried a negative factor.

"(1/x) / (-1 - 1/x)".ToEntity().Simplify()   =>   -(1 + x)

At x = 1 the expression is -1/2 and that answer is -2.

The cause is in Patterns.NumericNeatRules. Four of the rules there take a negative constant out of a product and multiply the rest by it, which is right. The two that take it out of a denominator were written the same way:

Divf(var any2, Mulf(Real { IsNegative: true } num, var any1)) => -((-num) * (any1 / any2)),

but a / (-b * c) is -(a / (b * c)), not -(b * (c / a)). Simplify keeps whichever of its candidates is shortest, so the inverted form won wherever it was smaller than the correct one -- which is wherever the numerator is 1, hence the shape above.

Found from a limit rather than by hand: l'Hopital's rule simplifies the quotient of derivatives it builds, and (1/x) / (-1 - 1/x) is the shape of one. lim x->0+ (tan(x) * ln(x)) came back NaN because of it.

Filing for the record -- the fix is in #714 with five regression cases, each checking the value at a point rather than the printed form.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions