?

Average Error: 2.1 → 0.3
Time: 1.3min
Precision: binary64
Cost: 7368

?

\[\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 -1 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-58}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right) + a \cdot \left(t + z \cdot b\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 -1e+26)
     t_1
     (if (<= b 5e-58) (+ (fma z y x) (* a (+ t (* z b)))) 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 <= -1e+26) {
		tmp = t_1;
	} else if (b <= 5e-58) {
		tmp = fma(z, y, x) + (a * (t + (z * b)));
	} 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 <= -1e+26)
		tmp = t_1;
	elseif (b <= 5e-58)
		tmp = Float64(fma(z, y, x) + Float64(a * Float64(t + Float64(z * b))));
	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, -1e+26], t$95$1, If[LessEqual[b, 5e-58], N[(N[(z * y + x), $MachinePrecision] + N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision]), $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 -1 \cdot 10^{+26}:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error?

Target

Original2.1
Target0.3
Herbie0.3
\[\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 < -1.00000000000000005e26 or 4.99999999999999977e-58 < b

    1. Initial program 0.6

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

    if -1.00000000000000005e26 < b < 4.99999999999999977e-58

    1. Initial program 3.4

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

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

Alternatives

Alternative 1
Error28.5
Cost1376
\[\begin{array}{l} t_1 := a \cdot t + x\\ \mathbf{if}\;t \leq -8.4 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.8 \cdot 10^{-246}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;t \leq 1.1 \cdot 10^{-237}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{-191}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;t \leq 2.2 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-87}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{-76}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-23}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.5
Cost1376
\[\begin{array}{l} t_1 := y \cdot z + a \cdot t\\ t_2 := z \cdot \left(a \cdot b + y\right)\\ t_3 := y \cdot z + x\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{-20}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{-293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 410:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{+20}:\\ \;\;\;\;\left(t + b \cdot z\right) \cdot a\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{+48}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + x\\ \end{array} \]
Alternative 3
Error22.8
Cost1244
\[\begin{array}{l} t_1 := \left(t + b \cdot z\right) \cdot a\\ t_2 := y \cdot z + x\\ t_3 := z \cdot \left(a \cdot b + y\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{-35}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-223}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-251}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.16 \cdot 10^{-71}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+49}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;a \cdot t + x\\ \end{array} \]
Alternative 4
Error0.3
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 -4 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 4 \cdot 10^{-57}:\\ \;\;\;\;\left(z \cdot \left(a \cdot b + y\right) + x\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error8.9
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-46}:\\ \;\;\;\;y \cdot z + \left(a \cdot t + x\right)\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+23}:\\ \;\;\;\;\left(y \cdot z + a \cdot t\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(z \cdot b + t\right)\\ \end{array} \]
Alternative 6
Error2.7
Cost964
\[\begin{array}{l} \mathbf{if}\;a \leq 1.56 \cdot 10^{+25}:\\ \;\;\;\;\left(z \cdot \left(a \cdot b + y\right) + x\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(z \cdot b + t\right)\\ \end{array} \]
Alternative 7
Error34.7
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-223}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-293}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-143}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+20}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error20.4
Cost848
\[\begin{array}{l} t_1 := y \cdot z + x\\ t_2 := a \cdot t + x\\ \mathbf{if}\;t \leq -5.7 \cdot 10^{+62}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -4.2:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.35 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.1 \cdot 10^{-89}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error22.5
Cost844
\[\begin{array}{l} t_1 := a \cdot t + x\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{-38}:\\ \;\;\;\;y \cdot z + x\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-28}:\\ \;\;\;\;z \cdot \left(a \cdot b + y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error11.9
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b + t\right)\\ \mathbf{if}\;a \leq -1.4 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6.5 \cdot 10^{-113}:\\ \;\;\;\;y \cdot z + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error8.0
Cost840
\[\begin{array}{l} t_1 := x + a \cdot \left(z \cdot b + t\right)\\ \mathbf{if}\;a \leq -2.3 \cdot 10^{+74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.2 \cdot 10^{-6}:\\ \;\;\;\;y \cdot z + \left(a \cdot t + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error8.0
Cost840
\[\begin{array}{l} \mathbf{if}\;a \leq -1.8 \cdot 10^{+73}:\\ \;\;\;\;a \cdot t + \left(a \cdot \left(z \cdot b\right) + x\right)\\ \mathbf{elif}\;a \leq 2.5 \cdot 10^{-5}:\\ \;\;\;\;y \cdot z + \left(a \cdot t + x\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(z \cdot b + t\right)\\ \end{array} \]
Alternative 13
Error33.9
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-143}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{+20}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error32.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+20}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error40.1
Cost64
\[x \]

Error

Reproduce?

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