Average Error: 2.0 → 0.5
Time: 10.4s
Precision: binary64
Cost: 13640
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\right)\\ \mathbf{if}\;b \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (+ (* b (* z a)) (+ (* t a) (+ x (* y z))))))
   (if (<= b -9.5e+124)
     t_1
     (if (<= b 5e-9) (fma a (+ t (* b z)) (fma y z x)) t_1))))
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 = (b * (z * a)) + ((t * a) + (x + (y * z)));
	double tmp;
	if (b <= -9.5e+124) {
		tmp = t_1;
	} else if (b <= 5e-9) {
		tmp = fma(a, (t + (b * z)), fma(y, z, x));
	} else {
		tmp = t_1;
	}
	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(Float64(b * Float64(z * a)) + Float64(Float64(t * a) + Float64(x + Float64(y * z))))
	tmp = 0.0
	if (b <= -9.5e+124)
		tmp = t_1;
	elseif (b <= 5e-9)
		tmp = fma(a, Float64(t + Float64(b * z)), fma(y, z, x));
	else
		tmp = t_1;
	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[(N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision] + N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -9.5e+124], t$95$1, If[LessEqual[b, 5e-9], N[(a * N[(t + N[(b * z), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
t_1 := b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\right)\\
\mathbf{if}\;b \leq -9.5 \cdot 10^{+124}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original2.0
Target0.3
Herbie0.5
\[\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 b < -9.50000000000000004e124 or 5.0000000000000001e-9 < b

    1. Initial program 0.7

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

    if -9.50000000000000004e124 < b < 5.0000000000000001e-9

    1. Initial program 2.7

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

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

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

Alternatives

Alternative 1
Error9.8
Cost1756
\[\begin{array}{l} t_1 := b \cdot \left(z \cdot a\right) + \left(t \cdot a + y \cdot z\right)\\ t_2 := t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{if}\;t \leq -3.8 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -3.6 \cdot 10^{-47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.5 \cdot 10^{-160}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 9 \cdot 10^{-100}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;t \leq 7.1 \cdot 10^{-84}:\\ \;\;\;\;t \cdot a + \left(x + a \cdot \left(b \cdot z\right)\right)\\ \mathbf{elif}\;t \leq 8.6 \cdot 10^{-16}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error15.1
Cost1368
\[\begin{array}{l} t_1 := x + a \cdot \left(t + b \cdot z\right)\\ t_2 := z \cdot \left(y + b \cdot a\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+124}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-20}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.42 \cdot 10^{+163}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 10^{+215}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error22.5
Cost1244
\[\begin{array}{l} t_1 := a \cdot \left(t + b \cdot z\right)\\ t_2 := x + y \cdot z\\ t_3 := x + t \cdot a\\ \mathbf{if}\;t \leq -4.1 \cdot 10^{+77}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -7 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{-99}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.1 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.85 \cdot 10^{+153}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.02 \cdot 10^{+198}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error0.5
Cost1224
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := b \cdot \left(z \cdot a\right) + \left(t \cdot a + t_1\right)\\ \mathbf{if}\;b \leq -1.15 \cdot 10^{+125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error26.7
Cost1112
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;x \leq -3.5 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-279}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 6.1 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-180}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+19}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error23.4
Cost1112
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;t \leq -3.2 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -8 \cdot 10^{-53}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;t \leq -6.8 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{-100}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;t \leq 1.85 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.02 \cdot 10^{+198}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error2.3
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+183}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \end{array} \]
Alternative 8
Error19.6
Cost976
\[\begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{+26}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-88}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-116}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+19}:\\ \;\;\;\;t \cdot a + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 9
Error7.8
Cost968
\[\begin{array}{l} t_1 := t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{if}\;y \leq -1.9 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-62}:\\ \;\;\;\;t \cdot a + \left(x + a \cdot \left(b \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error9.2
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{if}\;a \leq -6 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 7.4 \cdot 10^{-90}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error7.7
Cost840
\[\begin{array}{l} t_1 := t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{if}\;y \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-61}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error33.4
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{+47}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-64}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{+19}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error20.5
Cost584
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -2.3 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6 \cdot 10^{-171}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error33.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+47}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-24}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error39.8
Cost64
\[x \]

Error

Reproduce

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