Average Error: 2.3 → 1.4
Time: 5.9s
Precision: binary64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;a \leq 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(b, a, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
(FPCore (x y z t a b)
 :precision binary64
 (if (<= a 1e+32)
   (fma z (fma b a y) (fma t a x))
   (fma z y (fma a (fma z b t) x))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (a <= 1e+32) {
		tmp = fma(z, fma(b, a, y), fma(t, a, x));
	} else {
		tmp = fma(z, y, fma(a, fma(z, b, t), x));
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b))
end
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (a <= 1e+32)
		tmp = fma(z, fma(b, a, y), fma(t, a, x));
	else
		tmp = fma(z, y, fma(a, fma(z, b, t), x));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[a, 1e+32], N[(z * N[(b * a + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision], N[(z * y + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;a \leq 10^{+32}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(b, a, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\


\end{array}

Error

Target

Original2.3
Target0.3
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;z < -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z < 4.7589743188364287 \cdot 10^{-122}:\\ \;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if a < 1.00000000000000005e32

    1. Initial program 1.6

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Applied egg-rr1.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot z, b, \mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\right)} \]
    3. Taylor expanded in a around 0 3.2

      \[\leadsto \color{blue}{y \cdot z + \left(\left(t + b \cdot z\right) \cdot a + x\right)} \]
    4. Simplified1.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{fma}\left(b, a, y\right), \mathsf{fma}\left(t, a, x\right)\right)} \]

    if 1.00000000000000005e32 < a

    1. Initial program 6.2

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Applied egg-rr6.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot z, b, \mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)\right)} \]
    3. Taylor expanded in a around 0 0.1

      \[\leadsto \color{blue}{y \cdot z + \left(\left(t + b \cdot z\right) \cdot a + x\right)} \]
    4. Simplified6.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{fma}\left(b, a, y\right), \mathsf{fma}\left(t, a, x\right)\right)} \]
    5. Taylor expanded in z around 0 7.0

      \[\leadsto \color{blue}{z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)} \]
    6. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 10^{+32}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(b, a, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022206 
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
  :precision binary64

  :herbie-target
  (if (< z -11820553527347888000.0) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))