?

Average Error: 3.5% → 0.52%
Time: 12.8s
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^{+84} \lor \neg \left(b \leq 10000\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+84) (not (<= b 10000.0)))
   (+ (+ (* 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+84) || !(b <= 10000.0)) {
		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+84) || !(b <= 10000.0))
		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+84], N[Not[LessEqual[b, 10000.0]], $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^{+84} \lor \neg \left(b \leq 10000\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

Original3.5%
Target0.52%
Herbie0.52%
\[\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.00000000000000006e84 or 1e4 < 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 -1.00000000000000006e84 < b < 1e4

    1. Initial program 5.03

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

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

      [Start]5.03

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

      +-commutative [=>]5.03

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

      +-commutative [=>]5.03

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

      associate-+l+ [=>]5.03

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

      associate-+r+ [=>]5.03

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

      *-commutative [=>]5.03

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

      associate-*l* [=>]0.26

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

      *-commutative [=>]0.26

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

      distribute-lft-out [=>]0.26

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

      fma-def [=>]0.25

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

      fma-def [=>]0.25

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

      +-commutative [=>]0.25

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

      fma-def [=>]0.24

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{+84} \lor \neg \left(b \leq 10000\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
Error0.51%
Cost13641
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-36} \lor \neg \left(b \leq 5 \cdot 10^{+70}\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
Error32.11%
Cost1373
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := x + t \cdot a\\ t_3 := z \cdot \left(y + b \cdot a\right)\\ \mathbf{if}\;z \leq -8.6 \cdot 10^{+211}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+171} \lor \neg \left(z \leq 1.76 \cdot 10^{+270}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error24.35%
Cost1373
\[\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 -5.2 \cdot 10^{+211}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -5.3 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-11}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+124}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+171} \lor \neg \left(z \leq 8.1 \cdot 10^{+245}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error5.2%
Cost1225
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-216} \lor \neg \left(y \leq 10^{-179}\right):\\ \;\;\;\;\left(t \cdot a + a \cdot \left(b \cdot z\right)\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(z \cdot a\right) + \left(x + t \cdot a\right)\\ \end{array} \]
Alternative 5
Error0.51%
Cost1225
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;b \leq -5 \cdot 10^{-36} \lor \neg \left(b \leq 5 \cdot 10^{+70}\right):\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t \cdot a + a \cdot \left(b \cdot z\right)\right) + t_1\\ \end{array} \]
Alternative 6
Error12.06%
Cost969
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;y \leq -6.6 \cdot 10^{-71} \lor \neg \left(y \leq 2.7 \cdot 10^{-24}\right):\\ \;\;\;\;y \cdot z + t_1\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(z \cdot a\right) + t_1\\ \end{array} \]
Alternative 7
Error12.34%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -6.8 \cdot 10^{-71} \lor \neg \left(y \leq 3.1 \cdot 10^{-24}\right):\\ \;\;\;\;y \cdot z + \left(x + t \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \end{array} \]
Alternative 8
Error52.7%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -1.56 \cdot 10^{+62}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.52 \cdot 10^{-131}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-291}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+55}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error32%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+68} \lor \neg \left(y \leq 4.5 \cdot 10^{+29}\right):\\ \;\;\;\;x + y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 10
Error40.89%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{+226}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+29}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 11
Error52.79%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+63}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{+53}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error62.33%
Cost64
\[x \]

Error

Reproduce?

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