?

Average Accuracy: 95.5% → 99.0%
Time: 18.8s
Precision: binary64
Cost: 13764

?

\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ [a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq 2.2 \cdot 10^{-105}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, -9 \cdot \left(z \cdot t\right), t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* b (* a 27.0))))
   (if (<= z 2.2e-105)
     (fma x 2.0 (fma y (* -9.0 (* z t)) t_1))
     (+ t_1 (- (* x 2.0) (* t (* 9.0 (* z y))))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = b * (a * 27.0);
	double tmp;
	if (z <= 2.2e-105) {
		tmp = fma(x, 2.0, fma(y, (-9.0 * (z * t)), t_1));
	} else {
		tmp = t_1 + ((x * 2.0) - (t * (9.0 * (z * y))));
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(b * Float64(a * 27.0))
	tmp = 0.0
	if (z <= 2.2e-105)
		tmp = fma(x, 2.0, fma(y, Float64(-9.0 * Float64(z * t)), t_1));
	else
		tmp = Float64(t_1 + Float64(Float64(x * 2.0) - Float64(t * Float64(9.0 * Float64(z * y)))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(a * 27.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 2.2e-105], N[(x * 2.0 + N[(y * N[(-9.0 * N[(z * t), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(x * 2.0), $MachinePrecision] - N[(t * N[(9.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\begin{array}{l}
t_1 := b \cdot \left(a \cdot 27\right)\\
\mathbf{if}\;z \leq 2.2 \cdot 10^{-105}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, -9 \cdot \left(z \cdot t\right), t_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right)\\


\end{array}

Error?

Target

Original95.5%
Target94.8%
Herbie99.0%
\[\begin{array}{l} \mathbf{if}\;y < 7.590524218811189 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if z < 2.20000000000000004e-105

    1. Initial program 94.4%

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

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

      [Start]94.4

      \[ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]

      associate-+l- [=>]94.4

      \[ \color{blue}{x \cdot 2 - \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)} \]

      fma-neg [=>]94.4

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

      neg-sub0 [=>]94.4

      \[ \mathsf{fma}\left(x, 2, \color{blue}{0 - \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}\right) \]

      associate-+l- [<=]94.4

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

      neg-sub0 [<=]94.4

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

      associate-*l* [=>]98.8

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

      associate-*l* [=>]99.0

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

      distribute-rgt-neg-in [=>]99.0

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

      fma-def [=>]99.0

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

      *-commutative [=>]99.0

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

      distribute-rgt-neg-in [=>]99.0

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

      metadata-eval [=>]99.0

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

    if 2.20000000000000004e-105 < z

    1. Initial program 99.2%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Taylor expanded in y around 0 99.2%

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot \left(y \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

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

Alternatives

Alternative 1
Accuracy83.3%
Cost1480
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+83}:\\ \;\;\;\;t_1 + \left(x + x\right)\\ \mathbf{elif}\;t_1 \leq 10^{-38}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot -9\right) \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \end{array} \]
Alternative 2
Accuracy98.3%
Cost1476
\[\begin{array}{l} \mathbf{if}\;z \cdot \left(y \cdot 9\right) \leq 10^{+295}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot -9\right) \cdot \left(z \cdot t\right)\\ \end{array} \]
Alternative 3
Accuracy81.3%
Cost1352
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \cdot 2 \leq -1 \cdot 10^{-24}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot -9\right) \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;x \cdot 2 \leq 10^{-43}:\\ \;\;\;\;t_1 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x + x\right)\\ \end{array} \]
Alternative 4
Accuracy99.1%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 8 \cdot 10^{-54}:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 5
Accuracy46.9%
Cost1112
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;a \leq -2.25 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.05 \cdot 10^{+100}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;a \leq -2.4 \cdot 10^{+85}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;a \leq -5.8 \cdot 10^{+54}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;a \leq -3.2 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.14 \cdot 10^{+64}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 6
Accuracy54.4%
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+43}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{-102}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{-201}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-112}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-25}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 7
Accuracy54.2%
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+43}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -1.26 \cdot 10^{-104}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-202}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-110}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-29}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 8
Accuracy71.6%
Cost972
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right) + \left(x + x\right)\\ \mathbf{if}\;y \leq -1.8 \cdot 10^{+247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{+241}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 9
Accuracy55.3%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+43}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -5.3 \cdot 10^{-104}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-22}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Accuracy56.2%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.12 \cdot 10^{-30}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-31}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 11
Accuracy41.7%
Cost192
\[x + x \]

Error

Reproduce?

herbie shell --seed 2023147 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"
  :precision binary64

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))