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

Percentage Accurate: 99.8% → 100.0%
Time: 5.7s
Alternatives: 9
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 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: 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 \left(\frac{y - x}{z} - -0.5\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* -4.0 (- (/ (- y x) z) -0.5)))
double code(double x, double y, double z) {
	return -4.0 * (((y - x) / z) - -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 = (-4.0d0) * (((y - x) / z) - (-0.5d0))
end function
public static double code(double x, double y, double z) {
	return -4.0 * (((y - x) / z) - -0.5);
}
def code(x, y, z):
	return -4.0 * (((y - x) / z) - -0.5)
function code(x, y, z)
	return Float64(-4.0 * Float64(Float64(Float64(y - x) / z) - -0.5))
end
function tmp = code(x, y, z)
	tmp = -4.0 * (((y - x) / z) - -0.5);
end
code[x_, y_, z_] := N[(-4.0 * N[(N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-4 \cdot \left(\frac{y - x}{z} - -0.5\right)
\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. remove-double-neg100.0%

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

      \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
    3. times-frac100.0%

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

      \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
    5. div-sub100.0%

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

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

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

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

      \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
    10. distribute-neg-out100.0%

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

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

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

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
    14. neg-mul-1100.0%

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
    15. times-frac100.0%

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

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
    17. *-inverses100.0%

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

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

    \[\leadsto \color{blue}{-4 \cdot \left(\frac{y - x}{z} - -0.5\right)} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 52.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-4 \cdot y}{z}\\ t_1 := \frac{x \cdot 4}{z}\\ \mathbf{if}\;x \leq -1.16 \cdot 10^{+91}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-47}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-158}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-287}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* -4.0 y) z)) (t_1 (/ (* x 4.0) z)))
   (if (<= x -1.16e+91)
     t_1
     (if (<= x -7e-47)
       -2.0
       (if (<= x -1.7e-158)
         t_0
         (if (<= x 8.5e-287) -2.0 (if (<= x 1.08e+124) t_0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = (-4.0 * y) / z;
	double t_1 = (x * 4.0) / z;
	double tmp;
	if (x <= -1.16e+91) {
		tmp = t_1;
	} else if (x <= -7e-47) {
		tmp = -2.0;
	} else if (x <= -1.7e-158) {
		tmp = t_0;
	} else if (x <= 8.5e-287) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) * y) / z
    t_1 = (x * 4.0d0) / z
    if (x <= (-1.16d+91)) then
        tmp = t_1
    else if (x <= (-7d-47)) then
        tmp = -2.0d0
    else if (x <= (-1.7d-158)) then
        tmp = t_0
    else if (x <= 8.5d-287) then
        tmp = -2.0d0
    else if (x <= 1.08d+124) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (-4.0 * y) / z;
	double t_1 = (x * 4.0) / z;
	double tmp;
	if (x <= -1.16e+91) {
		tmp = t_1;
	} else if (x <= -7e-47) {
		tmp = -2.0;
	} else if (x <= -1.7e-158) {
		tmp = t_0;
	} else if (x <= 8.5e-287) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (-4.0 * y) / z
	t_1 = (x * 4.0) / z
	tmp = 0
	if x <= -1.16e+91:
		tmp = t_1
	elif x <= -7e-47:
		tmp = -2.0
	elif x <= -1.7e-158:
		tmp = t_0
	elif x <= 8.5e-287:
		tmp = -2.0
	elif x <= 1.08e+124:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(-4.0 * y) / z)
	t_1 = Float64(Float64(x * 4.0) / z)
	tmp = 0.0
	if (x <= -1.16e+91)
		tmp = t_1;
	elseif (x <= -7e-47)
		tmp = -2.0;
	elseif (x <= -1.7e-158)
		tmp = t_0;
	elseif (x <= 8.5e-287)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (-4.0 * y) / z;
	t_1 = (x * 4.0) / z;
	tmp = 0.0;
	if (x <= -1.16e+91)
		tmp = t_1;
	elseif (x <= -7e-47)
		tmp = -2.0;
	elseif (x <= -1.7e-158)
		tmp = t_0;
	elseif (x <= 8.5e-287)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-4.0 * y), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * 4.0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[x, -1.16e+91], t$95$1, If[LessEqual[x, -7e-47], -2.0, If[LessEqual[x, -1.7e-158], t$95$0, If[LessEqual[x, 8.5e-287], -2.0, If[LessEqual[x, 1.08e+124], t$95$0, t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -7 \cdot 10^{-47}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq -1.7 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 8.5 \cdot 10^{-287}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.1600000000000001e91 or 1.08000000000000005e124 < 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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot x}{z}} \]
      2. *-commutative79.1%

        \[\leadsto \frac{\color{blue}{x \cdot 4}}{z} \]
    7. Simplified79.1%

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

    if -1.1600000000000001e91 < x < -6.9999999999999996e-47 or -1.7e-158 < x < 8.5000000000000003e-287

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    if -6.9999999999999996e-47 < x < -1.7e-158 or 8.5000000000000003e-287 < x < 1.08000000000000005e124

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 57.9%

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

        \[\leadsto \frac{\color{blue}{y \cdot -4}}{z} \]
    5. Simplified57.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.16 \cdot 10^{+91}:\\ \;\;\;\;\frac{x \cdot 4}{z}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-47}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-158}:\\ \;\;\;\;\frac{-4 \cdot y}{z}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-287}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\ \;\;\;\;\frac{-4 \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 4}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 52.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \frac{-4}{z}\\ t_1 := \frac{x \cdot 4}{z}\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{+90}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-44}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-155}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-287}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (/ -4.0 z))) (t_1 (/ (* x 4.0) z)))
   (if (<= x -8.5e+90)
     t_1
     (if (<= x -6.5e-44)
       -2.0
       (if (<= x -1.5e-155)
         t_0
         (if (<= x 2.1e-287) -2.0 (if (<= x 1.08e+124) t_0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = y * (-4.0 / z);
	double t_1 = (x * 4.0) / z;
	double tmp;
	if (x <= -8.5e+90) {
		tmp = t_1;
	} else if (x <= -6.5e-44) {
		tmp = -2.0;
	} else if (x <= -1.5e-155) {
		tmp = t_0;
	} else if (x <= 2.1e-287) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 = y * ((-4.0d0) / z)
    t_1 = (x * 4.0d0) / z
    if (x <= (-8.5d+90)) then
        tmp = t_1
    else if (x <= (-6.5d-44)) then
        tmp = -2.0d0
    else if (x <= (-1.5d-155)) then
        tmp = t_0
    else if (x <= 2.1d-287) then
        tmp = -2.0d0
    else if (x <= 1.08d+124) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (-4.0 / z);
	double t_1 = (x * 4.0) / z;
	double tmp;
	if (x <= -8.5e+90) {
		tmp = t_1;
	} else if (x <= -6.5e-44) {
		tmp = -2.0;
	} else if (x <= -1.5e-155) {
		tmp = t_0;
	} else if (x <= 2.1e-287) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (-4.0 / z)
	t_1 = (x * 4.0) / z
	tmp = 0
	if x <= -8.5e+90:
		tmp = t_1
	elif x <= -6.5e-44:
		tmp = -2.0
	elif x <= -1.5e-155:
		tmp = t_0
	elif x <= 2.1e-287:
		tmp = -2.0
	elif x <= 1.08e+124:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(-4.0 / z))
	t_1 = Float64(Float64(x * 4.0) / z)
	tmp = 0.0
	if (x <= -8.5e+90)
		tmp = t_1;
	elseif (x <= -6.5e-44)
		tmp = -2.0;
	elseif (x <= -1.5e-155)
		tmp = t_0;
	elseif (x <= 2.1e-287)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (-4.0 / z);
	t_1 = (x * 4.0) / z;
	tmp = 0.0;
	if (x <= -8.5e+90)
		tmp = t_1;
	elseif (x <= -6.5e-44)
		tmp = -2.0;
	elseif (x <= -1.5e-155)
		tmp = t_0;
	elseif (x <= 2.1e-287)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * 4.0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[x, -8.5e+90], t$95$1, If[LessEqual[x, -6.5e-44], -2.0, If[LessEqual[x, -1.5e-155], t$95$0, If[LessEqual[x, 2.1e-287], -2.0, If[LessEqual[x, 1.08e+124], t$95$0, t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -6.5 \cdot 10^{-44}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq -1.5 \cdot 10^{-155}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 2.1 \cdot 10^{-287}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.5000000000000002e90 or 1.08000000000000005e124 < 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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot x}{z}} \]
      2. *-commutative79.1%

        \[\leadsto \frac{\color{blue}{x \cdot 4}}{z} \]
    7. Simplified79.1%

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

    if -8.5000000000000002e90 < x < -6.5e-44 or -1.49999999999999992e-155 < x < 2.0999999999999999e-287

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    if -6.5e-44 < x < -1.49999999999999992e-155 or 2.0999999999999999e-287 < x < 1.08000000000000005e124

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{-4 \cdot y}{z}} \]
      2. *-commutative57.9%

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

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

      \[\leadsto \color{blue}{y \cdot \frac{-4}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 52.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \frac{-4}{z}\\ t_1 := \frac{4}{\frac{z}{x}}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+91}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-46}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-158}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-286}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (/ -4.0 z))) (t_1 (/ 4.0 (/ z x))))
   (if (<= x -1e+91)
     t_1
     (if (<= x -1.6e-46)
       -2.0
       (if (<= x -5.8e-158)
         t_0
         (if (<= x 1.75e-286) -2.0 (if (<= x 1.08e+124) t_0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = y * (-4.0 / z);
	double t_1 = 4.0 / (z / x);
	double tmp;
	if (x <= -1e+91) {
		tmp = t_1;
	} else if (x <= -1.6e-46) {
		tmp = -2.0;
	} else if (x <= -5.8e-158) {
		tmp = t_0;
	} else if (x <= 1.75e-286) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 = y * ((-4.0d0) / z)
    t_1 = 4.0d0 / (z / x)
    if (x <= (-1d+91)) then
        tmp = t_1
    else if (x <= (-1.6d-46)) then
        tmp = -2.0d0
    else if (x <= (-5.8d-158)) then
        tmp = t_0
    else if (x <= 1.75d-286) then
        tmp = -2.0d0
    else if (x <= 1.08d+124) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (-4.0 / z);
	double t_1 = 4.0 / (z / x);
	double tmp;
	if (x <= -1e+91) {
		tmp = t_1;
	} else if (x <= -1.6e-46) {
		tmp = -2.0;
	} else if (x <= -5.8e-158) {
		tmp = t_0;
	} else if (x <= 1.75e-286) {
		tmp = -2.0;
	} else if (x <= 1.08e+124) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (-4.0 / z)
	t_1 = 4.0 / (z / x)
	tmp = 0
	if x <= -1e+91:
		tmp = t_1
	elif x <= -1.6e-46:
		tmp = -2.0
	elif x <= -5.8e-158:
		tmp = t_0
	elif x <= 1.75e-286:
		tmp = -2.0
	elif x <= 1.08e+124:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(-4.0 / z))
	t_1 = Float64(4.0 / Float64(z / x))
	tmp = 0.0
	if (x <= -1e+91)
		tmp = t_1;
	elseif (x <= -1.6e-46)
		tmp = -2.0;
	elseif (x <= -5.8e-158)
		tmp = t_0;
	elseif (x <= 1.75e-286)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (-4.0 / z);
	t_1 = 4.0 / (z / x);
	tmp = 0.0;
	if (x <= -1e+91)
		tmp = t_1;
	elseif (x <= -1.6e-46)
		tmp = -2.0;
	elseif (x <= -5.8e-158)
		tmp = t_0;
	elseif (x <= 1.75e-286)
		tmp = -2.0;
	elseif (x <= 1.08e+124)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(4.0 / N[(z / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+91], t$95$1, If[LessEqual[x, -1.6e-46], -2.0, If[LessEqual[x, -5.8e-158], t$95$0, If[LessEqual[x, 1.75e-286], -2.0, If[LessEqual[x, 1.08e+124], t$95$0, t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1.6 \cdot 10^{-46}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq -5.8 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;x \leq 1.08 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.00000000000000008e91 or 1.08000000000000005e124 < 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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot x}{z}} \]
      2. *-commutative79.1%

        \[\leadsto \frac{\color{blue}{x \cdot 4}}{z} \]
    7. Simplified79.1%

      \[\leadsto \color{blue}{\frac{x \cdot 4}{z}} \]
    8. Step-by-step derivation
      1. clear-num79.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot 4}}} \]
      2. inv-pow79.0%

        \[\leadsto \color{blue}{{\left(\frac{z}{x \cdot 4}\right)}^{-1}} \]
      3. *-un-lft-identity79.0%

        \[\leadsto {\left(\frac{\color{blue}{1 \cdot z}}{x \cdot 4}\right)}^{-1} \]
      4. *-commutative79.0%

        \[\leadsto {\left(\frac{1 \cdot z}{\color{blue}{4 \cdot x}}\right)}^{-1} \]
      5. times-frac79.0%

        \[\leadsto {\color{blue}{\left(\frac{1}{4} \cdot \frac{z}{x}\right)}}^{-1} \]
      6. metadata-eval79.0%

        \[\leadsto {\left(\color{blue}{0.25} \cdot \frac{z}{x}\right)}^{-1} \]
    9. Applied egg-rr79.0%

      \[\leadsto \color{blue}{{\left(0.25 \cdot \frac{z}{x}\right)}^{-1}} \]
    10. Step-by-step derivation
      1. unpow-179.0%

        \[\leadsto \color{blue}{\frac{1}{0.25 \cdot \frac{z}{x}}} \]
      2. associate-/r*79.0%

        \[\leadsto \color{blue}{\frac{\frac{1}{0.25}}{\frac{z}{x}}} \]
      3. metadata-eval79.0%

        \[\leadsto \frac{\color{blue}{4}}{\frac{z}{x}} \]
    11. Simplified79.0%

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

    if -1.00000000000000008e91 < x < -1.6e-46 or -5.79999999999999961e-158 < x < 1.74999999999999994e-286

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    if -1.6e-46 < x < -5.79999999999999961e-158 or 1.74999999999999994e-286 < x < 1.08000000000000005e124

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{-4 \cdot y}{z}} \]
      2. *-commutative57.9%

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

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

      \[\leadsto \color{blue}{y \cdot \frac{-4}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 85.7% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+76} \lor \neg \left(y \leq 1.3 \cdot 10^{-6}\right):\\
\;\;\;\;-2 + -4 \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.2e76 or 1.30000000000000005e-6 < y

    1. Initial program 99.9%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. remove-double-neg99.9%

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-\left(-z\right)}} \]
      2. neg-mul-199.9%

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac99.9%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

      \[\leadsto \color{blue}{-4 \cdot \left(0.5 + \frac{y}{z}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-in82.6%

        \[\leadsto \color{blue}{0.5 \cdot -4 + \frac{y}{z} \cdot -4} \]
      2. metadata-eval82.6%

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

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

    if -1.2e76 < y < 1.30000000000000005e-6

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{+76} \lor \neg \left(y \leq 1.3 \cdot 10^{-6}\right):\\ \;\;\;\;-2 + -4 \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \left(0.5 - \frac{x}{z}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 80.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+105} \lor \neg \left(y \leq 6.2 \cdot 10^{+66}\right):\\
\;\;\;\;\frac{-4 \cdot y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.3999999999999999e105 or 6.20000000000000037e66 < y

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 69.9%

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

        \[\leadsto \frac{\color{blue}{y \cdot -4}}{z} \]
    5. Simplified69.9%

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

    if -3.3999999999999999e105 < y < 6.20000000000000037e66

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+105} \lor \neg \left(y \leq 6.2 \cdot 10^{+66}\right):\\ \;\;\;\;\frac{-4 \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \left(0.5 - \frac{x}{z}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 84.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-82}:\\
\;\;\;\;\frac{4 \cdot \left(x - y\right)}{z}\\

\mathbf{elif}\;y \leq 0.135:\\
\;\;\;\;-4 \cdot \left(0.5 - \frac{x}{z}\right)\\

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


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

    1. Initial program 100.0%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0 81.4%

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

    if -5.9999999999999998e-82 < y < 0.13500000000000001

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    if 0.13500000000000001 < y

    1. Initial program 99.9%

      \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
    2. Step-by-step derivation
      1. remove-double-neg99.9%

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-\left(-z\right)}} \]
      2. neg-mul-199.9%

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac99.9%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

      \[\leadsto \color{blue}{-4 \cdot \left(0.5 + \frac{y}{z}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-in86.3%

        \[\leadsto \color{blue}{0.5 \cdot -4 + \frac{y}{z} \cdot -4} \]
      2. metadata-eval86.3%

        \[\leadsto \color{blue}{-2} + \frac{y}{z} \cdot -4 \]
    7. Simplified86.3%

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

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

Alternative 8: 53.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.8 \cdot 10^{+110}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+72}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.8e+110) -2.0 (if (<= z 1.45e+72) (* y (/ -4.0 z)) -2.0)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.8e+110) {
		tmp = -2.0;
	} else if (z <= 1.45e+72) {
		tmp = y * (-4.0 / 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 (z <= (-2.8d+110)) then
        tmp = -2.0d0
    else if (z <= 1.45d+72) then
        tmp = y * ((-4.0d0) / z)
    else
        tmp = -2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.8e+110) {
		tmp = -2.0;
	} else if (z <= 1.45e+72) {
		tmp = y * (-4.0 / z);
	} else {
		tmp = -2.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -2.8e+110:
		tmp = -2.0
	elif z <= 1.45e+72:
		tmp = y * (-4.0 / z)
	else:
		tmp = -2.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -2.8e+110)
		tmp = -2.0;
	elseif (z <= 1.45e+72)
		tmp = Float64(y * Float64(-4.0 / z));
	else
		tmp = -2.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -2.8e+110)
		tmp = -2.0;
	elseif (z <= 1.45e+72)
		tmp = y * (-4.0 / z);
	else
		tmp = -2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -2.8e+110], -2.0, If[LessEqual[z, 1.45e+72], N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision], -2.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+110}:\\
\;\;\;\;-2\\

\mathbf{elif}\;z \leq 1.45 \cdot 10^{+72}:\\
\;\;\;\;y \cdot \frac{-4}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.79999999999999987e110 or 1.45000000000000009e72 < z

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

    if -2.79999999999999987e110 < z < 1.45000000000000009e72

    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. remove-double-neg100.0%

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

        \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
      3. times-frac100.0%

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

        \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
      5. div-sub100.0%

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

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

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

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

        \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
      10. distribute-neg-out100.0%

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

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

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
      14. neg-mul-1100.0%

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
      15. times-frac100.0%

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

        \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
      17. *-inverses100.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \frac{-4}{z}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 33.5% 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. remove-double-neg100.0%

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

      \[\leadsto \frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{\color{blue}{-1 \cdot \left(-z\right)}} \]
    3. times-frac100.0%

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

      \[\leadsto \color{blue}{-4} \cdot \frac{\left(x - y\right) - z \cdot 0.5}{-z} \]
    5. div-sub100.0%

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

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

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

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

      \[\leadsto -4 \cdot \left(\frac{-\color{blue}{\left(\left(-y\right) + x\right)}}{z} - \frac{z \cdot 0.5}{-z}\right) \]
    10. distribute-neg-out100.0%

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

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

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

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{\color{blue}{0.5 \cdot z}}{-z}\right) \]
    14. neg-mul-1100.0%

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \frac{0.5 \cdot z}{\color{blue}{-1 \cdot z}}\right) \]
    15. times-frac100.0%

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

      \[\leadsto -4 \cdot \left(\frac{y - x}{z} - \color{blue}{-0.5} \cdot \frac{z}{z}\right) \]
    17. *-inverses100.0%

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

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

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

    \[\leadsto \color{blue}{-2} \]
  6. Add Preprocessing

Developer target: 97.9% 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 2024110 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
  :precision binary64

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

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