# Reaktor/Tutorials/Applied algebra for Reaktor users

## What you should know

Algebra is by far the most important form of mathematics needed when it comes to working with Reaktor. Ideally one should have an understanding of high school algebra, along with at least some peripheral knowledge of trigonometry. One generally does not encounter circumstances in Reaktor where things such as the quadratic equation are needed, but generally speaking you should be comfortable with solving single variable linear equations (i.e. solving for x if: ${\displaystyle 2x+10=4x}$ ) and double variable linear equations (i.e. solving for y if: ${\displaystyle 3y=2x+6y+20}$ ). Polynomials with terms to powers greater than one are not encountered too often (i.e. ${\displaystyle y=x^{2}+3x+4}$ ), but you may encounter them when doing such things as shaping linear controller data into a curve.

## Useful formulas

### Scaling data from one range to another

${\displaystyle f(x)={\frac {M'-m'}{M-m}}\cdot (x-m)+m'}$

• x = input
• f(x) = output
• m = min value of input
• M = max value of input
• m' = min value of output
• M' = max value of output

As an example, say you have an LFO which is outputting in a range from -1 to 1. However, you want the LFO to be outputting in a range from 30 to 50. We can use the above formula to construct a function which transforms our input from the old range to the new range: We simply plug in our values and then simplify.

• ${\displaystyle f(x)={\frac {(50)-(30)}{(1)-(-1)}}\cdot (x-(-1))+(30)}$
• ${\displaystyle f(x)={\frac {20}{1+1}}\cdot (x+1)+30}$
• ${\displaystyle f(x)=10\cdot (x+1)+30}$

NOTE: The dot ( ${\displaystyle \cdot }$  ) signifies multiplication. Subtracting a negative is the same as adding.

Taking into account order of operations (from highest priority to lowest: parenthesis, exponents, multiplication and division, addition and subtraction), we see that we can transform our input via three easy steps:

1. Add 1 to the input -- This shifts the range (-1..1) to (0..2).
2. Multiply the result of that by 10 -- This scales the range of (0..2) to (0..20).
3. Add 30 to the result of the multiplication -- This shifts the range of (0..20) to (30..50), our goal.

Here is one more example, where we transform our input with a range of -300 to 24 into data with a range of 100 to 10000.

• ${\displaystyle f(x)={\frac {(10000)-(100)}{(24)-(-300)}}\cdot (x-(-300))+(100)}$
• ${\displaystyle f(x)={\frac {9900}{324}}\cdot (x+300)+(100)}$

NOTE: We do not reduce the fraction because 9900 ÷ 324 produces a repeating decimal (30.55555...).

Hence we get the following steps:

1. Divide 9900 by 324 -- This gives us 30.555555...
2. Add 300 to the input -- This shifts the range (-300..24) to (0..324).
3. Multiply the result of step 1 by the result of step 2 -- This scales the range (0..324) to (0..9900).
4. Add 100 to the result of step 3 -- This shifts the range of (0..9900) to (100..10000), our goal.

As you can see, linearly scaling data is as simple as shift, scale, shift.

### MIDI Pitch => Frequency (Hz)

${\displaystyle f(x)=440\cdot 2^{\frac {x-69}{12}}\approx 440\cdot e^{0.057762265\cdot (x-69)}}$

• ${\displaystyle x}$  = pitch
• ${\displaystyle f(x)}$  = frequency
• ${\displaystyle e\approx 2.71828183}$

### Frequency (Hz) => MIDI Pitch

${\displaystyle f(x)=69+12\cdot {\frac {\log \left({\frac {x}{440}}\right)}{\log(2)}}\approx {\frac {\ln \left({\frac {x}{8.175798}}\right)}{\ln 1.0594633}}}$

• ${\displaystyle x}$  = frequency
• ${\displaystyle f(x)}$  = pitch
• ${\displaystyle \ln }$  = the natural log

### How many times MIDI pitch A is slower than MIDI pitch B (A < B)

${\displaystyle f(A,B)=2^{\frac {B-A}{12}}\approx e^{0.057762265\cdot (B-A)}}$

• A = MIDI pitch A
• B = MIDI pitch B
• f(x) = output
• ${\displaystyle e\approx 2.71828183}$