Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B

Percentage Accurate: 99.8% → 100.0%
Time: 5.6s
Alternatives: 8
Speedup: 1.2×

Specification

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

\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\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: 99.8% accurate, 1.0× speedup?

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

\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}

Alternative 1: 100.0% accurate, 1.2× speedup?

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

\\
4 \cdot \frac{x - y}{z} - 2
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/99.7%

      \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
    2. sub-neg99.7%

      \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
    3. distribute-rgt-neg-in99.7%

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

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

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

    \[\leadsto \color{blue}{4 \cdot \frac{x - y}{z} - 2} \]
  5. Final simplification100.0%

    \[\leadsto 4 \cdot \frac{x - y}{z} - 2 \]

Alternative 2: 54.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := y \cdot \frac{-4}{z}\\ \mathbf{if}\;x \leq -1.26 \cdot 10^{+74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-156}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-286}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-178}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.18 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-75}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x z))) (t_1 (* y (/ -4.0 z))))
   (if (<= x -1.26e+74)
     t_0
     (if (<= x -9e+42)
       t_1
       (if (<= x -2.4e-156)
         -2.0
         (if (<= x -1.55e-188)
           t_1
           (if (<= x 1.1e-286)
             -2.0
             (if (<= x 1.2e-242)
               t_1
               (if (<= x 1.3e-178)
                 -2.0
                 (if (<= x 1.18e-145)
                   t_1
                   (if (<= x 4.1e-75)
                     -2.0
                     (if (<= x 2.4e+64) t_1 t_0))))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = y * (-4.0 / z);
	double tmp;
	if (x <= -1.26e+74) {
		tmp = t_0;
	} else if (x <= -9e+42) {
		tmp = t_1;
	} else if (x <= -2.4e-156) {
		tmp = -2.0;
	} else if (x <= -1.55e-188) {
		tmp = t_1;
	} else if (x <= 1.1e-286) {
		tmp = -2.0;
	} else if (x <= 1.2e-242) {
		tmp = t_1;
	} else if (x <= 1.3e-178) {
		tmp = -2.0;
	} else if (x <= 1.18e-145) {
		tmp = t_1;
	} else if (x <= 4.1e-75) {
		tmp = -2.0;
	} else if (x <= 2.4e+64) {
		tmp = t_1;
	} else {
		tmp = t_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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / z)
    t_1 = y * ((-4.0d0) / z)
    if (x <= (-1.26d+74)) then
        tmp = t_0
    else if (x <= (-9d+42)) then
        tmp = t_1
    else if (x <= (-2.4d-156)) then
        tmp = -2.0d0
    else if (x <= (-1.55d-188)) then
        tmp = t_1
    else if (x <= 1.1d-286) then
        tmp = -2.0d0
    else if (x <= 1.2d-242) then
        tmp = t_1
    else if (x <= 1.3d-178) then
        tmp = -2.0d0
    else if (x <= 1.18d-145) then
        tmp = t_1
    else if (x <= 4.1d-75) then
        tmp = -2.0d0
    else if (x <= 2.4d+64) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = y * (-4.0 / z);
	double tmp;
	if (x <= -1.26e+74) {
		tmp = t_0;
	} else if (x <= -9e+42) {
		tmp = t_1;
	} else if (x <= -2.4e-156) {
		tmp = -2.0;
	} else if (x <= -1.55e-188) {
		tmp = t_1;
	} else if (x <= 1.1e-286) {
		tmp = -2.0;
	} else if (x <= 1.2e-242) {
		tmp = t_1;
	} else if (x <= 1.3e-178) {
		tmp = -2.0;
	} else if (x <= 1.18e-145) {
		tmp = t_1;
	} else if (x <= 4.1e-75) {
		tmp = -2.0;
	} else if (x <= 2.4e+64) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / z)
	t_1 = y * (-4.0 / z)
	tmp = 0
	if x <= -1.26e+74:
		tmp = t_0
	elif x <= -9e+42:
		tmp = t_1
	elif x <= -2.4e-156:
		tmp = -2.0
	elif x <= -1.55e-188:
		tmp = t_1
	elif x <= 1.1e-286:
		tmp = -2.0
	elif x <= 1.2e-242:
		tmp = t_1
	elif x <= 1.3e-178:
		tmp = -2.0
	elif x <= 1.18e-145:
		tmp = t_1
	elif x <= 4.1e-75:
		tmp = -2.0
	elif x <= 2.4e+64:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / z))
	t_1 = Float64(y * Float64(-4.0 / z))
	tmp = 0.0
	if (x <= -1.26e+74)
		tmp = t_0;
	elseif (x <= -9e+42)
		tmp = t_1;
	elseif (x <= -2.4e-156)
		tmp = -2.0;
	elseif (x <= -1.55e-188)
		tmp = t_1;
	elseif (x <= 1.1e-286)
		tmp = -2.0;
	elseif (x <= 1.2e-242)
		tmp = t_1;
	elseif (x <= 1.3e-178)
		tmp = -2.0;
	elseif (x <= 1.18e-145)
		tmp = t_1;
	elseif (x <= 4.1e-75)
		tmp = -2.0;
	elseif (x <= 2.4e+64)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / z);
	t_1 = y * (-4.0 / z);
	tmp = 0.0;
	if (x <= -1.26e+74)
		tmp = t_0;
	elseif (x <= -9e+42)
		tmp = t_1;
	elseif (x <= -2.4e-156)
		tmp = -2.0;
	elseif (x <= -1.55e-188)
		tmp = t_1;
	elseif (x <= 1.1e-286)
		tmp = -2.0;
	elseif (x <= 1.2e-242)
		tmp = t_1;
	elseif (x <= 1.3e-178)
		tmp = -2.0;
	elseif (x <= 1.18e-145)
		tmp = t_1;
	elseif (x <= 4.1e-75)
		tmp = -2.0;
	elseif (x <= 2.4e+64)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.26e+74], t$95$0, If[LessEqual[x, -9e+42], t$95$1, If[LessEqual[x, -2.4e-156], -2.0, If[LessEqual[x, -1.55e-188], t$95$1, If[LessEqual[x, 1.1e-286], -2.0, If[LessEqual[x, 1.2e-242], t$95$1, If[LessEqual[x, 1.3e-178], -2.0, If[LessEqual[x, 1.18e-145], t$95$1, If[LessEqual[x, 4.1e-75], -2.0, If[LessEqual[x, 2.4e+64], t$95$1, t$95$0]]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
t_1 := y \cdot \frac{-4}{z}\\
\mathbf{if}\;x \leq -1.26 \cdot 10^{+74}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -9 \cdot 10^{+42}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -2.4 \cdot 10^{-156}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq -1.55 \cdot 10^{-188}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.1 \cdot 10^{-286}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.2 \cdot 10^{-242}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.3 \cdot 10^{-178}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.18 \cdot 10^{-145}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 4.1 \cdot 10^{-75}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 2.4 \cdot 10^{+64}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.26000000000000008e74 or 2.39999999999999999e64 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{z}} \]

    if -1.26000000000000008e74 < x < -9.00000000000000025e42 or -2.4e-156 < x < -1.5500000000000001e-188 or 1.1e-286 < x < 1.2e-242 or 1.29999999999999999e-178 < x < 1.18000000000000006e-145 or 4.10000000000000002e-75 < x < 2.39999999999999999e64

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

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

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

      \[\leadsto \frac{4}{\color{blue}{-1 \cdot \frac{z}{y}}} \]
    5. Step-by-step derivation
      1. associate-*r/75.6%

        \[\leadsto \frac{4}{\color{blue}{\frac{-1 \cdot z}{y}}} \]
      2. neg-mul-175.6%

        \[\leadsto \frac{4}{\frac{\color{blue}{-z}}{y}} \]
    6. Simplified75.6%

      \[\leadsto \frac{4}{\color{blue}{\frac{-z}{y}}} \]
    7. Step-by-step derivation
      1. frac-2neg75.6%

        \[\leadsto \color{blue}{\frac{-4}{-\frac{-z}{y}}} \]
      2. frac-2neg75.6%

        \[\leadsto \color{blue}{\frac{-\left(-4\right)}{-\left(-\frac{-z}{y}\right)}} \]
      3. metadata-eval75.6%

        \[\leadsto \frac{-\color{blue}{-4}}{-\left(-\frac{-z}{y}\right)} \]
      4. metadata-eval75.6%

        \[\leadsto \frac{\color{blue}{4}}{-\left(-\frac{-z}{y}\right)} \]
      5. distribute-frac-neg75.6%

        \[\leadsto \frac{4}{-\left(-\color{blue}{\left(-\frac{z}{y}\right)}\right)} \]
      6. remove-double-neg75.6%

        \[\leadsto \frac{4}{-\color{blue}{\frac{z}{y}}} \]
      7. frac-2neg75.6%

        \[\leadsto \frac{4}{-\color{blue}{\frac{-z}{-y}}} \]
      8. distribute-frac-neg75.6%

        \[\leadsto \frac{4}{\color{blue}{\frac{-\left(-z\right)}{-y}}} \]
      9. remove-double-neg75.6%

        \[\leadsto \frac{4}{\frac{\color{blue}{z}}{-y}} \]
      10. associate-/r/75.6%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(-y\right)} \]
    8. Applied egg-rr75.6%

      \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(-y\right)} \]
    9. Taylor expanded in z around 0 75.9%

      \[\leadsto \color{blue}{-4 \cdot \frac{y}{z}} \]
    10. Step-by-step derivation
      1. associate-*r/75.9%

        \[\leadsto \color{blue}{\frac{-4 \cdot y}{z}} \]
      2. associate-*l/75.6%

        \[\leadsto \color{blue}{\frac{-4}{z} \cdot y} \]
    11. Simplified75.6%

      \[\leadsto \color{blue}{\frac{-4}{z} \cdot y} \]

    if -9.00000000000000025e42 < x < -2.4e-156 or -1.5500000000000001e-188 < x < 1.1e-286 or 1.2e-242 < x < 1.29999999999999999e-178 or 1.18000000000000006e-145 < x < 4.10000000000000002e-75

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.6%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.6%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + \color{blue}{z \cdot \left(-0.5\right)}\right) \]
      4. metadata-eval99.6%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot \color{blue}{-0.5}\right) \]
    3. Simplified99.6%

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

      \[\leadsto \color{blue}{-2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.26 \cdot 10^{+74}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \mathbf{elif}\;x \leq -9 \cdot 10^{+42}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-156}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-188}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-286}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-242}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-178}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.18 \cdot 10^{-145}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-75}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+64}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \end{array} \]

Alternative 3: 54.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := \frac{y \cdot -4}{z}\\ \mathbf{if}\;x \leq -1.7 \cdot 10^{+74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-156}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-185}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-286}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-179}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-144}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-75}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.36 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x z))) (t_1 (/ (* y -4.0) z)))
   (if (<= x -1.7e+74)
     t_0
     (if (<= x -2.1e+41)
       t_1
       (if (<= x -1.5e-156)
         -2.0
         (if (<= x -1.15e-185)
           t_1
           (if (<= x 1.15e-286)
             -2.0
             (if (<= x 2e-242)
               t_1
               (if (<= x 9e-179)
                 -2.0
                 (if (<= x 7e-144)
                   (* y (/ -4.0 z))
                   (if (<= x 2.3e-75)
                     -2.0
                     (if (<= x 1.36e+65) t_1 t_0))))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = (y * -4.0) / z;
	double tmp;
	if (x <= -1.7e+74) {
		tmp = t_0;
	} else if (x <= -2.1e+41) {
		tmp = t_1;
	} else if (x <= -1.5e-156) {
		tmp = -2.0;
	} else if (x <= -1.15e-185) {
		tmp = t_1;
	} else if (x <= 1.15e-286) {
		tmp = -2.0;
	} else if (x <= 2e-242) {
		tmp = t_1;
	} else if (x <= 9e-179) {
		tmp = -2.0;
	} else if (x <= 7e-144) {
		tmp = y * (-4.0 / z);
	} else if (x <= 2.3e-75) {
		tmp = -2.0;
	} else if (x <= 1.36e+65) {
		tmp = t_1;
	} else {
		tmp = t_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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / z)
    t_1 = (y * (-4.0d0)) / z
    if (x <= (-1.7d+74)) then
        tmp = t_0
    else if (x <= (-2.1d+41)) then
        tmp = t_1
    else if (x <= (-1.5d-156)) then
        tmp = -2.0d0
    else if (x <= (-1.15d-185)) then
        tmp = t_1
    else if (x <= 1.15d-286) then
        tmp = -2.0d0
    else if (x <= 2d-242) then
        tmp = t_1
    else if (x <= 9d-179) then
        tmp = -2.0d0
    else if (x <= 7d-144) then
        tmp = y * ((-4.0d0) / z)
    else if (x <= 2.3d-75) then
        tmp = -2.0d0
    else if (x <= 1.36d+65) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = (y * -4.0) / z;
	double tmp;
	if (x <= -1.7e+74) {
		tmp = t_0;
	} else if (x <= -2.1e+41) {
		tmp = t_1;
	} else if (x <= -1.5e-156) {
		tmp = -2.0;
	} else if (x <= -1.15e-185) {
		tmp = t_1;
	} else if (x <= 1.15e-286) {
		tmp = -2.0;
	} else if (x <= 2e-242) {
		tmp = t_1;
	} else if (x <= 9e-179) {
		tmp = -2.0;
	} else if (x <= 7e-144) {
		tmp = y * (-4.0 / z);
	} else if (x <= 2.3e-75) {
		tmp = -2.0;
	} else if (x <= 1.36e+65) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / z)
	t_1 = (y * -4.0) / z
	tmp = 0
	if x <= -1.7e+74:
		tmp = t_0
	elif x <= -2.1e+41:
		tmp = t_1
	elif x <= -1.5e-156:
		tmp = -2.0
	elif x <= -1.15e-185:
		tmp = t_1
	elif x <= 1.15e-286:
		tmp = -2.0
	elif x <= 2e-242:
		tmp = t_1
	elif x <= 9e-179:
		tmp = -2.0
	elif x <= 7e-144:
		tmp = y * (-4.0 / z)
	elif x <= 2.3e-75:
		tmp = -2.0
	elif x <= 1.36e+65:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / z))
	t_1 = Float64(Float64(y * -4.0) / z)
	tmp = 0.0
	if (x <= -1.7e+74)
		tmp = t_0;
	elseif (x <= -2.1e+41)
		tmp = t_1;
	elseif (x <= -1.5e-156)
		tmp = -2.0;
	elseif (x <= -1.15e-185)
		tmp = t_1;
	elseif (x <= 1.15e-286)
		tmp = -2.0;
	elseif (x <= 2e-242)
		tmp = t_1;
	elseif (x <= 9e-179)
		tmp = -2.0;
	elseif (x <= 7e-144)
		tmp = Float64(y * Float64(-4.0 / z));
	elseif (x <= 2.3e-75)
		tmp = -2.0;
	elseif (x <= 1.36e+65)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / z);
	t_1 = (y * -4.0) / z;
	tmp = 0.0;
	if (x <= -1.7e+74)
		tmp = t_0;
	elseif (x <= -2.1e+41)
		tmp = t_1;
	elseif (x <= -1.5e-156)
		tmp = -2.0;
	elseif (x <= -1.15e-185)
		tmp = t_1;
	elseif (x <= 1.15e-286)
		tmp = -2.0;
	elseif (x <= 2e-242)
		tmp = t_1;
	elseif (x <= 9e-179)
		tmp = -2.0;
	elseif (x <= 7e-144)
		tmp = y * (-4.0 / z);
	elseif (x <= 2.3e-75)
		tmp = -2.0;
	elseif (x <= 1.36e+65)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y * -4.0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[x, -1.7e+74], t$95$0, If[LessEqual[x, -2.1e+41], t$95$1, If[LessEqual[x, -1.5e-156], -2.0, If[LessEqual[x, -1.15e-185], t$95$1, If[LessEqual[x, 1.15e-286], -2.0, If[LessEqual[x, 2e-242], t$95$1, If[LessEqual[x, 9e-179], -2.0, If[LessEqual[x, 7e-144], N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.3e-75], -2.0, If[LessEqual[x, 1.36e+65], t$95$1, t$95$0]]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
t_1 := \frac{y \cdot -4}{z}\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+74}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -2.1 \cdot 10^{+41}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -1.5 \cdot 10^{-156}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq -1.15 \cdot 10^{-185}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.15 \cdot 10^{-286}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 2 \cdot 10^{-242}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 9 \cdot 10^{-179}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-144}:\\
\;\;\;\;y \cdot \frac{-4}{z}\\

\mathbf{elif}\;x \leq 2.3 \cdot 10^{-75}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.36 \cdot 10^{+65}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -1.7e74 or 1.3600000000000001e65 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{z}} \]

    if -1.7e74 < x < -2.1e41 or -1.5e-156 < x < -1.15e-185 or 1.1500000000000001e-286 < x < 2e-242 or 2.3e-75 < x < 1.3600000000000001e65

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{-4 \cdot \frac{y}{z}} \]
    5. Step-by-step derivation
      1. *-commutative73.7%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot -4} \]
      2. associate-*l/73.7%

        \[\leadsto \color{blue}{\frac{y \cdot -4}{z}} \]
    6. Simplified73.7%

      \[\leadsto \color{blue}{\frac{y \cdot -4}{z}} \]

    if -2.1e41 < x < -1.5e-156 or -1.15e-185 < x < 1.1500000000000001e-286 or 2e-242 < x < 8.99999999999999984e-179 or 6.9999999999999997e-144 < x < 2.3e-75

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.6%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.6%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + \color{blue}{z \cdot \left(-0.5\right)}\right) \]
      4. metadata-eval99.6%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot \color{blue}{-0.5}\right) \]
    3. Simplified99.6%

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

      \[\leadsto \color{blue}{-2} \]

    if 8.99999999999999984e-179 < x < 6.9999999999999997e-144

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{4}{\frac{z}{\left(x - y\right) - z \cdot 0.5}}} \]
    3. Simplified99.8%

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

      \[\leadsto \frac{4}{\color{blue}{-1 \cdot \frac{z}{y}}} \]
    5. Step-by-step derivation
      1. associate-*r/89.0%

        \[\leadsto \frac{4}{\color{blue}{\frac{-1 \cdot z}{y}}} \]
      2. neg-mul-189.0%

        \[\leadsto \frac{4}{\frac{\color{blue}{-z}}{y}} \]
    6. Simplified89.0%

      \[\leadsto \frac{4}{\color{blue}{\frac{-z}{y}}} \]
    7. Step-by-step derivation
      1. frac-2neg89.0%

        \[\leadsto \color{blue}{\frac{-4}{-\frac{-z}{y}}} \]
      2. frac-2neg89.0%

        \[\leadsto \color{blue}{\frac{-\left(-4\right)}{-\left(-\frac{-z}{y}\right)}} \]
      3. metadata-eval89.0%

        \[\leadsto \frac{-\color{blue}{-4}}{-\left(-\frac{-z}{y}\right)} \]
      4. metadata-eval89.0%

        \[\leadsto \frac{\color{blue}{4}}{-\left(-\frac{-z}{y}\right)} \]
      5. distribute-frac-neg89.0%

        \[\leadsto \frac{4}{-\left(-\color{blue}{\left(-\frac{z}{y}\right)}\right)} \]
      6. remove-double-neg89.0%

        \[\leadsto \frac{4}{-\color{blue}{\frac{z}{y}}} \]
      7. frac-2neg89.0%

        \[\leadsto \frac{4}{-\color{blue}{\frac{-z}{-y}}} \]
      8. distribute-frac-neg89.0%

        \[\leadsto \frac{4}{\color{blue}{\frac{-\left(-z\right)}{-y}}} \]
      9. remove-double-neg89.0%

        \[\leadsto \frac{4}{\frac{\color{blue}{z}}{-y}} \]
      10. associate-/r/89.2%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(-y\right)} \]
    8. Applied egg-rr89.2%

      \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(-y\right)} \]
    9. Taylor expanded in z around 0 89.2%

      \[\leadsto \color{blue}{-4 \cdot \frac{y}{z}} \]
    10. Step-by-step derivation
      1. associate-*r/89.2%

        \[\leadsto \color{blue}{\frac{-4 \cdot y}{z}} \]
      2. associate-*l/89.2%

        \[\leadsto \color{blue}{\frac{-4}{z} \cdot y} \]
    11. Simplified89.2%

      \[\leadsto \color{blue}{\frac{-4}{z} \cdot y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification67.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+74}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+41}:\\ \;\;\;\;\frac{y \cdot -4}{z}\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-156}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-185}:\\ \;\;\;\;\frac{y \cdot -4}{z}\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-286}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-242}:\\ \;\;\;\;\frac{y \cdot -4}{z}\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-179}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-144}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-75}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.36 \cdot 10^{+65}:\\ \;\;\;\;\frac{y \cdot -4}{z}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \end{array} \]

Alternative 4: 84.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \left(-0.5 - \frac{y}{z}\right)\\ t_1 := 4 \cdot \frac{x}{z} + -2\\ \mathbf{if}\;x \leq -6.5 \cdot 10^{+76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+18}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (- -0.5 (/ y z)))) (t_1 (+ (* 4.0 (/ x z)) -2.0)))
   (if (<= x -6.5e+76)
     t_1
     (if (<= x -3e+15)
       t_0
       (if (<= x -5.6e-55)
         t_1
         (if (<= x 4.1e+18) t_0 (* 4.0 (/ (- x y) z))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (-0.5 - (y / z));
	double t_1 = (4.0 * (x / z)) + -2.0;
	double tmp;
	if (x <= -6.5e+76) {
		tmp = t_1;
	} else if (x <= -3e+15) {
		tmp = t_0;
	} else if (x <= -5.6e-55) {
		tmp = t_1;
	} else if (x <= 4.1e+18) {
		tmp = t_0;
	} else {
		tmp = 4.0 * ((x - y) / 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * ((-0.5d0) - (y / z))
    t_1 = (4.0d0 * (x / z)) + (-2.0d0)
    if (x <= (-6.5d+76)) then
        tmp = t_1
    else if (x <= (-3d+15)) then
        tmp = t_0
    else if (x <= (-5.6d-55)) then
        tmp = t_1
    else if (x <= 4.1d+18) then
        tmp = t_0
    else
        tmp = 4.0d0 * ((x - y) / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * (-0.5 - (y / z));
	double t_1 = (4.0 * (x / z)) + -2.0;
	double tmp;
	if (x <= -6.5e+76) {
		tmp = t_1;
	} else if (x <= -3e+15) {
		tmp = t_0;
	} else if (x <= -5.6e-55) {
		tmp = t_1;
	} else if (x <= 4.1e+18) {
		tmp = t_0;
	} else {
		tmp = 4.0 * ((x - y) / z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (-0.5 - (y / z))
	t_1 = (4.0 * (x / z)) + -2.0
	tmp = 0
	if x <= -6.5e+76:
		tmp = t_1
	elif x <= -3e+15:
		tmp = t_0
	elif x <= -5.6e-55:
		tmp = t_1
	elif x <= 4.1e+18:
		tmp = t_0
	else:
		tmp = 4.0 * ((x - y) / z)
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(-0.5 - Float64(y / z)))
	t_1 = Float64(Float64(4.0 * Float64(x / z)) + -2.0)
	tmp = 0.0
	if (x <= -6.5e+76)
		tmp = t_1;
	elseif (x <= -3e+15)
		tmp = t_0;
	elseif (x <= -5.6e-55)
		tmp = t_1;
	elseif (x <= 4.1e+18)
		tmp = t_0;
	else
		tmp = Float64(4.0 * Float64(Float64(x - y) / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (-0.5 - (y / z));
	t_1 = (4.0 * (x / z)) + -2.0;
	tmp = 0.0;
	if (x <= -6.5e+76)
		tmp = t_1;
	elseif (x <= -3e+15)
		tmp = t_0;
	elseif (x <= -5.6e-55)
		tmp = t_1;
	elseif (x <= 4.1e+18)
		tmp = t_0;
	else
		tmp = 4.0 * ((x - y) / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(-0.5 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]}, If[LessEqual[x, -6.5e+76], t$95$1, If[LessEqual[x, -3e+15], t$95$0, If[LessEqual[x, -5.6e-55], t$95$1, If[LessEqual[x, 4.1e+18], t$95$0, N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
t_1 := 4 \cdot \frac{x}{z} + -2\\
\mathbf{if}\;x \leq -6.5 \cdot 10^{+76}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -3 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -5.6 \cdot 10^{-55}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 4.1 \cdot 10^{+18}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.5000000000000005e76 or -3e15 < x < -5.59999999999999968e-55

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.8%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.8%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + \color{blue}{z \cdot \left(-0.5\right)}\right) \]
      4. metadata-eval99.8%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot \color{blue}{-0.5}\right) \]
    3. Simplified99.8%

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

      \[\leadsto \color{blue}{4 \cdot \frac{-0.5 \cdot z + x}{z}} \]
    5. Step-by-step derivation
      1. +-commutative95.9%

        \[\leadsto 4 \cdot \frac{\color{blue}{x + -0.5 \cdot z}}{z} \]
      2. metadata-eval95.9%

        \[\leadsto 4 \cdot \frac{x + \color{blue}{\left(-0.5\right)} \cdot z}{z} \]
      3. cancel-sign-sub-inv95.9%

        \[\leadsto 4 \cdot \frac{\color{blue}{x - 0.5 \cdot z}}{z} \]
      4. div-sub95.9%

        \[\leadsto 4 \cdot \color{blue}{\left(\frac{x}{z} - \frac{0.5 \cdot z}{z}\right)} \]
      5. associate-/l*95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} - \color{blue}{\frac{0.5}{\frac{z}{z}}}\right) \]
      6. *-lft-identity95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} - \frac{0.5}{\frac{\color{blue}{1 \cdot z}}{z}}\right) \]
      7. associate-*l/95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} - \frac{0.5}{\color{blue}{\frac{1}{z} \cdot z}}\right) \]
      8. lft-mult-inverse95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} - \frac{0.5}{\color{blue}{1}}\right) \]
      9. metadata-eval95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} - \color{blue}{0.5}\right) \]
      10. sub-neg95.9%

        \[\leadsto 4 \cdot \color{blue}{\left(\frac{x}{z} + \left(-0.5\right)\right)} \]
      11. metadata-eval95.9%

        \[\leadsto 4 \cdot \left(\frac{x}{z} + \color{blue}{-0.5}\right) \]
      12. distribute-lft-in95.9%

        \[\leadsto \color{blue}{4 \cdot \frac{x}{z} + 4 \cdot -0.5} \]
      13. metadata-eval95.9%

        \[\leadsto 4 \cdot \frac{x}{z} + \color{blue}{-2} \]
    6. Simplified95.9%

      \[\leadsto \color{blue}{4 \cdot \frac{x}{z} + -2} \]

    if -6.5000000000000005e76 < x < -3e15 or -5.59999999999999968e-55 < x < 4.1e18

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{-0.5 \cdot z - y}{z}} \]
    5. Step-by-step derivation
      1. div-sub97.6%

        \[\leadsto 4 \cdot \color{blue}{\left(\frac{-0.5 \cdot z}{z} - \frac{y}{z}\right)} \]
      2. associate-/l*97.6%

        \[\leadsto 4 \cdot \left(\color{blue}{\frac{-0.5}{\frac{z}{z}}} - \frac{y}{z}\right) \]
      3. *-lft-identity97.6%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\frac{\color{blue}{1 \cdot z}}{z}} - \frac{y}{z}\right) \]
      4. associate-*l/97.4%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{\frac{1}{z} \cdot z}} - \frac{y}{z}\right) \]
      5. lft-mult-inverse97.6%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{1}} - \frac{y}{z}\right) \]
      6. metadata-eval97.6%

        \[\leadsto 4 \cdot \left(\color{blue}{-0.5} - \frac{y}{z}\right) \]
    6. Simplified97.6%

      \[\leadsto \color{blue}{4 \cdot \left(-0.5 - \frac{y}{z}\right)} \]

    if 4.1e18 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - y}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification93.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+76}:\\ \;\;\;\;4 \cdot \frac{x}{z} + -2\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+15}:\\ \;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-55}:\\ \;\;\;\;4 \cdot \frac{x}{z} + -2\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+18}:\\ \;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \end{array} \]

Alternative 5: 80.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+88} \lor \neg \left(x \leq 1.3 \cdot 10^{+201}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.1000000000000001e88 or 1.29999999999999993e201 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.8%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.8%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + \color{blue}{z \cdot \left(-0.5\right)}\right) \]
      4. metadata-eval99.8%

        \[\leadsto \frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot \color{blue}{-0.5}\right) \]
    3. Simplified99.8%

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{z}} \]

    if -3.1000000000000001e88 < x < 1.29999999999999993e201

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{-0.5 \cdot z - y}{z}} \]
    5. Step-by-step derivation
      1. div-sub87.1%

        \[\leadsto 4 \cdot \color{blue}{\left(\frac{-0.5 \cdot z}{z} - \frac{y}{z}\right)} \]
      2. associate-/l*87.1%

        \[\leadsto 4 \cdot \left(\color{blue}{\frac{-0.5}{\frac{z}{z}}} - \frac{y}{z}\right) \]
      3. *-lft-identity87.1%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\frac{\color{blue}{1 \cdot z}}{z}} - \frac{y}{z}\right) \]
      4. associate-*l/86.9%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{\frac{1}{z} \cdot z}} - \frac{y}{z}\right) \]
      5. lft-mult-inverse87.1%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{1}} - \frac{y}{z}\right) \]
      6. metadata-eval87.1%

        \[\leadsto 4 \cdot \left(\color{blue}{-0.5} - \frac{y}{z}\right) \]
    6. Simplified87.1%

      \[\leadsto \color{blue}{4 \cdot \left(-0.5 - \frac{y}{z}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+88} \lor \neg \left(x \leq 1.3 \cdot 10^{+201}\right):\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\ \end{array} \]

Alternative 6: 86.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 1.26 \cdot 10^{+17}\right):\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.75e88 or 1.26e17 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - y}{z}} \]

    if -2.75e88 < x < 1.26e17

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{-0.5 \cdot z - y}{z}} \]
    5. Step-by-step derivation
      1. div-sub93.5%

        \[\leadsto 4 \cdot \color{blue}{\left(\frac{-0.5 \cdot z}{z} - \frac{y}{z}\right)} \]
      2. associate-/l*93.5%

        \[\leadsto 4 \cdot \left(\color{blue}{\frac{-0.5}{\frac{z}{z}}} - \frac{y}{z}\right) \]
      3. *-lft-identity93.5%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\frac{\color{blue}{1 \cdot z}}{z}} - \frac{y}{z}\right) \]
      4. associate-*l/93.3%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{\frac{1}{z} \cdot z}} - \frac{y}{z}\right) \]
      5. lft-mult-inverse93.5%

        \[\leadsto 4 \cdot \left(\frac{-0.5}{\color{blue}{1}} - \frac{y}{z}\right) \]
      6. metadata-eval93.5%

        \[\leadsto 4 \cdot \left(\color{blue}{-0.5} - \frac{y}{z}\right) \]
    6. Simplified93.5%

      \[\leadsto \color{blue}{4 \cdot \left(-0.5 - \frac{y}{z}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 1.26 \cdot 10^{+17}\right):\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\ \end{array} \]

Alternative 7: 54.4% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 2.8 \cdot 10^{+16}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;-2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.75e88 or 2.8e16 < x

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{z}} \]

    if -2.75e88 < x < 2.8e16

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
      2. sub-neg99.7%

        \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
      3. distribute-rgt-neg-in99.7%

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

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

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

      \[\leadsto \color{blue}{-2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification54.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 2.8 \cdot 10^{+16}\right):\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]

Alternative 8: 34.6% accurate, 11.0× speedup?

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

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

    \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/99.7%

      \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]
    2. sub-neg99.7%

      \[\leadsto \frac{4}{z} \cdot \color{blue}{\left(\left(x - y\right) + \left(-z \cdot 0.5\right)\right)} \]
    3. distribute-rgt-neg-in99.7%

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

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

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

    \[\leadsto \color{blue}{-2} \]
  5. Final simplification33.1%

    \[\leadsto -2 \]

Developer target: 97.7% accurate, 0.8× speedup?

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

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

Reproduce

?
herbie shell --seed 2023171 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
  :precision binary64

  :herbie-target
  (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))

  (/ (* 4.0 (- (- x y) (* z 0.5))) z))