Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1

Percentage Accurate: 100.0% → 100.0%
Time: 3.0s
Alternatives: 8
Speedup: 0.1×

Specification

?
\[\begin{array}{l} \\ \left(\frac{x}{2} + y \cdot x\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z):
	return ((x / 2.0) + (y * x)) + z
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function tmp = code(x, y, z)
	tmp = ((x / 2.0) + (y * x)) + z;
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{x}{2} + y \cdot x\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
	return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z):
	return ((x / 2.0) + (y * x)) + z
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z)
end
function tmp = code(x, y, z)
	tmp = ((x / 2.0) + (y * x)) + z;
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x, y + 0.5, z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma x (+ y 0.5) z))
double code(double x, double y, double z) {
	return fma(x, (y + 0.5), z);
}
function code(x, y, z)
	return fma(x, Float64(y + 0.5), z)
end
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, y + 0.5, z\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Step-by-step derivation
    1. associate-+l+100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
    2. *-commutative100.0%

      \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
  4. Taylor expanded in x around 0 100.0%

    \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
  5. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x + z} \]
    2. *-commutative100.0%

      \[\leadsto \color{blue}{x \cdot \left(0.5 + y\right)} + z \]
    3. fma-udef100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.5 + y, z\right)} \]
    4. +-commutative100.0%

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + 0.5}, z\right) \]
  6. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y + 0.5, z\right)} \]
  7. Final simplification100.0%

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

Alternative 2: 59.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -16000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.38 \cdot 10^{-273}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-184}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+33}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+205}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{+226}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -16000.0)
   (* x y)
   (if (<= y -1.38e-273)
     z
     (if (<= y 3e-184)
       (* x 0.5)
       (if (<= y 2.1e+33)
         z
         (if (<= y 1.25e+205) (* x y) (if (<= y 5.7e+226) z (* x y))))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -16000.0) {
		tmp = x * y;
	} else if (y <= -1.38e-273) {
		tmp = z;
	} else if (y <= 3e-184) {
		tmp = x * 0.5;
	} else if (y <= 2.1e+33) {
		tmp = z;
	} else if (y <= 1.25e+205) {
		tmp = x * y;
	} else if (y <= 5.7e+226) {
		tmp = z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-16000.0d0)) then
        tmp = x * y
    else if (y <= (-1.38d-273)) then
        tmp = z
    else if (y <= 3d-184) then
        tmp = x * 0.5d0
    else if (y <= 2.1d+33) then
        tmp = z
    else if (y <= 1.25d+205) then
        tmp = x * y
    else if (y <= 5.7d+226) then
        tmp = z
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -16000.0) {
		tmp = x * y;
	} else if (y <= -1.38e-273) {
		tmp = z;
	} else if (y <= 3e-184) {
		tmp = x * 0.5;
	} else if (y <= 2.1e+33) {
		tmp = z;
	} else if (y <= 1.25e+205) {
		tmp = x * y;
	} else if (y <= 5.7e+226) {
		tmp = z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -16000.0:
		tmp = x * y
	elif y <= -1.38e-273:
		tmp = z
	elif y <= 3e-184:
		tmp = x * 0.5
	elif y <= 2.1e+33:
		tmp = z
	elif y <= 1.25e+205:
		tmp = x * y
	elif y <= 5.7e+226:
		tmp = z
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -16000.0)
		tmp = Float64(x * y);
	elseif (y <= -1.38e-273)
		tmp = z;
	elseif (y <= 3e-184)
		tmp = Float64(x * 0.5);
	elseif (y <= 2.1e+33)
		tmp = z;
	elseif (y <= 1.25e+205)
		tmp = Float64(x * y);
	elseif (y <= 5.7e+226)
		tmp = z;
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -16000.0)
		tmp = x * y;
	elseif (y <= -1.38e-273)
		tmp = z;
	elseif (y <= 3e-184)
		tmp = x * 0.5;
	elseif (y <= 2.1e+33)
		tmp = z;
	elseif (y <= 1.25e+205)
		tmp = x * y;
	elseif (y <= 5.7e+226)
		tmp = z;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -16000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.38e-273], z, If[LessEqual[y, 3e-184], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2.1e+33], z, If[LessEqual[y, 1.25e+205], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.7e+226], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq -1.38 \cdot 10^{-273}:\\
\;\;\;\;z\\

\mathbf{elif}\;y \leq 3 \cdot 10^{-184}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 2.1 \cdot 10^{+33}:\\
\;\;\;\;z\\

\mathbf{elif}\;y \leq 1.25 \cdot 10^{+205}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 5.7 \cdot 10^{+226}:\\
\;\;\;\;z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -16000 or 2.1000000000000001e33 < y < 1.25e205 or 5.69999999999999948e226 < y

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around inf 75.8%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in y around inf 75.4%

      \[\leadsto \color{blue}{y \cdot x} \]

    if -16000 < y < -1.37999999999999993e-273 or 2.99999999999999991e-184 < y < 2.1000000000000001e33 or 1.25e205 < y < 5.69999999999999948e226

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in z around inf 66.6%

      \[\leadsto \color{blue}{z} \]

    if -1.37999999999999993e-273 < y < 2.99999999999999991e-184

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around inf 69.0%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in y around 0 69.0%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -16000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.38 \cdot 10^{-273}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-184}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+33}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+205}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{+226}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 3: 73.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -27 \lor \neg \left(x \leq -1.08 \cdot 10^{-54} \lor \neg \left(x \leq -3.4 \cdot 10^{-82}\right) \land x \leq 7.6 \cdot 10^{-78}\right):\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -27.0)
         (not
          (or (<= x -1.08e-54) (and (not (<= x -3.4e-82)) (<= x 7.6e-78)))))
   (* x (+ y 0.5))
   z))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -27.0) || !((x <= -1.08e-54) || (!(x <= -3.4e-82) && (x <= 7.6e-78)))) {
		tmp = x * (y + 0.5);
	} else {
		tmp = z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-27.0d0)) .or. (.not. (x <= (-1.08d-54)) .or. (.not. (x <= (-3.4d-82))) .and. (x <= 7.6d-78))) then
        tmp = x * (y + 0.5d0)
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -27.0) || !((x <= -1.08e-54) || (!(x <= -3.4e-82) && (x <= 7.6e-78)))) {
		tmp = x * (y + 0.5);
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -27.0) or not ((x <= -1.08e-54) or (not (x <= -3.4e-82) and (x <= 7.6e-78))):
		tmp = x * (y + 0.5)
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -27.0) || !((x <= -1.08e-54) || (!(x <= -3.4e-82) && (x <= 7.6e-78))))
		tmp = Float64(x * Float64(y + 0.5));
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -27.0) || ~(((x <= -1.08e-54) || (~((x <= -3.4e-82)) && (x <= 7.6e-78)))))
		tmp = x * (y + 0.5);
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -27.0], N[Not[Or[LessEqual[x, -1.08e-54], And[N[Not[LessEqual[x, -3.4e-82]], $MachinePrecision], LessEqual[x, 7.6e-78]]]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -27 \lor \neg \left(x \leq -1.08 \cdot 10^{-54} \lor \neg \left(x \leq -3.4 \cdot 10^{-82}\right) \land x \leq 7.6 \cdot 10^{-78}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -27 or -1.08000000000000002e-54 < x < -3.39999999999999975e-82 or 7.5999999999999998e-78 < x

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around inf 80.0%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x} \]

    if -27 < x < -1.08000000000000002e-54 or -3.39999999999999975e-82 < x < 7.5999999999999998e-78

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in z around inf 75.8%

      \[\leadsto \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -27 \lor \neg \left(x \leq -1.08 \cdot 10^{-54} \lor \neg \left(x \leq -3.4 \cdot 10^{-82}\right) \land x \leq 7.6 \cdot 10^{-78}\right):\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 4: 85.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{-107} \lor \neg \left(z \leq 4.8 \cdot 10^{-160}\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -6.8e-107) (not (<= z 4.8e-160)))
   (+ z (* x y))
   (* x (+ y 0.5))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -6.8e-107) || !(z <= 4.8e-160)) {
		tmp = z + (x * y);
	} else {
		tmp = x * (y + 0.5);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-6.8d-107)) .or. (.not. (z <= 4.8d-160))) then
        tmp = z + (x * y)
    else
        tmp = x * (y + 0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -6.8e-107) || !(z <= 4.8e-160)) {
		tmp = z + (x * y);
	} else {
		tmp = x * (y + 0.5);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -6.8e-107) or not (z <= 4.8e-160):
		tmp = z + (x * y)
	else:
		tmp = x * (y + 0.5)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -6.8e-107) || !(z <= 4.8e-160))
		tmp = Float64(z + Float64(x * y));
	else
		tmp = Float64(x * Float64(y + 0.5));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -6.8e-107) || ~((z <= 4.8e-160)))
		tmp = z + (x * y);
	else
		tmp = x * (y + 0.5);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.8e-107], N[Not[LessEqual[z, 4.8e-160]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-107} \lor \neg \left(z \leq 4.8 \cdot 10^{-160}\right):\\
\;\;\;\;z + x \cdot y\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.79999999999999989e-107 or 4.79999999999999982e-160 < z

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in y around inf 90.6%

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

    if -6.79999999999999989e-107 < z < 4.79999999999999982e-160

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around inf 93.7%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{-107} \lor \neg \left(z \leq 4.8 \cdot 10^{-160}\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \end{array} \]

Alternative 5: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -65 \lor \neg \left(y \leq 0.019\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z + \frac{x}{2}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -65.0) (not (<= y 0.019))) (+ z (* x y)) (+ z (/ x 2.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -65.0) || !(y <= 0.019)) {
		tmp = z + (x * y);
	} else {
		tmp = z + (x / 2.0);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-65.0d0)) .or. (.not. (y <= 0.019d0))) then
        tmp = z + (x * y)
    else
        tmp = z + (x / 2.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -65.0) || !(y <= 0.019)) {
		tmp = z + (x * y);
	} else {
		tmp = z + (x / 2.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -65.0) or not (y <= 0.019):
		tmp = z + (x * y)
	else:
		tmp = z + (x / 2.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -65.0) || !(y <= 0.019))
		tmp = Float64(z + Float64(x * y));
	else
		tmp = Float64(z + Float64(x / 2.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -65.0) || ~((y <= 0.019)))
		tmp = z + (x * y);
	else
		tmp = z + (x / 2.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -65.0], N[Not[LessEqual[y, 0.019]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -65 \lor \neg \left(y \leq 0.019\right):\\
\;\;\;\;z + x \cdot y\\

\mathbf{else}:\\
\;\;\;\;z + \frac{x}{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -65 or 0.0189999999999999995 < y

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in y around inf 99.6%

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

    if -65 < y < 0.0189999999999999995

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \frac{x}{2} + \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -65 \lor \neg \left(y \leq 0.019\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z + \frac{x}{2}\\ \end{array} \]

Alternative 6: 50.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-117}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-160}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.15e-117) z (if (<= z 5e-160) (* x 0.5) z)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.15e-117) {
		tmp = z;
	} else if (z <= 5e-160) {
		tmp = x * 0.5;
	} else {
		tmp = z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-1.15d-117)) then
        tmp = z
    else if (z <= 5d-160) then
        tmp = x * 0.5d0
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.15e-117) {
		tmp = z;
	} else if (z <= 5e-160) {
		tmp = x * 0.5;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.15e-117:
		tmp = z
	elif z <= 5e-160:
		tmp = x * 0.5
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.15e-117)
		tmp = z;
	elseif (z <= 5e-160)
		tmp = Float64(x * 0.5);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.15e-117)
		tmp = z;
	elseif (z <= 5e-160)
		tmp = x * 0.5;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.15e-117], z, If[LessEqual[z, 5e-160], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-117}:\\
\;\;\;\;z\\

\mathbf{elif}\;z \leq 5 \cdot 10^{-160}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.14999999999999997e-117 or 4.99999999999999994e-160 < z

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in z around inf 58.2%

      \[\leadsto \color{blue}{z} \]

    if -1.14999999999999997e-117 < z < 4.99999999999999994e-160

    1. Initial program 100.0%

      \[\left(\frac{x}{2} + y \cdot x\right) + z \]
    2. Step-by-step derivation
      1. associate-+l+100.0%

        \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
      2. *-commutative100.0%

        \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
    4. Taylor expanded in x around inf 93.6%

      \[\leadsto \color{blue}{\left(0.5 + y\right) \cdot x} \]
    5. Taylor expanded in y around 0 52.8%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-117}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-160}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 7: 100.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ z + x \cdot \left(y + 0.5\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ z (* x (+ y 0.5))))
double code(double x, double y, double z) {
	return z + (x * (y + 0.5));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z + (x * (y + 0.5d0))
end function
public static double code(double x, double y, double z) {
	return z + (x * (y + 0.5));
}
def code(x, y, z):
	return z + (x * (y + 0.5))
function code(x, y, z)
	return Float64(z + Float64(x * Float64(y + 0.5)))
end
function tmp = code(x, y, z)
	tmp = z + (x * (y + 0.5));
end
code[x_, y_, z_] := N[(z + N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
z + x \cdot \left(y + 0.5\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Step-by-step derivation
    1. associate-+l+100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
    2. *-commutative100.0%

      \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
  4. Taylor expanded in x around 0 100.0%

    \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
  5. Final simplification100.0%

    \[\leadsto z + x \cdot \left(y + 0.5\right) \]

Alternative 8: 40.6% accurate, 9.0× speedup?

\[\begin{array}{l} \\ z \end{array} \]
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
	return z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z
end function
public static double code(double x, double y, double z) {
	return z;
}
def code(x, y, z):
	return z
function code(x, y, z)
	return z
end
function tmp = code(x, y, z)
	tmp = z;
end
code[x_, y_, z_] := z
\begin{array}{l}

\\
z
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Step-by-step derivation
    1. associate-+l+100.0%

      \[\leadsto \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)} \]
    2. *-commutative100.0%

      \[\leadsto \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{x}{2} + \left(x \cdot y + z\right)} \]
  4. Taylor expanded in x around 0 100.0%

    \[\leadsto \color{blue}{z + \left(0.5 + y\right) \cdot x} \]
  5. Taylor expanded in z around inf 45.5%

    \[\leadsto \color{blue}{z} \]
  6. Final simplification45.5%

    \[\leadsto z \]

Reproduce

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