Bouland and Aaronson, Equation (25)

?

Percentage Accurate: 73.9% → 98.4%
Time: 10.5s
Precision: binary64
Cost: 47748

?

\[\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 \]
\[\begin{array}{l} \mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(4, \mathsf{fma}\left(a, \mathsf{fma}\left(a, a, a\right), b \cdot \left(b \cdot \mathsf{fma}\left(a, -3, 1\right)\right)\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{3} \cdot \left(a + 4\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))
(FPCore (a b)
 :precision binary64
 (if (<=
      (+
       (pow (+ (* a a) (* b b)) 2.0)
       (* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0))))))
      INFINITY)
   (+
    (fma
     4.0
     (fma a (fma a a a) (* b (* b (fma a -3.0 1.0))))
     (pow (hypot a b) 4.0))
    -1.0)
   (+ (* (pow a 3.0) (+ a 4.0)) -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;
}
double code(double a, double b) {
	double tmp;
	if ((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))))) <= ((double) INFINITY)) {
		tmp = fma(4.0, fma(a, fma(a, a, a), (b * (b * fma(a, -3.0, 1.0)))), pow(hypot(a, b), 4.0)) + -1.0;
	} else {
		tmp = (pow(a, 3.0) * (a + 4.0)) + -1.0;
	}
	return tmp;
}
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 code(a, b)
	tmp = 0.0
	if (Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(a + 1.0)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0)))))) <= Inf)
		tmp = Float64(fma(4.0, fma(a, fma(a, a, a), Float64(b * Float64(b * fma(a, -3.0, 1.0)))), (hypot(a, b) ^ 4.0)) + -1.0);
	else
		tmp = Float64(Float64((a ^ 3.0) * Float64(a + 4.0)) + -1.0);
	end
	return tmp
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]
code[a_, b_] := If[LessEqual[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[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(4.0 * N[(a * N[(a * a + a), $MachinePrecision] + N[(b * N[(b * N[(a * -3.0 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\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
\begin{array}{l}
\mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(4, \mathsf{fma}\left(a, \mathsf{fma}\left(a, a, a\right), b \cdot \left(b \cdot \mathsf{fma}\left(a, -3, 1\right)\right)\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1\\

\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + 4\right) + -1\\


\end{array}

Local Percentage Accuracy?

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.

Derivation?

  1. Split input into 2 regimes
  2. if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a)))))) < +inf.0

    1. Initial program 99.8%

      \[\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. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4, \mathsf{fma}\left(a, \mathsf{fma}\left(a, a, a\right), b \cdot \left(b \cdot \mathsf{fma}\left(a, -3, 1\right)\right)\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1} \]
      Step-by-step derivation

      [Start]99.8

      \[ \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 \]

      sub-neg [=>]99.8

      \[ \color{blue}{\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) + \left(-1\right)} \]

    if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a))))))

    1. Initial program 0.0%

      \[\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. Simplified6.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(4, \mathsf{fma}\left(a, \mathsf{fma}\left(a, a, a\right), b \cdot \left(b \cdot \mathsf{fma}\left(a, -3, 1\right)\right)\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1} \]
      Step-by-step derivation

      [Start]0.0

      \[ \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 \]

      sub-neg [=>]0.0

      \[ \color{blue}{\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) + \left(-1\right)} \]
    3. Taylor expanded in a around inf 21.5%

      \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
    4. Simplified90.8%

      \[\leadsto \color{blue}{{a}^{3} \cdot \left(4 + a\right)} + -1 \]
      Step-by-step derivation

      [Start]21.5

      \[ \left(4 \cdot {a}^{3} + {a}^{4}\right) + -1 \]

      metadata-eval [<=]21.5

      \[ \left(4 \cdot {a}^{3} + {a}^{\color{blue}{\left(2 \cdot 2\right)}}\right) + -1 \]

      pow-sqr [<=]21.5

      \[ \left(4 \cdot {a}^{3} + \color{blue}{{a}^{2} \cdot {a}^{2}}\right) + -1 \]

      unpow2 [=>]21.5

      \[ \left(4 \cdot {a}^{3} + \color{blue}{\left(a \cdot a\right)} \cdot {a}^{2}\right) + -1 \]

      associate-*l* [=>]21.5

      \[ \left(4 \cdot {a}^{3} + \color{blue}{a \cdot \left(a \cdot {a}^{2}\right)}\right) + -1 \]

      unpow2 [=>]21.5

      \[ \left(4 \cdot {a}^{3} + a \cdot \left(a \cdot \color{blue}{\left(a \cdot a\right)}\right)\right) + -1 \]

      cube-mult [<=]21.5

      \[ \left(4 \cdot {a}^{3} + a \cdot \color{blue}{{a}^{3}}\right) + -1 \]

      distribute-rgt-out [=>]90.8

      \[ \color{blue}{{a}^{3} \cdot \left(4 + a\right)} + -1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(4, \mathsf{fma}\left(a, \mathsf{fma}\left(a, a, a\right), b \cdot \left(b \cdot \mathsf{fma}\left(a, -3, 1\right)\right)\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{3} \cdot \left(a + 4\right) + -1\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.3%
Cost16580
\[\begin{array}{l} t_0 := {\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right)\\ \mathbf{if}\;t_0 \leq \infty:\\ \;\;\;\;t_0 + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{3} \cdot \left(a + 4\right) + -1\\ \end{array} \]
Alternative 2
Accuracy96.6%
Cost8456
\[\begin{array}{l} \mathbf{if}\;a \leq -2 \cdot 10^{+103}:\\ \;\;\;\;{a}^{4}\\ \mathbf{elif}\;a \leq -5 \cdot 10^{-8}:\\ \;\;\;\;\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + b \cdot \left(b \cdot \left(a \cdot -3\right)\right)\right)\right) + -1\\ \mathbf{elif}\;a \leq 4.3 \cdot 10^{+48}:\\ \;\;\;\;b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \]
Alternative 3
Accuracy93.8%
Cost7241
\[\begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{+20} \lor \neg \left(a \leq 4.1 \cdot 10^{+48}\right):\\ \;\;\;\;{a}^{4}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right) + -1\\ \end{array} \]
Alternative 4
Accuracy93.8%
Cost6793
\[\begin{array}{l} \mathbf{if}\;a \leq -5.6 \cdot 10^{+20} \lor \neg \left(a \leq 4.1 \cdot 10^{+48}\right):\\ \;\;\;\;{a}^{4}\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b + 4\right) + -1\\ \end{array} \]
Alternative 5
Accuracy84.3%
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -4.3 \cdot 10^{+151} \lor \neg \left(a \leq 3.1 \cdot 10^{+137}\right):\\ \;\;\;\;a \cdot \left(a \cdot 4\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b + 4\right) + -1\\ \end{array} \]
Alternative 6
Accuracy69.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;b \leq -9 \cdot 10^{+110} \lor \neg \left(b \leq 6.6 \cdot 10^{+153}\right):\\ \;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(a \cdot 4\right) + -1\\ \end{array} \]
Alternative 7
Accuracy51.5%
Cost448
\[\left(b \cdot b\right) \cdot 4 + -1 \]

Error

Reproduce?

herbie shell --seed 2023160 
(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))