Bouland and Aaronson, Equation (25)

Percentage Accurate: 73.5% → 99.1%
Time: 12.7s
Alternatives: 15
Speedup: 5.9×

Specification

?
\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (-
  (+
   (pow (+ (* a a) (* b b)) 2.0)
   (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a))))))
  1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 15 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (-
  (+
   (pow (+ (* a a) (* b b)) 2.0)
   (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a))))))
  1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1
\end{array}

Alternative 1: 99.1% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{b \cdot \left(a \cdot b\right)}{a}, a \cdot a\right)}} + 4 \cdot \left(b \cdot b\right)\right) + -1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (+
  (+
   (/ (fma a a (* b b)) (/ 1.0 (fma 1.0 (/ (* b (* a b)) a) (* a a))))
   (* 4.0 (* b b)))
  -1.0))
double code(double a, double b) {
	return ((fma(a, a, (b * b)) / (1.0 / fma(1.0, ((b * (a * b)) / a), (a * a)))) + (4.0 * (b * b))) + -1.0;
}
function code(a, b)
	return Float64(Float64(Float64(fma(a, a, Float64(b * b)) / Float64(1.0 / fma(1.0, Float64(Float64(b * Float64(a * b)) / a), Float64(a * a)))) + Float64(4.0 * Float64(b * b))) + -1.0)
end
code[a_, b_] := N[(N[(N[(N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(1.0 * N[(N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{b \cdot \left(a \cdot b\right)}{a}, a \cdot a\right)}} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Derivation
  1. Initial program 74.5%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{2}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. unpow2N/A

      \[\leadsto \left(\color{blue}{\left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a + b \cdot b\right)} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    3. lift-+.f64N/A

      \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\left(a \cdot a + b \cdot b\right)} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    4. flip-+N/A

      \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\frac{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{a \cdot a - b \cdot b}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    5. clear-numN/A

      \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\frac{1}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    6. un-div-invN/A

      \[\leadsto \left(\color{blue}{\frac{a \cdot a + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    7. lower-/.f64N/A

      \[\leadsto \left(\color{blue}{\frac{a \cdot a + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    8. lift-+.f64N/A

      \[\leadsto \left(\frac{\color{blue}{a \cdot a + b \cdot b}}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    9. lift-*.f64N/A

      \[\leadsto \left(\frac{\color{blue}{a \cdot a} + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    10. lower-fma.f64N/A

      \[\leadsto \left(\frac{\color{blue}{\mathsf{fma}\left(a, a, b \cdot b\right)}}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    11. clear-numN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\color{blue}{\frac{1}{\frac{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{a \cdot a - b \cdot b}}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    12. flip-+N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    13. lift-+.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    14. lower-/.f6474.5

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\color{blue}{\frac{1}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    15. lift-+.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    16. lift-*.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a} + b \cdot b}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    17. lower-fma.f6474.5

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(a, a, b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  4. Applied rewrites74.5%

    \[\leadsto \left(\color{blue}{\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  5. Taylor expanded in a around 0

    \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{{b}^{2}}\right) - 1 \]
  6. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
    2. lower-*.f6499.3

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
  7. Applied rewrites99.3%

    \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
  8. Taylor expanded in a around inf

    \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{{a}^{2} \cdot \left(1 + \frac{{b}^{2}}{{a}^{2}}\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  9. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{{a}^{2} \cdot \color{blue}{\left(\frac{{b}^{2}}{{a}^{2}} + 1\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. distribute-lft-inN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{{a}^{2} \cdot \frac{{b}^{2}}{{a}^{2}} + {a}^{2} \cdot 1}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    3. associate-*r/N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{a}^{2}}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    4. unpow2N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2}}{{a}^{2}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    5. associate-*l*N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{a \cdot \left(a \cdot {b}^{2}\right)}}{{a}^{2}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    6. unpow2N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{a \cdot \left(a \cdot {b}^{2}\right)}{\color{blue}{a \cdot a}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    7. times-fracN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\frac{a}{a} \cdot \frac{a \cdot {b}^{2}}{a}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    8. *-rgt-identityN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{a \cdot 1}}{a} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    9. associate-*r/N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\left(a \cdot \frac{1}{a}\right)} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    10. rgt-mult-inverseN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{1} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    11. *-rgt-identityN/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{1 \cdot \frac{a \cdot {b}^{2}}{a} + \color{blue}{{a}^{2}}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    12. lower-fma.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(1, \frac{a \cdot {b}^{2}}{a}, {a}^{2}\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    13. lower-/.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \color{blue}{\frac{a \cdot {b}^{2}}{a}}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    14. lower-*.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{\color{blue}{a \cdot {b}^{2}}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    15. unpow2N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \color{blue}{\left(b \cdot b\right)}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    16. lower-*.f64N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \color{blue}{\left(b \cdot b\right)}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    17. unpow2N/A

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, \color{blue}{a \cdot a}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    18. lower-*.f6499.4

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, \color{blue}{a \cdot a}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  10. Applied rewrites99.4%

    \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, a \cdot a\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  11. Step-by-step derivation
    1. Applied rewrites99.4%

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{\left(a \cdot b\right) \cdot b}{a}, a \cdot a\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Final simplification99.4%

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{b \cdot \left(a \cdot b\right)}{a}, a \cdot a\right)}} + 4 \cdot \left(b \cdot b\right)\right) + -1 \]
    3. Add Preprocessing

    Alternative 2: 99.1% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ \left(4 \cdot \left(b \cdot b\right) + \frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, a \cdot a\right)}}\right) + -1 \end{array} \]
    (FPCore (a b)
     :precision binary64
     (+
      (+
       (* 4.0 (* b b))
       (/ (fma a a (* b b)) (/ 1.0 (fma 1.0 (/ (* a (* b b)) a) (* a a)))))
      -1.0))
    double code(double a, double b) {
    	return ((4.0 * (b * b)) + (fma(a, a, (b * b)) / (1.0 / fma(1.0, ((a * (b * b)) / a), (a * a))))) + -1.0;
    }
    
    function code(a, b)
    	return Float64(Float64(Float64(4.0 * Float64(b * b)) + Float64(fma(a, a, Float64(b * b)) / Float64(1.0 / fma(1.0, Float64(Float64(a * Float64(b * b)) / a), Float64(a * a))))) + -1.0)
    end
    
    code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(1.0 * N[(N[(a * N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \left(4 \cdot \left(b \cdot b\right) + \frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, a \cdot a\right)}}\right) + -1
    \end{array}
    
    Derivation
    1. Initial program 73.5%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{2}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      2. unpow2N/A

        \[\leadsto \left(\color{blue}{\left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a + b \cdot b\right)} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      3. lift-+.f64N/A

        \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\left(a \cdot a + b \cdot b\right)} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      4. flip-+N/A

        \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\frac{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{a \cdot a - b \cdot b}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      5. clear-numN/A

        \[\leadsto \left(\left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\frac{1}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      6. un-div-invN/A

        \[\leadsto \left(\color{blue}{\frac{a \cdot a + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      7. lower-/.f64N/A

        \[\leadsto \left(\color{blue}{\frac{a \cdot a + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      8. lift-+.f64N/A

        \[\leadsto \left(\frac{\color{blue}{a \cdot a + b \cdot b}}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      9. lift-*.f64N/A

        \[\leadsto \left(\frac{\color{blue}{a \cdot a} + b \cdot b}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      10. lower-fma.f64N/A

        \[\leadsto \left(\frac{\color{blue}{\mathsf{fma}\left(a, a, b \cdot b\right)}}{\frac{a \cdot a - b \cdot b}{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      11. clear-numN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\color{blue}{\frac{1}{\frac{\left(a \cdot a\right) \cdot \left(a \cdot a\right) - \left(b \cdot b\right) \cdot \left(b \cdot b\right)}{a \cdot a - b \cdot b}}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      12. flip-+N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      13. lift-+.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      14. lower-/.f6473.5

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\color{blue}{\frac{1}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      15. lift-+.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a + b \cdot b}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      16. lift-*.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{a \cdot a} + b \cdot b}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
      17. lower-fma.f6473.5

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(a, a, b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    4. Applied rewrites73.5%

      \[\leadsto \left(\color{blue}{\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}}} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    5. Taylor expanded in a around 0

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{{b}^{2}}\right) - 1 \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
      2. lower-*.f6499.1

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
    7. Applied rewrites99.1%

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(a, a, b \cdot b\right)}} + 4 \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
    8. Taylor expanded in a around inf

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{{a}^{2} \cdot \left(1 + \frac{{b}^{2}}{{a}^{2}}\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{{a}^{2} \cdot \color{blue}{\left(\frac{{b}^{2}}{{a}^{2}} + 1\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      2. distribute-lft-inN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{{a}^{2} \cdot \frac{{b}^{2}}{{a}^{2}} + {a}^{2} \cdot 1}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      3. associate-*r/N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{a}^{2}}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      4. unpow2N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2}}{{a}^{2}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      5. associate-*l*N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{a \cdot \left(a \cdot {b}^{2}\right)}}{{a}^{2}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      6. unpow2N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{a \cdot \left(a \cdot {b}^{2}\right)}{\color{blue}{a \cdot a}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      7. times-fracN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\frac{a}{a} \cdot \frac{a \cdot {b}^{2}}{a}} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      8. *-rgt-identityN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\frac{\color{blue}{a \cdot 1}}{a} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      9. associate-*r/N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\left(a \cdot \frac{1}{a}\right)} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      10. rgt-mult-inverseN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{1} \cdot \frac{a \cdot {b}^{2}}{a} + {a}^{2} \cdot 1}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      11. *-rgt-identityN/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{1 \cdot \frac{a \cdot {b}^{2}}{a} + \color{blue}{{a}^{2}}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      12. lower-fma.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(1, \frac{a \cdot {b}^{2}}{a}, {a}^{2}\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      13. lower-/.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \color{blue}{\frac{a \cdot {b}^{2}}{a}}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      14. lower-*.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{\color{blue}{a \cdot {b}^{2}}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      15. unpow2N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \color{blue}{\left(b \cdot b\right)}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      16. lower-*.f64N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \color{blue}{\left(b \cdot b\right)}}{a}, {a}^{2}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      17. unpow2N/A

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, \color{blue}{a \cdot a}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
      18. lower-*.f6499.1

        \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, \color{blue}{a \cdot a}\right)}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    10. Applied rewrites99.1%

      \[\leadsto \left(\frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\color{blue}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, a \cdot a\right)}}} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    11. Final simplification99.1%

      \[\leadsto \left(4 \cdot \left(b \cdot b\right) + \frac{\mathsf{fma}\left(a, a, b \cdot b\right)}{\frac{1}{\mathsf{fma}\left(1, \frac{a \cdot \left(b \cdot b\right)}{a}, a \cdot a\right)}}\right) + -1 \]
    12. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024226 
    (FPCore (a b)
      :name "Bouland and Aaronson, Equation (25)"
      :precision binary64
      (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a)))))) 1.0))