?

Average Accuracy: 96.9% → 97.9%
Time: 13.7s
Precision: binary64
Cost: 13508

?

\[\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^{-31}:\\ \;\;\;\;\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} \]
(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 (<= b -5e-31)
   (+ (+ (* t a) (+ x (* y z))) (* b (* z a)))
   (fma a (+ t (* b z)) (fma y z 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-31) {
		tmp = ((t * a) + (x + (y * z))) + (b * (z * a));
	} else {
		tmp = fma(a, (t + (b * z)), fma(y, z, 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-31)
		tmp = Float64(Float64(Float64(t * a) + Float64(x + Float64(y * z))) + Float64(b * Float64(z * a)));
	else
		tmp = fma(a, Float64(t + Float64(b * z)), fma(y, z, 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[b, -5e-31], N[(N[(N[(t * a), $MachinePrecision] + N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(t + N[(b * z), $MachinePrecision]), $MachinePrecision] + N[(y * z + 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^{-31}:\\
\;\;\;\;\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}

Error?

Target

Original96.9%
Target99.4%
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 b < -5e-31

    1. Initial program 98.9%

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

    if -5e-31 < b

    1. Initial program 96.2%

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

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

      [Start]96.2

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

      associate-+l+ [=>]96.2

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

      +-commutative [=>]96.2

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

      *-commutative [=>]96.2

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

      associate-*l* [=>]97.5

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

      distribute-lft-out [=>]97.5

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

      fma-def [=>]97.5

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

      +-commutative [=>]97.5

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

      fma-def [=>]97.5

      \[ \mathsf{fma}\left(a, t + z \cdot b, \color{blue}{\mathsf{fma}\left(y, z, x\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-31}:\\ \;\;\;\;\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} \]

Alternatives

Alternative 1
Accuracy94.4%
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \leq -1 \cdot 10^{-85} \lor \neg \left(a \leq 10^{-182}\right):\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + \left(x + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \end{array} \]
Alternative 2
Accuracy66.8%
Cost1113
\[\begin{array}{l} t_1 := x + y \cdot z\\ t_2 := x + t \cdot a\\ \mathbf{if}\;t \leq -2 \cdot 10^{+21}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -7.2 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{-216}:\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{elif}\;t \leq 1.1 \cdot 10^{-113} \lor \neg \left(t \leq 1.5 \cdot 10^{-52}\right) \land t \leq 1.02 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy70.0%
Cost1108
\[\begin{array}{l} t_1 := x + t \cdot a\\ t_2 := x + y \cdot z\\ t_3 := a \cdot \left(t + b \cdot z\right)\\ \mathbf{if}\;a \leq -6.4 \cdot 10^{+166}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -6.6 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.3 \cdot 10^{-70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 3.2 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.55 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Accuracy84.7%
Cost1104
\[\begin{array}{l} t_1 := y \cdot z + \left(x + t \cdot a\right)\\ t_2 := x + b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -4.3 \cdot 10^{+223}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq -2.3 \cdot 10^{+197}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -3.5 \cdot 10^{+84}:\\ \;\;\;\;x + z \cdot \left(y + b \cdot a\right)\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{+112}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Accuracy96.7%
Cost1092
\[\begin{array}{l} t_1 := x + y \cdot z\\ \mathbf{if}\;z \leq -1.2 \cdot 10^{+215}:\\ \;\;\;\;\left(a \cdot \left(b \cdot z\right) + t \cdot a\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;\left(t \cdot a + t_1\right) + b \cdot \left(z \cdot a\right)\\ \end{array} \]
Alternative 6
Accuracy67.8%
Cost850
\[\begin{array}{l} \mathbf{if}\;t \leq -1.55 \cdot 10^{+20} \lor \neg \left(t \leq 1.1 \cdot 10^{-113}\right) \land \left(t \leq 1.5 \cdot 10^{-52} \lor \neg \left(t \leq 7 \cdot 10^{+94}\right)\right):\\ \;\;\;\;x + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 7
Accuracy70.2%
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{-61}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-155}:\\ \;\;\;\;a \cdot \left(t + b \cdot z\right)\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-30}:\\ \;\;\;\;y \cdot z + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 8
Accuracy70.2%
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -3.3 \cdot 10^{-60}:\\ \;\;\;\;x + y \cdot z\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-153}:\\ \;\;\;\;b \cdot \left(z \cdot a\right) + t \cdot a\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-30}:\\ \;\;\;\;y \cdot z + t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 9
Accuracy84.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;b \leq -2.85 \cdot 10^{+222} \lor \neg \left(b \leq 1.9 \cdot 10^{+110}\right):\\ \;\;\;\;x + b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z + \left(x + t \cdot a\right)\\ \end{array} \]
Alternative 10
Accuracy87.8%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{-77} \lor \neg \left(y \leq 1.75 \cdot 10^{-85}\right):\\ \;\;\;\;y \cdot z + \left(x + t \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x + a \cdot \left(t + b \cdot z\right)\\ \end{array} \]
Alternative 11
Accuracy48.0%
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-199}:\\ \;\;\;\;t \cdot a\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-29}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Accuracy60.3%
Cost585
\[\begin{array}{l} \mathbf{if}\;b \leq -3.8 \cdot 10^{+224} \lor \neg \left(b \leq 1.16 \cdot 10^{+154}\right):\\ \;\;\;\;b \cdot \left(z \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;x + t \cdot a\\ \end{array} \]
Alternative 13
Accuracy49.3%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 740000:\\ \;\;\;\;t \cdot a\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Accuracy38.1%
Cost64
\[x \]

Error

Reproduce?

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