?

Average Error: 2.4 → 0.8
Time: 12.9s
Precision: binary64
Cost: 9160

?

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

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+291}:\\
\;\;\;\;t_2\\

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


\end{array}

Error?

Target

Original2.4
Target0.3
Herbie0.8
\[\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 (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < -1.00000000000000006e290

    1. Initial program 22.5

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

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

      [Start]22.5

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

      associate-+l+ [=>]22.5

      \[ \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)} \]

      associate-*l* [=>]5.5

      \[ \left(x + y \cdot z\right) + \left(t \cdot a + \color{blue}{a \cdot \left(z \cdot b\right)}\right) \]

    if -1.00000000000000006e290 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 1.9999999999999999e291

    1. Initial program 0.4

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

    if 1.9999999999999999e291 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))

    1. Initial program 20.9

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

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

      [Start]20.9

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

      +-commutative [=>]20.9

      \[ \color{blue}{\left(a \cdot z\right) \cdot b + \left(\left(x + y \cdot z\right) + t \cdot a\right)} \]

      +-commutative [=>]20.9

      \[ \left(a \cdot z\right) \cdot b + \left(\color{blue}{\left(y \cdot z + x\right)} + t \cdot a\right) \]

      associate-+l+ [=>]20.9

      \[ \left(a \cdot z\right) \cdot b + \color{blue}{\left(y \cdot z + \left(x + t \cdot a\right)\right)} \]

      associate-+r+ [=>]20.9

      \[ \color{blue}{\left(\left(a \cdot z\right) \cdot b + y \cdot z\right) + \left(x + t \cdot a\right)} \]

      *-commutative [=>]20.9

      \[ \left(\color{blue}{\left(z \cdot a\right)} \cdot b + y \cdot z\right) + \left(x + t \cdot a\right) \]

      associate-*l* [=>]5.0

      \[ \left(\color{blue}{z \cdot \left(a \cdot b\right)} + y \cdot z\right) + \left(x + t \cdot a\right) \]

      *-commutative [=>]5.0

      \[ \left(z \cdot \left(a \cdot b\right) + \color{blue}{z \cdot y}\right) + \left(x + t \cdot a\right) \]

      distribute-lft-out [=>]5.0

      \[ \color{blue}{z \cdot \left(a \cdot b + y\right)} + \left(x + t \cdot a\right) \]

      fma-def [=>]5.0

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

      fma-def [=>]5.0

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

      +-commutative [=>]5.0

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

      fma-def [=>]5.0

      \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{\mathsf{fma}\left(t, a, x\right)}\right) \]
    3. Applied egg-rr5.0

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

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

Alternatives

Alternative 1
Error1.0
Cost3017
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := \left(t \cdot a + t_1\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+290} \lor \neg \left(t_2 \leq 5 \cdot 10^{+249}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error19.9
Cost1897
\[\begin{array}{l} t_1 := x + a \cdot \left(t + z \cdot b\right)\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := x + y \cdot z\\ \mathbf{if}\;t \leq -2.2 \cdot 10^{+195}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;t \leq -1.1 \cdot 10^{+179}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.35 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.3 \cdot 10^{-218}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6 \cdot 10^{-284}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 3.2 \cdot 10^{-218}:\\ \;\;\;\;x + \left(z \cdot a\right) \cdot b\\ \mathbf{elif}\;t \leq 9.6 \cdot 10^{-198} \lor \neg \left(t \leq 1.6 \cdot 10^{-121}\right) \land t \leq 1.12 \cdot 10^{-48}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error22.7
Cost1640
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + t \cdot a\\ t_3 := x + y \cdot z\\ \mathbf{if}\;t \leq -6.6 \cdot 10^{+196}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.1 \cdot 10^{+179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.65 \cdot 10^{+37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.3 \cdot 10^{-218}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{-274}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 3.3 \cdot 10^{-218}:\\ \;\;\;\;x + \left(z \cdot a\right) \cdot b\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{-162}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{-123}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;t \leq 5.2 \cdot 10^{-48}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error22.5
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + t \cdot a\\ t_3 := x + y \cdot z\\ \mathbf{if}\;t \leq -2.2 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.6 \cdot 10^{+178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.8 \cdot 10^{+42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.3 \cdot 10^{-218}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{-162}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 4.4 \cdot 10^{-122}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-48}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error27.3
Cost1112
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;x \leq -5.1 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-199}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-304}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-180}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-52}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error21.4
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + t \cdot a\\ t_3 := x + y \cdot z\\ \mathbf{if}\;t \leq -2.2 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.1 \cdot 10^{+179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.1 \cdot 10^{+32}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.3 \cdot 10^{-218}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.65 \cdot 10^{-47}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error9.0
Cost972
\[\begin{array}{l} t_1 := x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -5.6 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-51}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+36}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.6
Cost960
\[\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + \left(x + y \cdot z\right) \]
Alternative 9
Error19.8
Cost849
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.7 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-35}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{+232} \lor \neg \left(z \leq 4.1 \cdot 10^{+270}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 10
Error7.7
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-48} \lor \neg \left(y \leq 4 \cdot 10^{-189}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 11
Error33.0
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{-31}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-302}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-180}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-7}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error33.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.05 \cdot 10^{-33}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-23}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error40.1
Cost64
\[x \]

Error

Reproduce?

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