Average Error: 1.9 → 0.9
Time: 18.9s
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 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{if}\;b \leq -5 \cdot 10^{+194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 10^{+105}:\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(z, y, 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 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b))))
   (if (<= b -5e+194)
     t_1
     (if (<= b 1e+105) (fma a (+ t (* z b)) (fma z y 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 = ((x + (y * z)) + (t * a)) + ((a * z) * b);
	double tmp;
	if (b <= -5e+194) {
		tmp = t_1;
	} else if (b <= 1e+105) {
		tmp = fma(a, (t + (z * b)), fma(z, y, 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(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b))
	tmp = 0.0
	if (b <= -5e+194)
		tmp = t_1;
	elseif (b <= 1e+105)
		tmp = fma(a, Float64(t + Float64(z * b)), fma(z, y, 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[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5e+194], t$95$1, If[LessEqual[b, 1e+105], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(z * y + 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 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\
\mathbf{if}\;b \leq -5 \cdot 10^{+194}:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error

Target

Original1.9
Target0.3
Herbie0.9
\[\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 < -4.99999999999999989e194 or 9.9999999999999994e104 < b

    1. Initial program 1.0

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

    if -4.99999999999999989e194 < b < 9.9999999999999994e104

    1. Initial program 2.1

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

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

Alternatives

Alternative 1
Error25.0
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b + y\right)\\ t_2 := \left(t + b \cdot z\right) \cdot a\\ t_3 := y \cdot z + x\\ \mathbf{if}\;x \leq -1.7 \cdot 10^{+118}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -235000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-41}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-264}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-291}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+43}:\\ \;\;\;\;a \cdot t + x\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error34.3
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -14200000000:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-37}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-183}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-266}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-287}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-216}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-10}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error20.8
Cost1240
\[\begin{array}{l} t_1 := a \cdot t + x\\ t_2 := y \cdot z + x\\ t_3 := z \cdot \left(a \cdot b + y\right)\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+41}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{-101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+71}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{+221}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error20.8
Cost1240
\[\begin{array}{l} t_1 := a \cdot t + x\\ t_2 := y \cdot z + x\\ t_3 := \left(t + b \cdot z\right) \cdot a\\ \mathbf{if}\;a \leq -8000000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 8.2 \cdot 10^{-124}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.15 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.3 \cdot 10^{+163}:\\ \;\;\;\;x + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error20.7
Cost1240
\[\begin{array}{l} t_1 := a \cdot t + x\\ t_2 := y \cdot z + x\\ t_3 := \left(t + b \cdot z\right) \cdot a\\ \mathbf{if}\;a \leq -3550000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 7.4 \cdot 10^{-123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 8.8 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 7.6 \cdot 10^{+163}:\\ \;\;\;\;a \cdot \left(b \cdot z\right) + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error21.2
Cost1240
\[\begin{array}{l} t_1 := y \cdot z + x\\ t_2 := \left(t + b \cdot z\right) \cdot a\\ \mathbf{if}\;a \leq -6200000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 1.3 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.6 \cdot 10^{+33}:\\ \;\;\;\;y \cdot z + a \cdot t\\ \mathbf{elif}\;a \leq 4.9 \cdot 10^{+163}:\\ \;\;\;\;a \cdot \left(b \cdot z\right) + x\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + x\\ \end{array} \]
Alternative 7
Error0.5
Cost1224
\[\begin{array}{l} t_1 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{if}\;b \leq -2.3 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 5 \cdot 10^{+93}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error12.8
Cost1104
\[\begin{array}{l} t_1 := y \cdot z + x\\ t_2 := x + a \cdot \left(z \cdot b + t\right)\\ \mathbf{if}\;a \leq -0.00115:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1.65 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -8.2 \cdot 10^{-125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.2 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error10.0
Cost1104
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b + t\right)\\ t_2 := z \cdot \left(a \cdot b + y\right) + x\\ \mathbf{if}\;b \leq -2.5 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 8.5 \cdot 10^{+57}:\\ \;\;\;\;y \cdot z + \left(a \cdot t + x\right)\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{+201}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{+260}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error3.4
Cost1096
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b + y\right) + \left(a \cdot t + x\right)\\ \mathbf{if}\;z \leq 2 \cdot 10^{-221}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-99}:\\ \;\;\;\;x + a \cdot \left(z \cdot b + t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error26.5
Cost848
\[\begin{array}{l} t_1 := a \cdot t + x\\ \mathbf{if}\;x \leq -7500000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.42 \cdot 10^{-37}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-265}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error20.6
Cost848
\[\begin{array}{l} t_1 := a \cdot t + x\\ t_2 := y \cdot z + x\\ \mathbf{if}\;z \leq -7.6 \cdot 10^{+40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.9 \cdot 10^{-104}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 13
Error8.1
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b + t\right)\\ \mathbf{if}\;a \leq -2.35 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.02 \cdot 10^{+21}:\\ \;\;\;\;y \cdot z + \left(a \cdot t + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 14
Error34.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-10}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error40.1
Cost64
\[x \]

Error

Reproduce

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