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

Percentage Accurate: 100.0% → 100.0%
Time: 4.8s
Alternatives: 9
Speedup: 1.0×

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 9 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, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{x}{2} + x \cdot y\right) + z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* x y)) z))
double code(double x, double y, double z) {
	return ((x / 2.0) + (x * y)) + 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) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
	return ((x / 2.0) + (x * y)) + z;
}
def code(x, y, z):
	return ((x / 2.0) + (x * y)) + z
function code(x, y, z)
	return Float64(Float64(Float64(x / 2.0) + Float64(x * y)) + z)
end
function tmp = code(x, y, z)
	tmp = ((x / 2.0) + (x * y)) + z;
end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}

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

    \[\left(\frac{x}{2} + y \cdot x\right) + z \]
  2. Add Preprocessing
  3. Final simplification100.0%

    \[\leadsto \left(\frac{x}{2} + x \cdot y\right) + z \]
  4. Add Preprocessing

Alternative 2: 57.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.5:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-206}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-267}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-196}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+137}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -0.5)
   (* x y)
   (if (<= y -5.2e-206)
     (* x 0.5)
     (if (<= y 6.6e-267)
       z
       (if (<= y 7.2e-196) (* x 0.5) (if (<= y 1.5e+137) z (* x y)))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -0.5) {
		tmp = x * y;
	} else if (y <= -5.2e-206) {
		tmp = x * 0.5;
	} else if (y <= 6.6e-267) {
		tmp = z;
	} else if (y <= 7.2e-196) {
		tmp = x * 0.5;
	} else if (y <= 1.5e+137) {
		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 <= (-0.5d0)) then
        tmp = x * y
    else if (y <= (-5.2d-206)) then
        tmp = x * 0.5d0
    else if (y <= 6.6d-267) then
        tmp = z
    else if (y <= 7.2d-196) then
        tmp = x * 0.5d0
    else if (y <= 1.5d+137) 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 <= -0.5) {
		tmp = x * y;
	} else if (y <= -5.2e-206) {
		tmp = x * 0.5;
	} else if (y <= 6.6e-267) {
		tmp = z;
	} else if (y <= 7.2e-196) {
		tmp = x * 0.5;
	} else if (y <= 1.5e+137) {
		tmp = z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -0.5:
		tmp = x * y
	elif y <= -5.2e-206:
		tmp = x * 0.5
	elif y <= 6.6e-267:
		tmp = z
	elif y <= 7.2e-196:
		tmp = x * 0.5
	elif y <= 1.5e+137:
		tmp = z
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -0.5)
		tmp = Float64(x * y);
	elseif (y <= -5.2e-206)
		tmp = Float64(x * 0.5);
	elseif (y <= 6.6e-267)
		tmp = z;
	elseif (y <= 7.2e-196)
		tmp = Float64(x * 0.5);
	elseif (y <= 1.5e+137)
		tmp = z;
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -0.5)
		tmp = x * y;
	elseif (y <= -5.2e-206)
		tmp = x * 0.5;
	elseif (y <= 6.6e-267)
		tmp = z;
	elseif (y <= 7.2e-196)
		tmp = x * 0.5;
	elseif (y <= 1.5e+137)
		tmp = z;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y), $MachinePrecision], If[LessEqual[y, -5.2e-206], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6.6e-267], z, If[LessEqual[y, 7.2e-196], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.5e+137], z, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -5.2 \cdot 10^{-206}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 6.6 \cdot 10^{-267}:\\
\;\;\;\;z\\

\mathbf{elif}\;y \leq 7.2 \cdot 10^{-196}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq 1.5 \cdot 10^{+137}:\\
\;\;\;\;z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -0.5 or 1.5e137 < y

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+90.4%

        \[\leadsto x \cdot \color{blue}{\left(\left(0.5 + y\right) + \frac{z}{x}\right)} \]
    7. Simplified90.4%

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

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

    if -0.5 < y < -5.2000000000000001e-206 or 6.60000000000000007e-267 < y < 7.2000000000000001e-196

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+89.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(0.5 + y\right) + \frac{z}{x}\right)} \]
    7. Simplified89.8%

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

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

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

    if -5.2000000000000001e-206 < y < 6.60000000000000007e-267 or 7.2000000000000001e-196 < y < 1.5e137

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 64.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.5:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{-206}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-267}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-196}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+137}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 73.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-73} \lor \neg \left(x \leq 2.5 \cdot 10^{-184}\right) \land \left(x \leq 4.7 \cdot 10^{-145} \lor \neg \left(x \leq 3.5 \cdot 10^{-86}\right)\right):\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -2.7e-73)
         (and (not (<= x 2.5e-184)) (or (<= x 4.7e-145) (not (<= x 3.5e-86)))))
   (* x (+ y 0.5))
   z))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -2.7e-73) || (!(x <= 2.5e-184) && ((x <= 4.7e-145) || !(x <= 3.5e-86)))) {
		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 <= (-2.7d-73)) .or. (.not. (x <= 2.5d-184)) .and. (x <= 4.7d-145) .or. (.not. (x <= 3.5d-86))) 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 <= -2.7e-73) || (!(x <= 2.5e-184) && ((x <= 4.7e-145) || !(x <= 3.5e-86)))) {
		tmp = x * (y + 0.5);
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -2.7e-73) or (not (x <= 2.5e-184) and ((x <= 4.7e-145) or not (x <= 3.5e-86))):
		tmp = x * (y + 0.5)
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -2.7e-73) || (!(x <= 2.5e-184) && ((x <= 4.7e-145) || !(x <= 3.5e-86))))
		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 <= -2.7e-73) || (~((x <= 2.5e-184)) && ((x <= 4.7e-145) || ~((x <= 3.5e-86)))))
		tmp = x * (y + 0.5);
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-73], And[N[Not[LessEqual[x, 2.5e-184]], $MachinePrecision], Or[LessEqual[x, 4.7e-145], N[Not[LessEqual[x, 3.5e-86]], $MachinePrecision]]]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-73} \lor \neg \left(x \leq 2.5 \cdot 10^{-184}\right) \land \left(x \leq 4.7 \cdot 10^{-145} \lor \neg \left(x \leq 3.5 \cdot 10^{-86}\right)\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 < -2.69999999999999994e-73 or 2.50000000000000001e-184 < x < 4.7000000000000002e-145 or 3.50000000000000021e-86 < x

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+98.8%

        \[\leadsto x \cdot \color{blue}{\left(\left(0.5 + y\right) + \frac{z}{x}\right)} \]
    7. Simplified98.8%

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

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

    if -2.69999999999999994e-73 < x < 2.50000000000000001e-184 or 4.7000000000000002e-145 < x < 3.50000000000000021e-86

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 79.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-73} \lor \neg \left(x \leq 2.5 \cdot 10^{-184}\right) \land \left(x \leq 4.7 \cdot 10^{-145} \lor \neg \left(x \leq 3.5 \cdot 10^{-86}\right)\right):\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{-11}:\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+60} \lor \neg \left(y \leq 1.12 \cdot 10^{+66}\right) \land y \leq 3.4 \cdot 10^{+136}:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.4e-11)
   (* x (+ y 0.5))
   (if (or (<= y 1.2e+60) (and (not (<= y 1.12e+66)) (<= y 3.4e+136)))
     (+ z (* x 0.5))
     (* x y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.4e-11) {
		tmp = x * (y + 0.5);
	} else if ((y <= 1.2e+60) || (!(y <= 1.12e+66) && (y <= 3.4e+136))) {
		tmp = z + (x * 0.5);
	} 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 <= (-1.4d-11)) then
        tmp = x * (y + 0.5d0)
    else if ((y <= 1.2d+60) .or. (.not. (y <= 1.12d+66)) .and. (y <= 3.4d+136)) then
        tmp = z + (x * 0.5d0)
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.4e-11) {
		tmp = x * (y + 0.5);
	} else if ((y <= 1.2e+60) || (!(y <= 1.12e+66) && (y <= 3.4e+136))) {
		tmp = z + (x * 0.5);
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.4e-11:
		tmp = x * (y + 0.5)
	elif (y <= 1.2e+60) or (not (y <= 1.12e+66) and (y <= 3.4e+136)):
		tmp = z + (x * 0.5)
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.4e-11)
		tmp = Float64(x * Float64(y + 0.5));
	elseif ((y <= 1.2e+60) || (!(y <= 1.12e+66) && (y <= 3.4e+136)))
		tmp = Float64(z + Float64(x * 0.5));
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.4e-11)
		tmp = x * (y + 0.5);
	elseif ((y <= 1.2e+60) || (~((y <= 1.12e+66)) && (y <= 3.4e+136)))
		tmp = z + (x * 0.5);
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.4e-11], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.2e+60], And[N[Not[LessEqual[y, 1.12e+66]], $MachinePrecision], LessEqual[y, 3.4e+136]]], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-11}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\

\mathbf{elif}\;y \leq 1.2 \cdot 10^{+60} \lor \neg \left(y \leq 1.12 \cdot 10^{+66}\right) \land y \leq 3.4 \cdot 10^{+136}:\\
\;\;\;\;z + x \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.4e-11

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+91.3%

        \[\leadsto x \cdot \color{blue}{\left(\left(0.5 + y\right) + \frac{z}{x}\right)} \]
    7. Simplified91.3%

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

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

    if -1.4e-11 < y < 1.2e60 or 1.12e66 < y < 3.39999999999999997e136

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 96.7%

      \[\leadsto \color{blue}{0.5 \cdot x} + z \]
    6. Step-by-step derivation
      1. *-commutative96.7%

        \[\leadsto \color{blue}{x \cdot 0.5} + z \]
    7. Simplified96.7%

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

    if 1.2e60 < y < 1.12e66 or 3.39999999999999997e136 < y

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+90.7%

        \[\leadsto x \cdot \color{blue}{\left(\left(0.5 + y\right) + \frac{z}{x}\right)} \]
    7. Simplified90.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{-11}:\\ \;\;\;\;x \cdot \left(y + 0.5\right)\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+60} \lor \neg \left(y \leq 1.12 \cdot 10^{+66}\right) \land y \leq 3.4 \cdot 10^{+136}:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 98.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -21:\\ \;\;\;\;z + x \cdot y\\ \mathbf{elif}\;y \leq 0.5:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + \frac{z}{y}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -21.0)
   (+ z (* x y))
   (if (<= y 0.5) (+ z (* x 0.5)) (* y (+ x (/ z y))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -21.0) {
		tmp = z + (x * y);
	} else if (y <= 0.5) {
		tmp = z + (x * 0.5);
	} else {
		tmp = y * (x + (z / 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 <= (-21.0d0)) then
        tmp = z + (x * y)
    else if (y <= 0.5d0) then
        tmp = z + (x * 0.5d0)
    else
        tmp = y * (x + (z / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -21.0) {
		tmp = z + (x * y);
	} else if (y <= 0.5) {
		tmp = z + (x * 0.5);
	} else {
		tmp = y * (x + (z / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -21.0:
		tmp = z + (x * y)
	elif y <= 0.5:
		tmp = z + (x * 0.5)
	else:
		tmp = y * (x + (z / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -21.0)
		tmp = Float64(z + Float64(x * y));
	elseif (y <= 0.5)
		tmp = Float64(z + Float64(x * 0.5));
	else
		tmp = Float64(y * Float64(x + Float64(z / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -21.0)
		tmp = z + (x * y);
	elseif (y <= 0.5)
		tmp = z + (x * 0.5);
	else
		tmp = y * (x + (z / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -21.0], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.5], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -21:\\
\;\;\;\;z + x \cdot y\\

\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;z + x \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -21

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

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

    if -21 < y < 0.5

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 98.3%

      \[\leadsto \color{blue}{0.5 \cdot x} + z \]
    6. Step-by-step derivation
      1. *-commutative98.3%

        \[\leadsto \color{blue}{x \cdot 0.5} + z \]
    7. Simplified98.3%

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

    if 0.5 < y

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot y} + z \]
    6. Taylor expanded in y around inf 99.6%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{z}{y}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -21:\\ \;\;\;\;z + x \cdot y\\ \mathbf{elif}\;y \leq 0.5:\\ \;\;\;\;z + x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + \frac{z}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -21 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -21.0) (not (<= y 0.5))) (+ z (* x y)) (+ z (* x 0.5))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -21.0) || !(y <= 0.5)) {
		tmp = z + (x * y);
	} else {
		tmp = z + (x * 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 ((y <= (-21.0d0)) .or. (.not. (y <= 0.5d0))) then
        tmp = z + (x * y)
    else
        tmp = z + (x * 0.5d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -21.0) || !(y <= 0.5)) {
		tmp = z + (x * y);
	} else {
		tmp = z + (x * 0.5);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -21.0) or not (y <= 0.5):
		tmp = z + (x * y)
	else:
		tmp = z + (x * 0.5)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -21.0) || !(y <= 0.5))
		tmp = Float64(z + Float64(x * y));
	else
		tmp = Float64(z + Float64(x * 0.5));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -21.0) || ~((y <= 0.5)))
		tmp = z + (x * y);
	else
		tmp = z + (x * 0.5);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -21.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

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

    if -21 < y < 0.5

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 98.3%

      \[\leadsto \color{blue}{0.5 \cdot x} + z \]
    6. Step-by-step derivation
      1. *-commutative98.3%

        \[\leadsto \color{blue}{x \cdot 0.5} + z \]
    7. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -21 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z + x \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 49.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.9 \cdot 10^{-111}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-170}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -5.9e-111) z (if (<= z 2.8e-170) (* x 0.5) z)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -5.9e-111) {
		tmp = z;
	} else if (z <= 2.8e-170) {
		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 <= (-5.9d-111)) then
        tmp = z
    else if (z <= 2.8d-170) 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 <= -5.9e-111) {
		tmp = z;
	} else if (z <= 2.8e-170) {
		tmp = x * 0.5;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -5.9e-111:
		tmp = z
	elif z <= 2.8e-170:
		tmp = x * 0.5
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -5.9e-111)
		tmp = z;
	elseif (z <= 2.8e-170)
		tmp = Float64(x * 0.5);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -5.9e-111)
		tmp = z;
	elseif (z <= 2.8e-170)
		tmp = x * 0.5;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -5.9e-111], z, If[LessEqual[z, 2.8e-170], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq 2.8 \cdot 10^{-170}:\\
\;\;\;\;x \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.9000000000000001e-111 or 2.79999999999999995e-170 < z

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 57.3%

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

    if -5.9000000000000001e-111 < z < 2.79999999999999995e-170

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
      5. neg-mul-1100.0%

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

        \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
      7. associate-/l*100.0%

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

        \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
      10. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{x \cdot \left(0.5 + \left(y + \frac{z}{x}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-+r+100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.9 \cdot 10^{-111}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-170}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 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. +-commutative100.0%

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

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

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

      \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
    5. neg-mul-1100.0%

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

      \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
    7. associate-/l*100.0%

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

      \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
    9. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
    10. metadata-eval100.0%

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

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

    \[\leadsto z + x \cdot \left(y - -0.5\right) \]
  6. Add Preprocessing

Alternative 9: 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. +-commutative100.0%

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

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

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

      \[\leadsto \color{blue}{\left(y \cdot x - \frac{-x}{2}\right)} + z \]
    5. neg-mul-1100.0%

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

      \[\leadsto \left(y \cdot x - \frac{\color{blue}{x \cdot -1}}{2}\right) + z \]
    7. associate-/l*100.0%

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

      \[\leadsto \left(y \cdot x - \color{blue}{\frac{-1}{2} \cdot x}\right) + z \]
    9. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{x \cdot \left(y - \frac{-1}{2}\right)} + z \]
    10. metadata-eval100.0%

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

    \[\leadsto \color{blue}{x \cdot \left(y - -0.5\right) + z} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 42.9%

    \[\leadsto \color{blue}{z} \]
  6. Final simplification42.9%

    \[\leadsto z \]
  7. Add Preprocessing

Reproduce

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