?

Average Accuracy: 97.1% → 96.9%
Time: 15.0s
Precision: binary64
Cost: 19780

?

\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-248}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(z \cdot a\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 (<= z -2e-248)
   (fma z (fma a b y) (fma t a x))
   (+ (+ (* a t) (+ x (* z y))) (* b (* z a)))))
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 (z <= -2e-248) {
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	} else {
		tmp = ((a * t) + (x + (z * y))) + (b * (z * a));
	}
	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 (z <= -2e-248)
		tmp = fma(z, fma(a, b, y), fma(t, a, x));
	else
		tmp = Float64(Float64(Float64(a * t) + Float64(x + Float64(z * y))) + Float64(b * Float64(z * a)));
	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[LessEqual[z, -2e-248], N[(z * N[(a * b + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * t), $MachinePrecision] + N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(z * a), $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}\;z \leq -2 \cdot 10^{-248}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\

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


\end{array}

Error?

Target

Original97.1%
Target99.5%
Herbie96.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 z < -1.99999999999999996e-248

    1. Initial program 96.7%

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Simplified96.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]96.7

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

      +-commutative [=>]96.7

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

      +-commutative [=>]96.7

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

      associate-+l+ [=>]96.7

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

      associate-+r+ [=>]96.7

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

      *-commutative [=>]96.7

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

      associate-*l* [=>]96.2

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

      *-commutative [=>]96.2

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

      distribute-lft-out [=>]96.2

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

      fma-def [=>]96.2

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

      fma-def [=>]96.2

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

      +-commutative [=>]96.2

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

      fma-def [=>]96.2

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

    if -1.99999999999999996e-248 < z

    1. Initial program 97.4%

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.9%

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

Alternatives

Alternative 1
Accuracy97.8%
Cost14404
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := \left(a \cdot t + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;t_2 \leq 2 \cdot 10^{-89}:\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+294}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \end{array} \]
Alternative 2
Accuracy97.8%
Cost3017
\[\begin{array}{l} t_1 := x + z \cdot y\\ t_2 := \left(a \cdot t + t_1\right) + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;t_2 \leq 2 \cdot 10^{-89} \lor \neg \left(t_2 \leq 2 \cdot 10^{+294}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy59.5%
Cost1246
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b\right)\\ \mathbf{if}\;z \leq -5.8 \cdot 10^{+255}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{+140}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{+111}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq -5.9 \cdot 10^{+69} \lor \neg \left(z \leq -7.6 \cdot 10^{+53}\right) \land \left(z \leq 3.6 \cdot 10^{+92} \lor \neg \left(z \leq 1.08 \cdot 10^{+201}\right)\right):\\ \;\;\;\;x + a \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy43.2%
Cost1244
\[\begin{array}{l} t_1 := a \cdot \left(z \cdot b\right)\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{-76}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-298}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-189}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-90}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{+78}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+101}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy64.8%
Cost1240
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot y\\ t_3 := x + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -4.2 \cdot 10^{+145}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq -2.2 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -4.3 \cdot 10^{-172}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 3.1 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-100}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Accuracy96.1%
Cost1225
\[\begin{array}{l} \mathbf{if}\;z \leq 4.8 \cdot 10^{+89} \lor \neg \left(z \leq 4.3 \cdot 10^{+198}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 7
Accuracy96.1%
Cost1225
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;z \leq 4.5 \cdot 10^{+89} \lor \neg \left(z \leq 1.05 \cdot 10^{+200}\right):\\ \;\;\;\;\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{\frac{1}{b}}{a}}{z}} + t_1\\ \end{array} \]
Alternative 8
Accuracy86.3%
Cost1100
\[\begin{array}{l} t_1 := x + a \cdot t\\ t_2 := x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{+53}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.3 \cdot 10^{-78}:\\ \;\;\;\;t_1 + z \cdot y\\ \mathbf{elif}\;z \leq 11.6:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Accuracy44.1%
Cost980
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.22 \cdot 10^{-76}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-175}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-188}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 2.65 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy68.2%
Cost849
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;z \leq -6.4 \cdot 10^{+216}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+140}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-79} \lor \neg \left(z \leq 85\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 11
Accuracy69.1%
Cost844
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ \mathbf{if}\;z \leq -4 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.8:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{+92}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Accuracy83.7%
Cost841
\[\begin{array}{l} \mathbf{if}\;b \leq -5.6 \cdot 10^{+166} \lor \neg \left(b \leq 2.6 \cdot 10^{+67}\right):\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \end{array} \]
Alternative 13
Accuracy88.0%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{+53} \lor \neg \left(z \leq 7.5 \cdot 10^{+35}\right):\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \end{array} \]
Alternative 14
Accuracy48.2%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -2.15 \cdot 10^{-76}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-281}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-189}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+32}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Accuracy48.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.22 \cdot 10^{-76}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+29}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 16
Accuracy37.9%
Cost64
\[x \]

Error

Reproduce?

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