?

Average Error: 2.0 → 0.8
Time: 13.2s
Precision: binary64
Cost: 13641

?

\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-111} \lor \neg \left(b \leq 2 \cdot 10^{-164}\right):\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, 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
 (if (or (<= b -5e-111) (not (<= b 2e-164)))
   (+ (+ (* t a) (+ x (* y z))) (* (* z a) b))
   (fma a (+ t (* z b)) (fma y z 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 tmp;
	if ((b <= -5e-111) || !(b <= 2e-164)) {
		tmp = ((t * a) + (x + (y * z))) + ((z * a) * b);
	} else {
		tmp = fma(a, (t + (z * b)), fma(y, z, 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)
	tmp = 0.0
	if ((b <= -5e-111) || !(b <= 2e-164))
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(Float64(z * a) * b));
	else
		tmp = fma(a, Float64(t + Float64(z * b)), fma(y, z, 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_] := If[Or[LessEqual[b, -5e-111], N[Not[LessEqual[b, 2e-164]], $MachinePrecision]], N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(z * a), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $MachinePrecision]), $MachinePrecision]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-111} \lor \neg \left(b \leq 2 \cdot 10^{-164}\right):\\
\;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + \left(z \cdot a\right) \cdot b\\

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


\end{array}

Error?

Target

Original2.0
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 2 regimes
  2. if b < -5.0000000000000003e-111 or 1.99999999999999992e-164 < b

    1. Initial program 1.2

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

    if -5.0000000000000003e-111 < b < 1.99999999999999992e-164

    1. Initial program 3.8

      \[\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(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)} \]
      Proof

      [Start]3.8

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

      associate-+l+ [=>]3.8

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

      +-commutative [=>]3.8

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

      *-commutative [=>]3.8

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

      associate-*l* [=>]0.0

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

      distribute-lft-out [=>]0.0

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

      fma-def [=>]0.0

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

      +-commutative [=>]0.0

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

      fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error0.4
Cost21704
\[\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 -\infty:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + t_1\\ \mathbf{elif}\;t_2 \leq 10^{+284}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \end{array} \]
Alternative 2
Error22.2
Cost1772
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + z \cdot \left(a \cdot b\right)\\ t_3 := x + y \cdot z\\ t_4 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+146}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-6}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-24}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -2.65 \cdot 10^{-61}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.5 \cdot 10^{-224}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{-298}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-296}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-238}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-157}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error20.8
Cost1241
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;a \leq -8 \cdot 10^{+143}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.75 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.9 \cdot 10^{-156}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;a \leq 2.25 \cdot 10^{-77} \lor \neg \left(a \leq 1.46 \cdot 10^{-15}\right) \land a \leq 70000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error0.6
Cost1225
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;b \leq -2 \cdot 10^{+31} \lor \neg \left(b \leq 10^{-161}\right):\\ \;\;\;\;\left(t \cdot a + t_1\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + t_1\\ \end{array} \]
Alternative 5
Error22.0
Cost1113
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := z \cdot \left(a \cdot b\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+141}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{+61}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.9 \cdot 10^{+54} \lor \neg \left(z \leq -2.1 \cdot 10^{-96}\right) \land z \leq 5.1 \cdot 10^{-92}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.2
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \leq -2.35 \cdot 10^{+132}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \end{array} \]
Alternative 7
Error33.4
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.55 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-14}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-214}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{-265}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-224}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-22}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error33.4
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-19}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-214}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -9.1 \cdot 10^{-265}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-224}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-21}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error9.1
Cost968
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;x \leq -14500000000:\\ \;\;\;\;x + t_1\\ \mathbf{elif}\;x \leq 1.32 \cdot 10^{-48}:\\ \;\;\;\;t_1 + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \end{array} \]
Alternative 10
Error32.7
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -35000000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-214}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -9.1 \cdot 10^{-265}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 10^{-224}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-19}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error19.0
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+65}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-11}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-27}:\\ \;\;\;\;t \cdot a + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 12
Error11.7
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -1.9 \cdot 10^{-156} \lor \neg \left(a \leq 1.06 \cdot 10^{-82}\right):\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 13
Error8.4
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -5.8 \cdot 10^{+127} \lor \neg \left(a \leq 3.5 \cdot 10^{-85}\right):\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \end{array} \]
Alternative 14
Error7.6
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -7.8 \cdot 10^{-53} \lor \neg \left(t \leq 4.6 \cdot 10^{-59}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 15
Error19.8
Cost717
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+60}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-97} \lor \neg \left(z \leq 1.18 \cdot 10^{-89}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 16
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+125}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-16}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 17
Error32.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -26000000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-80}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 18
Error39.4
Cost64
\[x \]

Error

Reproduce?

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