?

Average Error: 2.98% → 1.2%
Time: 13.5s
Precision: binary64
Cost: 20041

?

\[\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 -1.7 \cdot 10^{+121} \lor \neg \left(b \leq 2 \cdot 10^{-185}\right):\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, b \cdot z, \mathsf{fma}\left(t, a, \mathsf{fma}\left(y, z, x\right)\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 -1.7e+121) (not (<= b 2e-185)))
   (+ (+ (* t a) (+ x (* y z))) (* b (* z a)))
   (fma a (* b z) (fma t a (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 <= -1.7e+121) || !(b <= 2e-185)) {
		tmp = ((t * a) + (x + (y * z))) + (b * (z * a));
	} else {
		tmp = fma(a, (b * z), fma(t, a, 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 <= -1.7e+121) || !(b <= 2e-185))
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(b * Float64(z * a)));
	else
		tmp = fma(a, Float64(b * z), fma(t, a, 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, -1.7e+121], N[Not[LessEqual[b, 2e-185]], $MachinePrecision]], N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(b * z), $MachinePrecision] + N[(t * a + N[(y * z + x), $MachinePrecision]), $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 -1.7 \cdot 10^{+121} \lor \neg \left(b \leq 2 \cdot 10^{-185}\right):\\
\;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\

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


\end{array}

Error?

Target

Original2.98%
Target0.48%
Herbie1.2%
\[\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.70000000000000005e121 or 2e-185 < b

    1. Initial program 1.63

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

    if -1.70000000000000005e121 < b < 2e-185

    1. Initial program 4.43

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

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

      [Start]4.43

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

      +-commutative [=>]4.43

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

      associate-*l* [=>]0.76

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

      fma-def [=>]0.76

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

      +-commutative [=>]0.76

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

      fma-def [=>]0.75

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

      +-commutative [=>]0.75

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

      fma-def [=>]0.75

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

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

Alternatives

Alternative 1
Error0.98%
Cost13641
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2 \cdot 10^{+54} \lor \neg \left(b \leq 2 \cdot 10^{-186}\right):\\ \;\;\;\;\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, x\right)\right)\\ \end{array} \]
Alternative 2
Error31.99%
Cost1373
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -2.7 \cdot 10^{+147}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-213}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-30}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+96} \lor \neg \left(z \leq 1.55 \cdot 10^{+144}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error53.36%
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{+54}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-18}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-202}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-145}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-66}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+65}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error17.96%
Cost1237
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + y \cdot z\\ t_2 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -1.08 \cdot 10^{+147}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-240}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+96} \lor \neg \left(z \leq 5.8 \cdot 10^{+127}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error26.13%
Cost1236
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := x + a \cdot \left(t + b \cdot z\right)\\ t_3 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{+146}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-158}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+52}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Error1.05%
Cost1225
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;b \leq -4 \cdot 10^{-80} \lor \neg \left(b \leq 2 \cdot 10^{-186}\right):\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\ \end{array} \]
Alternative 7
Error43%
Cost1115
\[\begin{array}{l} \mathbf{if}\;x \leq -2.22 \cdot 10^{-150} \lor \neg \left(x \leq 8.8 \cdot 10^{-213}\right) \land \left(x \leq 4.7 \cdot 10^{-150} \lor \neg \left(x \leq 1.62 \cdot 10^{-77}\right) \land \left(x \leq 1.22 \cdot 10^{-10} \lor \neg \left(x \leq 3.8 \cdot 10^{+65}\right)\right)\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 8
Error31.63%
Cost1109
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -6.1 \cdot 10^{+144}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{-213}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+96} \lor \neg \left(z \leq 1.5 \cdot 10^{+143}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error14.1%
Cost1105
\[\begin{array}{l} t_1 := a \cdot \left(t + b \cdot z\right)\\ t_2 := \left(x + t \cdot a\right) + y \cdot z\\ \mathbf{if}\;y \leq -4.7 \cdot 10^{-59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-114}:\\ \;\;\;\;t_1 + y \cdot z\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-149} \lor \neg \left(y \leq 10^{-176}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x + t_1\\ \end{array} \]
Alternative 10
Error12.76%
Cost1100
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + y \cdot z\\ \mathbf{if}\;y \leq -9.4 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-114}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right) + y \cdot z\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-62}:\\ \;\;\;\;t \cdot a + \left(x + b \cdot \left(z \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error4.92%
Cost960
\[\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right) \]
Alternative 12
Error32.19%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2 \cdot 10^{-131} \lor \neg \left(z \leq 3.4 \cdot 10^{-213}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 13
Error52.22%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.18 \cdot 10^{-36}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error62.56%
Cost64
\[x \]

Error

Reproduce?

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