?

Average Accuracy: 96.3% → 97.9%
Time: 18.6s
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 5 \cdot 10^{+16}:\\ \;\;\;\;\left(t \cdot a + \left(x + z \cdot y\right)\right) + \left(z \cdot a\right) \cdot b\\ \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 (<= z 5e+16)
   (+ (+ (* t a) (+ x (* z y))) (* (* z a) b))
   (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 (z <= 5e+16) {
		tmp = ((t * a) + (x + (z * y))) + ((z * a) * b);
	} 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 (z <= 5e+16)
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(z * y))) + Float64(Float64(z * a) * b));
	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[LessEqual[z, 5e+16], N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(z * a), $MachinePrecision] * b), $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}\;z \leq 5 \cdot 10^{+16}:\\
\;\;\;\;\left(t \cdot a + \left(x + z \cdot y\right)\right) + \left(z \cdot a\right) \cdot b\\

\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.3%
Target99.5%
Herbie97.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 < 5e16

    1. Initial program 97.5%

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

    if 5e16 < z

    1. Initial program 90.6%

      \[\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(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)} \]
      Proof

      [Start]90.6

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

      +-commutative [=>]90.6

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

      +-commutative [=>]90.6

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

      associate-+l+ [=>]90.6

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

      associate-+r+ [=>]90.6

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

      *-commutative [=>]90.6

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

      associate-*l* [=>]99.9

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

      *-commutative [=>]99.9

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

      distribute-lft-out [=>]99.9

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

      fma-def [=>]99.9

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

      fma-def [=>]99.9

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

      +-commutative [=>]99.9

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

      fma-def [=>]99.9

      \[ \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 simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 5 \cdot 10^{+16}:\\ \;\;\;\;\left(t \cdot a + \left(x + z \cdot y\right)\right) + \left(z \cdot a\right) \cdot b\\ \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
Accuracy96.9%
Cost19780
\[\begin{array}{l} \mathbf{if}\;b \leq -3.05 \cdot 10^{+134}:\\ \;\;\;\;\left(t \cdot a + \left(x + z \cdot y\right)\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \end{array} \]
Alternative 2
Accuracy45.8%
Cost1512
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -19500000000:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{-57}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{-112}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-171}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -4.6 \cdot 10^{-254}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-270}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-132}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-84}:\\ \;\;\;\;a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+34}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy45.8%
Cost1512
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -540000000000:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-57}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-112}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-167}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -6.3 \cdot 10^{-254}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-268}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.14 \cdot 10^{-129}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-84}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+35}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Accuracy62.4%
Cost1504
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := z \cdot \left(y + a \cdot b\right)\\ t_3 := x + z \cdot y\\ t_4 := a \cdot \left(t + z \cdot b\right)\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{+122}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -28500000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-57}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-112}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -5.3 \cdot 10^{-166}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.28 \cdot 10^{+60}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Accuracy65.3%
Cost1504
\[\begin{array}{l} t_1 := a \cdot \left(t + z \cdot b\right)\\ t_2 := x + t \cdot a\\ t_3 := x + z \cdot y\\ \mathbf{if}\;y \leq -3.8 \cdot 10^{+55}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.4 \cdot 10^{-8}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.26 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{-101}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{-180}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-132}:\\ \;\;\;\;x + a \cdot \left(z \cdot b\right)\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+111}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t \cdot a + z \cdot y\\ \end{array} \]
Alternative 6
Accuracy46.4%
Cost1248
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -16000000000:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-57}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-112}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-170}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-254}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-270}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+34}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy65.4%
Cost1108
\[\begin{array}{l} t_1 := t \cdot a + z \cdot y\\ t_2 := x + z \cdot y\\ \mathbf{if}\;x \leq -2.7 \cdot 10^{+119}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.6 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{-269}:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + z \cdot y\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+60}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Accuracy79.5%
Cost1105
\[\begin{array}{l} t_1 := \left(x + t \cdot a\right) + z \cdot y\\ \mathbf{if}\;x \leq -4.8 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-270}:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + z \cdot y\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-129} \lor \neg \left(x \leq 6.6 \cdot 10^{-42}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right)\\ \end{array} \]
Alternative 9
Accuracy96.9%
Cost1092
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;b \leq -4 \cdot 10^{+135}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(t + z \cdot b\right) + t_1\\ \end{array} \]
Alternative 10
Accuracy87.4%
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-99}:\\ \;\;\;\;t \cdot a + \left(x + z \cdot y\right)\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-6}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;\left(x + t \cdot a\right) + z \cdot y\\ \end{array} \]
Alternative 11
Accuracy85.1%
Cost968
\[\begin{array}{l} t_1 := x + z \cdot y\\ \mathbf{if}\;x \leq -6.1 \cdot 10^{-96}:\\ \;\;\;\;t \cdot a + t_1\\ \mathbf{elif}\;x \leq 0.82:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right) + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(z \cdot b\right) + t_1\\ \end{array} \]
Alternative 12
Accuracy67.9%
Cost849
\[\begin{array}{l} t_1 := x + t \cdot a\\ \mathbf{if}\;a \leq -4.5 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.3 \cdot 10^{-96}:\\ \;\;\;\;z \cdot \left(y + a \cdot b\right)\\ \mathbf{elif}\;a \leq -1.65 \cdot 10^{-139} \lor \neg \left(a \leq 3.8 \cdot 10^{-92}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 13
Accuracy87.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -4.6 \cdot 10^{-151} \lor \neg \left(t \leq 2.05 \cdot 10^{-128}\right):\\ \;\;\;\;\left(x + t \cdot a\right) + z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \end{array} \]
Alternative 14
Accuracy87.6%
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -4.6 \cdot 10^{-151}:\\ \;\;\;\;\left(x + t \cdot a\right) + z \cdot y\\ \mathbf{elif}\;t \leq 2.25 \cdot 10^{-128}:\\ \;\;\;\;x + z \cdot \left(y + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot a + \left(x + z \cdot y\right)\\ \end{array} \]
Alternative 15
Accuracy95.4%
Cost832
\[a \cdot \left(t + z \cdot b\right) + \left(x + z \cdot y\right) \]
Alternative 16
Accuracy61.1%
Cost588
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+141}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 5.9 \cdot 10^{+128}:\\ \;\;\;\;x + t \cdot a\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+288}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 17
Accuracy68.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;a \leq -3.2 \cdot 10^{-73} \lor \neg \left(a \leq 9.4 \cdot 10^{-94}\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot y\\ \end{array} \]
Alternative 18
Accuracy46.2%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+30}:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 19
Accuracy37.0%
Cost64
\[x \]

Error

Reproduce?

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