Skip to content

Commit

Permalink
docs(rules): better multiplicative inverse docs
Browse files Browse the repository at this point in the history
  • Loading branch information
justindujardin committed Feb 6, 2024
1 parent 9663bba commit 3fa8012
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
17 changes: 17 additions & 0 deletions mathy_core/rules/multiplicative_inverse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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

`rule_tests:multiplicative_inverse`
18 changes: 1 addition & 17 deletions mathy_core/rules/multiplicative_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@


class MultiplicativeInverseRule(BaseRule):
r"""Multiplicative Inverse Property
`a / b = a * (1/b)`
The multiplicative inverse property involves converting division operations
into multiplication by the reciprocal. This transformation can simplify the
structure of mathematical expressions and prepare them for further simplification.
**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.
"""
"""Convert division operations to multiplication by the reciprocal."""

@property
def name(self) -> str:
Expand Down
4 changes: 4 additions & 0 deletions mathy_core/rules/multiplicative_inverse.test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"valid": [
{
"input": "4 / -(2 + 3)",
"output": "4 * -1 / (2 + 3)"
},
{
"input": "(21x^3 - 35x^2) / 7x",
"output": "(21x^3 - 35x^2) * 1 / 7x"
Expand Down
32 changes: 19 additions & 13 deletions website/docs/api/rules/multiplicative_inverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@

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.

## MultiplicativeInverseRule
```python
MultiplicativeInverseRule(self, args, kwargs)
```
Multiplicative Inverse Property
`a / b = a * (1/b)`

The multiplicative inverse property involves converting 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.
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

`rule_tests:multiplicative_inverse`


## API


## MultiplicativeInverseRule
```python
MultiplicativeInverseRule(self, args, kwargs)
```
Convert division operations to multiplication by the reciprocal.
### get_type
```python
MultiplicativeInverseRule.get_type(
Expand All @@ -36,3 +41,4 @@ 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

0 comments on commit 3fa8012

Please sign in to comment.