Average Error: 2.2 → 0.4
Time: 10.7s
Precision: binary64
Cost: 19912
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;a \leq -2 \cdot 10^{+107}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{elif}\;a \leq 10^{-64}:\\ \;\;\;\;\left(a \cdot t + t_1\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \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
 (let* ((t_1 (+ x (* y z))))
   (if (<= a -2e+107)
     (+ (+ (* a (* z b)) (* a t)) t_1)
     (if (<= a 1e-64)
       (+ (+ (* a t) t_1) (* b (* a z)))
       (fma y z (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 t_1 = x + (y * z);
	double tmp;
	if (a <= -2e+107) {
		tmp = ((a * (z * b)) + (a * t)) + t_1;
	} else if (a <= 1e-64) {
		tmp = ((a * t) + t_1) + (b * (a * z));
	} else {
		tmp = fma(y, z, 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)
	t_1 = Float64(x + Float64(y * z))
	tmp = 0.0
	if (a <= -2e+107)
		tmp = Float64(Float64(Float64(a * Float64(z * b)) + Float64(a * t)) + t_1);
	elseif (a <= 1e-64)
		tmp = Float64(Float64(Float64(a * t) + t_1) + Float64(b * Float64(a * z)));
	else
		tmp = fma(y, z, 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_] := Block[{t$95$1 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -2e+107], N[(N[(N[(a * N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(a * t), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[a, 1e-64], N[(N[(N[(a * t), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(b * N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * z + 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}
t_1 := x + y \cdot z\\
\mathbf{if}\;a \leq -2 \cdot 10^{+107}:\\
\;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\

\mathbf{elif}\;a \leq 10^{-64}:\\
\;\;\;\;\left(a \cdot t + t_1\right) + b \cdot \left(a \cdot z\right)\\

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


\end{array}

Error

Target

Original2.2
Target0.3
Herbie0.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 3 regimes
  2. if a < -1.9999999999999999e107

    1. Initial program 7.2

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified0.1

      \[\leadsto \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + a \cdot \left(z \cdot b\right)\right)} \]
      Proof
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (*.f64 a (*.f64 z b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 x (*.f64 y z)) (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b)))): 13 points increase in error, 16 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error

    if -1.9999999999999999e107 < a < 9.99999999999999965e-65

    1. Initial program 0.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]

    if 9.99999999999999965e-65 < a

    1. Initial program 4.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)} \]
      Proof
      (fma.f64 y z (fma.f64 a (fma.f64 z b t) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z b) t)) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (fma.f64 a (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (+.f64 t (*.f64 z b))) x))): 1 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 a t) (*.f64 a (*.f64 z b)))) x)): 0 points increase in error, 1 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 t a)) (*.f64 a (*.f64 z b))) x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 y z (+.f64 (+.f64 (*.f64 t a) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a z) b))) x)): 13 points increase in error, 16 points decrease in error
      (fma.f64 y z (Rewrite<= +-commutative_binary64 (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) (+.f64 x (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))))): 4 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y z) x) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y z))) (+.f64 (*.f64 t a) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error22.3
Cost2296
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := a \cdot \left(t + z \cdot b\right)\\ t_4 := x + y \cdot z\\ \mathbf{if}\;a \leq -2.35 \cdot 10^{+198}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -8.5 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.7 \cdot 10^{+68}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.25 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -4.8 \cdot 10^{-100}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -5.5 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{-166}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1 \cdot 10^{-198}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -7.7 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -8.5 \cdot 10^{-263}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 3.5 \cdot 10^{-12}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq 2900:\\ \;\;\;\;a \cdot t + y \cdot z\\ \mathbf{elif}\;a \leq 6.2 \cdot 10^{+32}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq 3.3 \cdot 10^{+152}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error21.7
Cost1772
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := a \cdot \left(t + z \cdot b\right)\\ t_4 := x + y \cdot z\\ \mathbf{if}\;a \leq -6.4 \cdot 10^{+199}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -8.3 \cdot 10^{+102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.5 \cdot 10^{+72}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -3.45 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3 \cdot 10^{-100}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -4.8 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{-166}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1 \cdot 10^{-198}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -7.7 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -8.5 \cdot 10^{-263}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 7.5 \cdot 10^{-7}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error34.4
Cost1380
\[\begin{array}{l} \mathbf{if}\;x \leq -150000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{-47}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.52 \cdot 10^{-87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-214}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-246}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-282}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-248}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-141}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 2.55 \cdot 10^{-42}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error0.5
Cost1224
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := \left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{if}\;a \leq -4.5 \cdot 10^{+106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2 \cdot 10^{+113}:\\ \;\;\;\;\left(a \cdot t + t_1\right) + b \cdot \left(a \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error33.9
Cost1116
\[\begin{array}{l} \mathbf{if}\;x \leq -510000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{-48}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-214}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-245}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-279}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 7.1 \cdot 10^{-43}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error17.1
Cost1108
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;z \leq -6.4 \cdot 10^{+133}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.95 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.3 \cdot 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+180}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error19.5
Cost976
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-40}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.8
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + y \cdot z\right) \]
Alternative 9
Error25.7
Cost848
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;z \leq -3 \cdot 10^{+135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{+55}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+180}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 10
Error19.9
Cost848
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -2.55 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-40}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+180}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error8.2
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -1.1 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.46 \cdot 10^{+69}:\\ \;\;\;\;\left(x + a \cdot t\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error33.5
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -98000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-45}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{-42}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error33.4
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -3900000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-53}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-277}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-43}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error39.6
Cost64
\[x \]

Error

Reproduce

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