?

Average Error: 2.2 → 0.9
Time: 12.9s
Precision: binary64
Cost: 19913

?

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

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


\end{array}

Error?

Target

Original2.2
Target0.4
Herbie0.9
\[\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.00000000000000007e-229 or 2e51 < b

    1. Initial program 1.4

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

    if -1.00000000000000007e-229 < b < 2e51

    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.2

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

      [Start]3.4

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

      +-commutative [=>]3.4

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

      +-commutative [=>]3.4

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

      associate-+l+ [=>]3.4

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

      associate-+r+ [=>]3.4

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

      *-commutative [=>]3.4

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

      associate-*l* [=>]0.2

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

      *-commutative [=>]0.2

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

      distribute-lft-out [=>]0.2

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

      fma-def [=>]0.2

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

      fma-def [=>]0.2

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

      +-commutative [=>]0.2

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

      fma-def [=>]0.2

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

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

Alternatives

Alternative 1
Error2.2
Cost13508
\[\begin{array}{l} \mathbf{if}\;t \leq -2.4 \cdot 10^{-31}:\\ \;\;\;\;\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
Error2.2
Cost7364
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;t \leq -5 \cdot 10^{-31}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, a, a \cdot \left(b \cdot z\right)\right) + t_1\\ \end{array} \]
Alternative 3
Error38.8
Cost1512
\[\begin{array}{l} \mathbf{if}\;t \leq -1.4 \cdot 10^{+261}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq -3.2 \cdot 10^{+185}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -0.000155:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq -1.55 \cdot 10^{-125}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.4 \cdot 10^{-152}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq -1.02 \cdot 10^{-216}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.4 \cdot 10^{-234}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{-225}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 2.3 \cdot 10^{-169}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq 820000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot a\\ \end{array} \]
Alternative 4
Error21.8
Cost1376
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := a \cdot \left(t + b \cdot z\right)\\ t_3 := x + t \cdot a\\ \mathbf{if}\;a \leq -4.6 \cdot 10^{+17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.05 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -6 \cdot 10^{-143}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 8.8 \cdot 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 7.5 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 7 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.3 \cdot 10^{+163}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 7.8 \cdot 10^{+245}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b \cdot z\right)\\ \end{array} \]
Alternative 5
Error3.2
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \leq -1.26 \cdot 10^{-114} \lor \neg \left(a \leq -1.2 \cdot 10^{-299}\right):\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \end{array} \]
Alternative 6
Error25.9
Cost1115
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-80} \lor \neg \left(x \leq -1.35 \cdot 10^{-93}\right) \land \left(x \leq -3.85 \cdot 10^{-199} \lor \neg \left(x \leq 1.8 \cdot 10^{-274} \lor \neg \left(x \leq 7.6 \cdot 10^{-169}\right) \land x \leq 2.45 \cdot 10^{-138}\right)\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 7
Error2.2
Cost1092
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;t \leq -8 \cdot 10^{-31}:\\ \;\;\;\;\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 8
Error8.5
Cost972
\[\begin{array}{l} t_1 := x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -8.5 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-265}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-21}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error7.6
Cost969
\[\begin{array}{l} \mathbf{if}\;t \leq -1.52 \cdot 10^{-18} \lor \neg \left(t \leq 1.2\right):\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b \cdot z\right) + \left(x + y \cdot z\right)\\ \end{array} \]
Alternative 10
Error19.7
Cost848
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := x + t \cdot a\\ \mathbf{if}\;t \leq -5.2 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5 \cdot 10^{-299}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{-245}:\\ \;\;\;\;x + a \cdot \left(b \cdot z\right)\\ \mathbf{elif}\;t \leq 20:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error13.5
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{-31} \lor \neg \left(y \leq 1.45 \cdot 10^{+52}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \end{array} \]
Alternative 12
Error9.6
Cost841
\[\begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{-12} \lor \neg \left(b \leq 3.8 \cdot 10^{+175}\right):\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + t \cdot a\right) + y \cdot z\\ \end{array} \]
Alternative 13
Error38.4
Cost588
\[\begin{array}{l} \mathbf{if}\;a \leq -1.1 \cdot 10^{-50}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;a \leq 2.85 \cdot 10^{+116}:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 3 \cdot 10^{+189}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error19.6
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -5.8 \cdot 10^{-18} \lor \neg \left(t \leq 27.5\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 15
Error40.0
Cost64
\[x \]

Error

Reproduce?

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