Skip to content

Multiplicative Inverse

import mathy_core.rules.multiplicative_inverse
The Multiplicative Inverse rule converts division operations into multiplication by the reciprocal. This transformation can simplify the structure of mathematical expressions and prepare them for further simplification.

This rule is expressed with the equation a / b = a * (1 / b)

Convert Division to Multiplication by Reciprocal

This handles the a / b conversion to a * (1 / b).

Handle Division by a Negative Denominator

When the denominator is negative, the rule handles it by negating the numerator and converting the division into multiplication by the positive reciprocal of the denominator.

This handles the 4 / -(2 + 3) conversion to 4 * -1 / (2 + 3)

Examples

Info

All the examples shown below are drawn from the mathy test suite that verifies the expected input/output combinations for rule transformations.

Input Output Valid
4 / -(2 + 3) 4 * -1 / (2 + 3)
(21x^3 - 35x^2) / 7x (21x^3 - 35x^2) * 1 / 7x
(x^2 + 4x + 4) / (2x - 2) (x^2 + 4x + 4) * 1 / (2x - 2)
(2 + 3x) / 2x (2 + 3x) * 1 / 2x
((x + 1) / -(y + 2)) (x + 1) * -1 / (y + 2)

API

MultiplicativeInverseRule

MultiplicativeInverseRule(self, args, kwargs)
Convert division operations to multiplication by the reciprocal.

get_type

MultiplicativeInverseRule.get_type(
    self, 
    node: mathy_core.expressions.MathExpression, 
) -> Optional[str]
Determine the configuration of the tree for this transformation.

Support different types of tree configurations based on the division operation: - DivisionExpression restated as multiplication by reciprocal - DivisionNegativeDenominator is a division by a negative term