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

Percentage Accurate: 99.8% → 100.0%
Time: 7.0s
Alternatives: 7
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 7 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: 54.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 \cdot \frac{y}{z}\\ \mathbf{if}\;y \leq -17500000000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-88}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-28}:\\ \;\;\;\;\frac{x}{z} \cdot 4\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* -4.0 (/ y z))))
   (if (<= y -17500000000000.0)
     t_0
     (if (<= y -5.5e-88) -2.0 (if (<= y 1.5e-28) (* (/ x z) 4.0) t_0)))))
double code(double x, double y, double z) {
	double t_0 = -4.0 * (y / z);
	double tmp;
	if (y <= -17500000000000.0) {
		tmp = t_0;
	} else if (y <= -5.5e-88) {
		tmp = -2.0;
	} else if (y <= 1.5e-28) {
		tmp = (x / z) * 4.0;
	} 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) :: tmp
    t_0 = (-4.0d0) * (y / z)
    if (y <= (-17500000000000.0d0)) then
        tmp = t_0
    else if (y <= (-5.5d-88)) then
        tmp = -2.0d0
    else if (y <= 1.5d-28) then
        tmp = (x / z) * 4.0d0
    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 * (y / z);
	double tmp;
	if (y <= -17500000000000.0) {
		tmp = t_0;
	} else if (y <= -5.5e-88) {
		tmp = -2.0;
	} else if (y <= 1.5e-28) {
		tmp = (x / z) * 4.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -4.0 * (y / z)
	tmp = 0
	if y <= -17500000000000.0:
		tmp = t_0
	elif y <= -5.5e-88:
		tmp = -2.0
	elif y <= 1.5e-28:
		tmp = (x / z) * 4.0
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(-4.0 * Float64(y / z))
	tmp = 0.0
	if (y <= -17500000000000.0)
		tmp = t_0;
	elseif (y <= -5.5e-88)
		tmp = -2.0;
	elseif (y <= 1.5e-28)
		tmp = Float64(Float64(x / z) * 4.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = -4.0 * (y / z);
	tmp = 0.0;
	if (y <= -17500000000000.0)
		tmp = t_0;
	elseif (y <= -5.5e-88)
		tmp = -2.0;
	elseif (y <= 1.5e-28)
		tmp = (x / z) * 4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -17500000000000.0], t$95$0, If[LessEqual[y, -5.5e-88], -2.0, If[LessEqual[y, 1.5e-28], N[(N[(x / z), $MachinePrecision] * 4.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -17500000000000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -5.5 \cdot 10^{-88}:\\
\;\;\;\;-2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.75e13 or 1.50000000000000001e-28 < y

    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 66.9%

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

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

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

    if -1.75e13 < y < -5.49999999999999971e-88

    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 72.8%

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

    if -5.49999999999999971e-88 < y < 1.50000000000000001e-28

    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 56.1%

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

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot 4} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification63.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -17500000000000:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-88}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-28}:\\ \;\;\;\;\frac{x}{z} \cdot 4\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 54.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := y \cdot \frac{-4}{z}\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -5 \cdot 10^{-88}:\\
\;\;\;\;-2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.2e16 or 2.9500000000000001e-28 < y

    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. Step-by-step derivation
      1. div-sub97.6%

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

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

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

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

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

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

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

    if -5.2e16 < y < -5.00000000000000009e-88

    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 72.8%

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

    if -5.00000000000000009e-88 < y < 2.9500000000000001e-28

    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 56.1%

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

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

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

Alternative 4: 86.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+28} \lor \neg \left(y \leq 6.9 \cdot 10^{-28}\right):\\
\;\;\;\;-4 \cdot \left(\frac{y}{z} - -0.5\right)\\

\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.5e28 or 6.90000000000000001e-28 < y

    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 89.3%

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

    if -3.5e28 < y < 6.90000000000000001e-28

    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.6%

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

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

Alternative 5: 80.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{+96} \lor \neg \left(y \leq 3.6 \cdot 10^{+172}\right):\\ \;\;\;\;-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 -2.05e+96) (not (<= y 3.6e+172)))
   (* -4.0 (/ y z))
   (* -4.0 (- 0.5 (/ x z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.05e+96) || !(y <= 3.6e+172)) {
		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 <= (-2.05d+96)) .or. (.not. (y <= 3.6d+172))) 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 <= -2.05e+96) || !(y <= 3.6e+172)) {
		tmp = -4.0 * (y / z);
	} else {
		tmp = -4.0 * (0.5 - (x / z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -2.05e+96) or not (y <= 3.6e+172):
		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 <= -2.05e+96) || !(y <= 3.6e+172))
		tmp = 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 <= -2.05e+96) || ~((y <= 3.6e+172)))
		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, -2.05e+96], N[Not[LessEqual[y, 3.6e+172]], $MachinePrecision]], N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(0.5 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+96} \lor \neg \left(y \leq 3.6 \cdot 10^{+172}\right):\\
\;\;\;\;-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 < -2.04999999999999999e96 or 3.59999999999999975e172 < y

    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 88.2%

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

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

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

    if -2.04999999999999999e96 < y < 3.59999999999999975e172

    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 85.6%

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

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

Alternative 6: 54.6% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.09999999999999981e32 or 4.5e14 < 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 69.6%

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

    if -4.09999999999999981e32 < z < 4.5e14

    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. Step-by-step derivation
      1. div-sub97.9%

        \[\leadsto -4 \cdot \left(\color{blue}{\left(\frac{y}{z} - \frac{x}{z}\right)} - -0.5\right) \]
    6. Applied egg-rr97.9%

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

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

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

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

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

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

Alternative 7: 33.7% 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 36.0%

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

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

  :alt
  (! :herbie-platform default (- (* 4 (/ x z)) (+ 2 (* 4 (/ y z)))))

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