?

Average Accuracy: 96.8% → 98.5%
Time: 12.7s
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 -5 \cdot 10^{+74} \lor \neg \left(b \leq 2 \cdot 10^{-214}\right):\\ \;\;\;\;b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\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 -5e+74) (not (<= b 2e-214)))
   (+ (* b (* z a)) (+ (* t a) (+ x (* y z))))
   (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 <= -5e+74) || !(b <= 2e-214)) {
		tmp = (b * (z * a)) + ((t * a) + (x + (y * z)));
	} 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 <= -5e+74) || !(b <= 2e-214))
		tmp = Float64(Float64(b * Float64(z * a)) + Float64(Float64(t * a) + Float64(x + Float64(y * z))));
	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, -5e+74], N[Not[LessEqual[b, 2e-214]], $MachinePrecision]], N[(N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision] + N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $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 -5 \cdot 10^{+74} \lor \neg \left(b \leq 2 \cdot 10^{-214}\right):\\
\;\;\;\;b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\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

Original96.8%
Target99.5%
Herbie98.5%
\[\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 < -4.99999999999999963e74 or 1.99999999999999983e-214 < b

    1. Initial program 97.7%

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

    if -4.99999999999999963e74 < b < 1.99999999999999983e-214

    1. Initial program 95.5%

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified99.6%

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

      [Start]95.5

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

      +-commutative [=>]95.5

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

      +-commutative [=>]95.5

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

      associate-+l+ [=>]95.5

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

      associate-+r+ [=>]95.5

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

      *-commutative [=>]95.5

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

      associate-*l* [=>]99.5

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

      *-commutative [=>]99.5

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

      distribute-lft-out [=>]99.5

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

      fma-def [=>]99.6

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

      fma-def [=>]99.6

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

      +-commutative [=>]99.6

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

      fma-def [=>]99.6

      \[ \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 simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+74} \lor \neg \left(b \leq 2 \cdot 10^{-214}\right):\\ \;\;\;\;b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\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
Accuracy98.5%
Cost13641
\[\begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-65} \lor \neg \left(b \leq 2 \cdot 10^{-214}\right):\\ \;\;\;\;b \cdot \left(z \cdot a\right) + \left(t \cdot a + \left(x + y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t + b \cdot z, \mathsf{fma}\left(y, z, x\right)\right)\\ \end{array} \]
Alternative 2
Accuracy70.2%
Cost1372
\[\begin{array}{l} t_1 := z \cdot \left(y + b \cdot a\right)\\ t_2 := x + y \cdot z\\ t_3 := x + t \cdot a\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3600000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-23}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-63}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-12}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+88}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy94.9%
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \leq 2 \cdot 10^{-174} \lor \neg \left(a \leq 10^{-125}\right):\\ \;\;\;\;\left(t \cdot a + a \cdot \left(b \cdot z\right)\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \end{array} \]
Alternative 4
Accuracy97.3%
Cost1225
\[\begin{array}{l} t_1 := t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{if}\;b \leq -1 \cdot 10^{-65} \lor \neg \left(b \leq 2 \cdot 10^{-214}\right):\\ \;\;\;\;b \cdot \left(z \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy71.0%
Cost1108
\[\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 -3.5 \cdot 10^{+151}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-14}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+86}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Accuracy47.0%
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-243}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-123}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.24 \cdot 10^{+17}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+55}:\\ \;\;\;\;z \cdot \left(b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy59.6%
Cost849
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;x \leq 5.4 \cdot 10^{-244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-148}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.24 \cdot 10^{+17} \lor \neg \left(x \leq 5.4 \cdot 10^{+55}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a\right)\\ \end{array} \]
Alternative 8
Accuracy68.7%
Cost849
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+151}:\\ \;\;\;\;z \cdot \left(b \cdot a\right)\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-61} \lor \neg \left(z \leq 7.4 \cdot 10^{-9}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 9
Accuracy80.1%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{-61} \lor \neg \left(z \leq 3.8 \cdot 10^{-15}\right):\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 10
Accuracy87.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -7.6 \cdot 10^{-43} \lor \neg \left(t \leq 4.8 \cdot 10^{-108}\right):\\ \;\;\;\;t \cdot a + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \end{array} \]
Alternative 11
Accuracy42.3%
Cost720
\[\begin{array}{l} \mathbf{if}\;t \leq -2.4 \cdot 10^{-23}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;t \leq 2 \cdot 10^{-198}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 5.7 \cdot 10^{-170}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;t \leq 8.6 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t \cdot a\\ \end{array} \]
Alternative 12
Accuracy42.7%
Cost457
\[\begin{array}{l} \mathbf{if}\;t \leq -2.15 \cdot 10^{-23} \lor \neg \left(t \leq 6.5 \cdot 10^{-20}\right):\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Accuracy37.8%
Cost64
\[x \]

Error

Reproduce?

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