Average Error: 0.0 → 1.0
Time: 2.8s
Precision: binary64
Cost: 6724
\[\left(\frac{x}{2} + y \cdot x\right) + z \]
\[\begin{array}{l} \mathbf{if}\;y \leq -9220194.986088628:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{elif}\;y \leq 1.459398127082692 \cdot 10^{-17}:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y -9220194.986088628)
   (fma y x z)
   (if (<= y 1.459398127082692e-17) (+ z (* x 0.5)) (+ z (* y x)))))
double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -9220194.986088628) {
		tmp = fma(y, x, z);
	} else if (y <= 1.459398127082692e-17) {
		tmp = z + (x * 0.5);
	} else {
		tmp = z + (y * x);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function code(x, y, z)
	tmp = 0.0
	if (y <= -9220194.986088628)
		tmp = fma(y, x, z);
	elseif (y <= 1.459398127082692e-17)
		tmp = Float64(z + Float64(x * 0.5));
	else
		tmp = Float64(z + Float64(y * x));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, -9220194.986088628], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 1.459398127082692e-17], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\left(\frac{x}{2} + y \cdot x\right) + z
\begin{array}{l}
\mathbf{if}\;y \leq -9220194.986088628:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\

\mathbf{elif}\;y \leq 1.459398127082692 \cdot 10^{-17}:\\
\;\;\;\;z + x \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if y < -9220194.98608862795

    1. Initial program 0.0

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around inf 0.2

      \[\leadsto \color{blue}{y \cdot x} + z \]
    3. Applied egg-rr0.2

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

    if -9220194.98608862795 < y < 1.45939812708269215e-17

    1. Initial program 0.0

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around 0 0.6

      \[\leadsto \color{blue}{0.5 \cdot x} + z \]

    if 1.45939812708269215e-17 < y

    1. Initial program 0.0

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Taylor expanded in y around inf 2.5

      \[\leadsto \color{blue}{y \cdot x} + z \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9220194.986088628:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{elif}\;y \leq 1.459398127082692 \cdot 10^{-17}:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error11.3
Cost848
\[\begin{array}{l} t_0 := z + x \cdot 0.5\\ \mathbf{if}\;y \leq -2.927740896032205 \cdot 10^{+48}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 6.327738987395586 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+157}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+201}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error29.0
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.927740896032205 \cdot 10^{+48}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 6.327738987395586 \cdot 10^{+22}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+157}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+201}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Error1.0
Cost584
\[\begin{array}{l} t_0 := z + y \cdot x\\ \mathbf{if}\;y \leq -9220194.986088628:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.459398127082692 \cdot 10^{-17}:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error33.6
Cost64
\[z \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x y z)
  :name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
  :precision binary64
  (+ (+ (/ x 2.0) (* y x)) z))