Average Error: 0.0 → 9.7
Time: 5.5s
Precision: binary64
Cost: 7500
\[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+30}:\\ \;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\ \mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-46}:\\ \;\;\;\;a \cdot b + t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-72}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\ \end{array} \]
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -1e+30)
   (fma a b (* y x))
   (if (<= (* a b) -2e-46)
     (+ (* a b) (* t z))
     (if (<= (* a b) 2e-72) (fma y x (* t z)) (fma y x (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * y) + (z * t)) + (a * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -1e+30) {
		tmp = fma(a, b, (y * x));
	} else if ((a * b) <= -2e-46) {
		tmp = (a * b) + (t * z);
	} else if ((a * b) <= 2e-72) {
		tmp = fma(y, x, (t * z));
	} else {
		tmp = fma(y, x, (a * b));
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b))
end
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -1e+30)
		tmp = fma(a, b, Float64(y * x));
	elseif (Float64(a * b) <= -2e-46)
		tmp = Float64(Float64(a * b) + Float64(t * z));
	elseif (Float64(a * b) <= 2e-72)
		tmp = fma(y, x, Float64(t * z));
	else
		tmp = fma(y, x, Float64(a * b));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+30], N[(a * b + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e-46], N[(N[(a * b), $MachinePrecision] + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e-72], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]]]]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+30}:\\
\;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\

\mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-46}:\\
\;\;\;\;a \cdot b + t \cdot z\\

\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\


\end{array}

Error

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 a b) < -1e30

    1. Initial program 0.0

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    3. Taylor expanded in z around 0 10.9

      \[\leadsto \color{blue}{a \cdot b + y \cdot x} \]
    4. Applied egg-rr10.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, a \cdot b\right)} \]
    5. Taylor expanded in y around 0 10.9

      \[\leadsto \color{blue}{a \cdot b + y \cdot x} \]
    6. Simplified10.9

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

    if -1e30 < (*.f64 a b) < -2.00000000000000005e-46

    1. Initial program 0.0

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Taylor expanded in x around 0 23.2

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    3. Simplified23.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, b, t \cdot z\right)} \]
    4. Applied egg-rr23.2

      \[\leadsto \color{blue}{t \cdot z + a \cdot b} \]

    if -2.00000000000000005e-46 < (*.f64 a b) < 1.9999999999999999e-72

    1. Initial program 0.0

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    3. Taylor expanded in a around 0 4.5

      \[\leadsto \color{blue}{y \cdot x + t \cdot z} \]
    4. Simplified4.5

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

    if 1.9999999999999999e-72 < (*.f64 a b)

    1. Initial program 0.0

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    3. Taylor expanded in z around 0 14.6

      \[\leadsto \color{blue}{a \cdot b + y \cdot x} \]
    4. Applied egg-rr14.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, a \cdot b\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.7

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

Alternatives

Alternative 1
Error9.7
Cost7500
\[\begin{array}{l} t_1 := a \cdot b + y \cdot x\\ \mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-46}:\\ \;\;\;\;a \cdot b + t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-72}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error9.7
Cost7500
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+30}:\\ \;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\ \mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-46}:\\ \;\;\;\;a \cdot b + t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-72}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + y \cdot x\\ \end{array} \]
Alternative 3
Error23.1
Cost1240
\[\begin{array}{l} t_1 := a \cdot b + t \cdot z\\ \mathbf{if}\;a \leq -2.658542133680414 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.5918549168358408 \cdot 10^{-139}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;a \leq 4.547715440359494 \cdot 10^{-278}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.2235150862565804 \cdot 10^{-226}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;a \leq 3.2925247215507614 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.730284291716509 \cdot 10^{-39}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error30.0
Cost1232
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -8.647093153606554 \cdot 10^{-17}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -1.9415546941397957 \cdot 10^{-59}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq -1.0343792498660506 \cdot 10^{-138}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;a \cdot b \leq 1.5924005794048365 \cdot 10^{-72}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 5
Error9.7
Cost1228
\[\begin{array}{l} t_1 := a \cdot b + y \cdot x\\ \mathbf{if}\;a \cdot b \leq -1.1275804822513018 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -2.1898384731153152 \cdot 10^{-46}:\\ \;\;\;\;a \cdot b + t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 1.5924005794048365 \cdot 10^{-72}:\\ \;\;\;\;y \cdot x + t \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error15.0
Cost976
\[\begin{array}{l} t_1 := a \cdot b + y \cdot x\\ t_2 := a \cdot b + t \cdot z\\ \mathbf{if}\;z \leq -1.95 \cdot 10^{+92}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.9064006968758767 \cdot 10^{-53}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 9.914749661589495 \cdot 10^{-148}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error30.2
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -8.647093153606554 \cdot 10^{-17}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 8.824314654231246 \cdot 10^{-39}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 8
Error42.0
Cost192
\[a \cdot b \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x y z t a b)
  :name "Linear.V3:$cdot from linear-1.19.1.3, B"
  :precision binary64
  (+ (+ (* x y) (* z t)) (* a b)))