?

Average Error: 3.06% → 0.56%
Time: 13.9s
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 -2 \cdot 10^{+54} \lor \neg \left(b \leq 5 \cdot 10^{-62}\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} \]
(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 -2e+54) (not (<= b 5e-62)))
   (+ (+ (* t a) (+ x (* y z))) (* b (* z a)))
   (fma a (+ t (* b z)) (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 <= -2e+54) || !(b <= 5e-62)) {
		tmp = ((t * a) + (x + (y * z))) + (b * (z * a));
	} else {
		tmp = fma(a, (t + (b * z)), 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 <= -2e+54) || !(b <= 5e-62))
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(b * Float64(z * a)));
	else
		tmp = fma(a, Float64(t + Float64(b * z)), 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, -2e+54], N[Not[LessEqual[b, 5e-62]], $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[(t + N[(b * z), $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 -2 \cdot 10^{+54} \lor \neg \left(b \leq 5 \cdot 10^{-62}\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}

Error?

Target

Original3.06%
Target0.48%
Herbie0.56%
\[\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 < -2.0000000000000002e54 or 5.0000000000000002e-62 < b

    1. Initial program 0.97

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

    if -2.0000000000000002e54 < b < 5.0000000000000002e-62

    1. Initial program 4.83

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

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

      [Start]4.83

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

      associate-+l+ [=>]4.83

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

      +-commutative [=>]4.83

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

      *-commutative [=>]4.83

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

      associate-*l* [=>]0.23

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

      distribute-lft-out [=>]0.23

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

      fma-def [=>]0.22

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

      +-commutative [=>]0.22

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

      fma-def [=>]0.21

      \[ \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.56

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{+54} \lor \neg \left(b \leq 5 \cdot 10^{-62}\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} \]

Alternatives

Alternative 1
Error69.71%
Cost1904
\[\begin{array}{l} t_1 := a \cdot \left(b \cdot z\right)\\ \mathbf{if}\;b \leq -2.4 \cdot 10^{+249}:\\ \;\;\;\;x\\ \mathbf{elif}\;b \leq -1.9 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -5.5 \cdot 10^{+109}:\\ \;\;\;\;x\\ \mathbf{elif}\;b \leq -9.2 \cdot 10^{+76}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;b \leq -1.5 \cdot 10^{+29}:\\ \;\;\;\;x\\ \mathbf{elif}\;b \leq -3.6 \cdot 10^{-191}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;b \leq -1.4 \cdot 10^{-269}:\\ \;\;\;\;x\\ \mathbf{elif}\;b \leq -1.75 \cdot 10^{-300}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-232}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{-136}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{+51}:\\ \;\;\;\;x\\ \mathbf{elif}\;b \leq 1.65 \cdot 10^{+260}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error62.75%
Cost1380
\[\begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{+126}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{+17}:\\ \;\;\;\;b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-47}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-57}:\\ \;\;\;\;a \cdot \left(b \cdot z\right)\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.42 \cdot 10^{-301}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-277}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-222}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;z \leq 13000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 3
Error32.88%
Cost1372
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ \mathbf{if}\;a \leq -3.6 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.2 \cdot 10^{-36}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;a \leq -3.2 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.5 \cdot 10^{-85}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.2 \cdot 10^{-43}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 5.5 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \end{array} \]
Alternative 4
Error62.46%
Cost1248
\[\begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{+127}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{+17}:\\ \;\;\;\;z \cdot \left(b \cdot a\right)\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-69}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-175}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-302}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{-278}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-222}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;z \leq 300000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error34.41%
Cost1113
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -3.35 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.1 \cdot 10^{-35}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;a \leq -1.85 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.52 \cdot 10^{+47}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 2.8 \cdot 10^{+174} \lor \neg \left(a \leq 4.3 \cdot 10^{+271}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b \cdot z\right)\\ \end{array} \]
Alternative 6
Error32.68%
Cost1108
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -8.3 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.9 \cdot 10^{-36}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;a \leq -1.35 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.2 \cdot 10^{+46}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 3.2 \cdot 10^{+172}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \end{array} \]
Alternative 7
Error24.86%
Cost1105
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{-16}:\\ \;\;\;\;z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;z \leq 290 \lor \neg \left(z \leq 8.5 \cdot 10^{+98}\right) \land z \leq 3 \cdot 10^{+189}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 8
Error42.2%
Cost981
\[\begin{array}{l} \mathbf{if}\;z \leq -1.32 \cdot 10^{+128}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -7 \cdot 10^{+15}:\\ \;\;\;\;b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-16} \lor \neg \left(z \leq 300000000\right) \land z \leq 1.9 \cdot 10^{+87}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 9
Error4.45%
Cost960
\[\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right) \]
Alternative 10
Error3.06%
Cost960
\[\left(t \cdot a + \left(x + y \cdot z\right)\right) + b \cdot \left(z \cdot a\right) \]
Alternative 11
Error32.79%
Cost849
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -3 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.05 \cdot 10^{+46}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;a \leq 2.8 \cdot 10^{+174} \lor \neg \left(a \leq 1.65 \cdot 10^{+271}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b \cdot z\right)\\ \end{array} \]
Alternative 12
Error15.3%
Cost840
\[\begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{+45}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;b \leq 1.32 \cdot 10^{+92}:\\ \;\;\;\;t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 13
Error15.25%
Cost840
\[\begin{array}{l} \mathbf{if}\;b \leq -5.6 \cdot 10^{+45}:\\ \;\;\;\;a \cdot \left(b \cdot z\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;b \leq 3.15 \cdot 10^{+94}:\\ \;\;\;\;t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 14
Error51.7%
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -1.75 \cdot 10^{+32}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-175}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{+36}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error51.27%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+32}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-9}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 16
Error62.02%
Cost64
\[x \]

Error

Reproduce?

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