?

Average Accuracy: 96.6% → 99.0%
Time: 11.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}\;a \leq -5.5 \cdot 10^{+82} \lor \neg \left(a \leq 2.25 \cdot 10^{+126}\right):\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\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 (<= a -5.5e+82) (not (<= a 2.25e+126)))
   (fma a (+ t (* z b)) (fma y z x))
   (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 ((a <= -5.5e+82) || !(a <= 2.25e+126)) {
		tmp = fma(a, (t + (z * b)), fma(y, z, x));
	} 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 ((a <= -5.5e+82) || !(a <= 2.25e+126))
		tmp = fma(a, Float64(t + Float64(z * b)), fma(y, z, x));
	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[a, -5.5e+82], N[Not[LessEqual[a, 2.25e+126]], $MachinePrecision]], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $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}\;a \leq -5.5 \cdot 10^{+82} \lor \neg \left(a \leq 2.25 \cdot 10^{+126}\right):\\
\;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\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.6%
Target99.5%
Herbie99.0%
\[\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 a < -5.49999999999999997e82 or 2.24999999999999987e126 < a

    1. Initial program 87.8%

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

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

      [Start]87.8

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

      associate-+l+ [=>]87.8

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

      +-commutative [=>]87.8

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

      *-commutative [=>]87.8

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

      associate-*l* [=>]99.9

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

      distribute-lft-out [=>]99.9

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

      fma-def [=>]99.9

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

      +-commutative [=>]99.9

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

      fma-def [=>]99.9

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

    if -5.49999999999999997e82 < a < 2.24999999999999987e126

    1. Initial program 98.9%

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

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

      [Start]98.9

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

      +-commutative [=>]98.9

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

      +-commutative [=>]98.9

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

      associate-+l+ [=>]98.9

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

      associate-+r+ [=>]98.9

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

      *-commutative [=>]98.9

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

      associate-*l* [=>]98.8

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

      *-commutative [=>]98.8

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

      distribute-lft-out [=>]98.8

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

      fma-def [=>]98.8

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

      fma-def [=>]98.8

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

      +-commutative [=>]98.8

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

      fma-def [=>]98.8

      \[ \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 simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -5.5 \cdot 10^{+82} \lor \neg \left(a \leq 2.25 \cdot 10^{+126}\right):\\ \;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\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
Accuracy61.8%
Cost1640
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := a \cdot \left(t + z \cdot b\right)\\ t_3 := x + a \cdot t\\ t_4 := x + z \cdot y\\ \mathbf{if}\;x \leq -5 \cdot 10^{+205}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{+168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{+31}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-153}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-180}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-203}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-53}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Accuracy66.9%
Cost1241
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;z \leq -2.65 \cdot 10^{+88}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.9 \cdot 10^{-31}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-214}:\\ \;\;\;\;x + a \cdot t\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+23} \lor \neg \left(z \leq 3.2 \cdot 10^{+88}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \end{array} \]
Alternative 3
Accuracy61.8%
Cost1240
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := x + a \cdot t\\ t_3 := x + z \cdot y\\ \mathbf{if}\;x \leq -5 \cdot 10^{+205}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{+168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{+31}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-144}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy66.3%
Cost1240
\[\begin{array}{l} t_1 := z \cdot \left(y + a \cdot b\right)\\ t_2 := a \cdot t + z \cdot y\\ \mathbf{if}\;x \leq -102000000:\\ \;\;\;\;x + b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-144}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-227}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-265}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-169}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot t\\ \end{array} \]
Alternative 5
Accuracy43.8%
Cost984
\[\begin{array}{l} t_1 := z \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -3.7 \cdot 10^{+33}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-227}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.88 \cdot 10^{-264}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-161}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Accuracy43.7%
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -9.6 \cdot 10^{+34}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-101}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-227}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-264}:\\ \;\;\;\;b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-162}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy57.2%
Cost980
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;x \leq -0.0007:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-83}:\\ \;\;\;\;z \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-228}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.82 \cdot 10^{-264}:\\ \;\;\;\;b \cdot \left(a \cdot z\right)\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-172}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy95.8%
Cost960
\[\left(a \cdot \left(z \cdot b\right) + a \cdot t\right) + \left(x + z \cdot y\right) \]
Alternative 9
Accuracy96.6%
Cost960
\[\left(a \cdot t + \left(x + z \cdot y\right)\right) + b \cdot \left(a \cdot z\right) \]
Alternative 10
Accuracy45.3%
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -3000000000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.7 \cdot 10^{-96}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-182}:\\ \;\;\;\;a \cdot t\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-162}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy80.7%
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -1.4 \cdot 10^{-26} \lor \neg \left(a \leq 7.8 \cdot 10^{-66}\right):\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 12
Accuracy87.0%
Cost841
\[\begin{array}{l} \mathbf{if}\;a \leq -1.5 \cdot 10^{+35} \lor \neg \left(a \leq 4 \cdot 10^{-63}\right):\\ \;\;\;\;x + a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + a \cdot t\right) + z \cdot y\\ \end{array} \]
Alternative 13
Accuracy44.3%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+31}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.35 \cdot 10^{-102}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-162}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Accuracy65.9%
Cost716
\[\begin{array}{l} t_1 := x + a \cdot t\\ \mathbf{if}\;a \leq -2.55 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1 \cdot 10^{+36}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;a \leq 1.05 \cdot 10^{-57}:\\ \;\;\;\;x + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Accuracy46.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.05 \cdot 10^{-162}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{-112}:\\ \;\;\;\;a \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 16
Accuracy38.1%
Cost64
\[x \]

Error

Reproduce?

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