# Distributive Factor Out

The `Distributive Property` of numbers says that we can factor out common values from terms that are connected with an addition operator.

This rule is expressed by the equation `ab + ac = a(b + c)`

Note

This is a core transformation used in combining like terms, though we normally skip over it mentally because humans are quite smart.

Consider that the `9y + 9y` example from above becomes `(9 + 9) * y`. If you then apply a constant simplification rule, you end up with `18y`, which is the result of combining the two like `y` terms.

### Transformations¶

Given a common parent node, this rule extracts the common value from both sides, leaving an addition and a multiplication.

`ab + ac = a(b + c)`

``````          +               *
/ \             / \
/   \           /   \
/     \    ->   /     \
*       *       a       +
/ \     / \             / \
a   b   a   c           b   c
``````

### 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
g + -x^3 + 4x^3 + 19p^4 + -1y g + (-1 + 4) * x^3 + 19p^4 + -1y
5.8c + (3393c + 6o + -8614k) (5.8 + 3393) * c + (6o + -8614k)
8c + (4v + 9n) + 7n + 4r 8c + 4v + (9 + 7) * n + 4r
11 + 11d + (1d + d^2) 11 + (11 + 1) * d + d^2
5a + o + (o + y) + 4s 5a + (1 + 1) * o + y + 4s
15 + 20j + 9j 15 + (20 + 9) * j
23f + (5f + 5d) (23 + 5) * f + 5d
9y + 9y (9 + 9) * y
14x + 7x (14 + 7) * x
6 + 4 (3 + 2) * 2
7 + 7 (1 + 1) * 7
4 + (z + 4) --- ---
6 + 4 --- ---
(z * 4 + z * 84x) + 1 --- ---

Last update: November 28, 2019