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

Percentage Accurate: 99.8% → 99.8%
Time: 4.0s
Alternatives: 7
Speedup: N/A×

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: 99.8% accurate, 1.2× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
    4. *-lft-identity100.0%

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

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

      \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
    7. associate-/r/99.8%

      \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
    8. fma-neg99.8%

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

      \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
    10. /-rgt-identity99.8%

      \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
    11. associate-/r/99.8%

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
  4. Step-by-step derivation
    1. fma-udef99.8%

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

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

    \[\leadsto \color{blue}{\frac{4}{z} \cdot \left(x - y\right) + -2} \]
  6. Final simplification99.8%

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

Alternative 2: 51.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 \cdot \frac{y}{z}\\ t_1 := \frac{4 \cdot x}{z}\\ \mathbf{if}\;z \leq -8200000000:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-305}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-122}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+140}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* -4.0 (/ y z))) (t_1 (/ (* 4.0 x) z)))
   (if (<= z -8200000000.0)
     -2.0
     (if (<= z -1.2e-144)
       t_1
       (if (<= z -5.5e-305)
         t_0
         (if (<= z 4.3e-172)
           t_1
           (if (<= z 8.8e-122)
             t_0
             (if (<= z 4.2e-15)
               t_1
               (if (<= z 8.5e+61) t_0 (if (<= z 2.2e+140) t_1 -2.0))))))))))
double code(double x, double y, double z) {
	double t_0 = -4.0 * (y / z);
	double t_1 = (4.0 * x) / z;
	double tmp;
	if (z <= -8200000000.0) {
		tmp = -2.0;
	} else if (z <= -1.2e-144) {
		tmp = t_1;
	} else if (z <= -5.5e-305) {
		tmp = t_0;
	} else if (z <= 4.3e-172) {
		tmp = t_1;
	} else if (z <= 8.8e-122) {
		tmp = t_0;
	} else if (z <= 4.2e-15) {
		tmp = t_1;
	} else if (z <= 8.5e+61) {
		tmp = t_0;
	} else if (z <= 2.2e+140) {
		tmp = t_1;
	} 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-4.0d0) * (y / z)
    t_1 = (4.0d0 * x) / z
    if (z <= (-8200000000.0d0)) then
        tmp = -2.0d0
    else if (z <= (-1.2d-144)) then
        tmp = t_1
    else if (z <= (-5.5d-305)) then
        tmp = t_0
    else if (z <= 4.3d-172) then
        tmp = t_1
    else if (z <= 8.8d-122) then
        tmp = t_0
    else if (z <= 4.2d-15) then
        tmp = t_1
    else if (z <= 8.5d+61) then
        tmp = t_0
    else if (z <= 2.2d+140) then
        tmp = t_1
    else
        tmp = -2.0d0
    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 = (4.0 * x) / z;
	double tmp;
	if (z <= -8200000000.0) {
		tmp = -2.0;
	} else if (z <= -1.2e-144) {
		tmp = t_1;
	} else if (z <= -5.5e-305) {
		tmp = t_0;
	} else if (z <= 4.3e-172) {
		tmp = t_1;
	} else if (z <= 8.8e-122) {
		tmp = t_0;
	} else if (z <= 4.2e-15) {
		tmp = t_1;
	} else if (z <= 8.5e+61) {
		tmp = t_0;
	} else if (z <= 2.2e+140) {
		tmp = t_1;
	} else {
		tmp = -2.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -4.0 * (y / z)
	t_1 = (4.0 * x) / z
	tmp = 0
	if z <= -8200000000.0:
		tmp = -2.0
	elif z <= -1.2e-144:
		tmp = t_1
	elif z <= -5.5e-305:
		tmp = t_0
	elif z <= 4.3e-172:
		tmp = t_1
	elif z <= 8.8e-122:
		tmp = t_0
	elif z <= 4.2e-15:
		tmp = t_1
	elif z <= 8.5e+61:
		tmp = t_0
	elif z <= 2.2e+140:
		tmp = t_1
	else:
		tmp = -2.0
	return tmp
function code(x, y, z)
	t_0 = Float64(-4.0 * Float64(y / z))
	t_1 = Float64(Float64(4.0 * x) / z)
	tmp = 0.0
	if (z <= -8200000000.0)
		tmp = -2.0;
	elseif (z <= -1.2e-144)
		tmp = t_1;
	elseif (z <= -5.5e-305)
		tmp = t_0;
	elseif (z <= 4.3e-172)
		tmp = t_1;
	elseif (z <= 8.8e-122)
		tmp = t_0;
	elseif (z <= 4.2e-15)
		tmp = t_1;
	elseif (z <= 8.5e+61)
		tmp = t_0;
	elseif (z <= 2.2e+140)
		tmp = t_1;
	else
		tmp = -2.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = -4.0 * (y / z);
	t_1 = (4.0 * x) / z;
	tmp = 0.0;
	if (z <= -8200000000.0)
		tmp = -2.0;
	elseif (z <= -1.2e-144)
		tmp = t_1;
	elseif (z <= -5.5e-305)
		tmp = t_0;
	elseif (z <= 4.3e-172)
		tmp = t_1;
	elseif (z <= 8.8e-122)
		tmp = t_0;
	elseif (z <= 4.2e-15)
		tmp = t_1;
	elseif (z <= 8.5e+61)
		tmp = t_0;
	elseif (z <= 2.2e+140)
		tmp = t_1;
	else
		tmp = -2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * x), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[z, -8200000000.0], -2.0, If[LessEqual[z, -1.2e-144], t$95$1, If[LessEqual[z, -5.5e-305], t$95$0, If[LessEqual[z, 4.3e-172], t$95$1, If[LessEqual[z, 8.8e-122], t$95$0, If[LessEqual[z, 4.2e-15], t$95$1, If[LessEqual[z, 8.5e+61], t$95$0, If[LessEqual[z, 2.2e+140], t$95$1, -2.0]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 \cdot \frac{y}{z}\\
t_1 := \frac{4 \cdot x}{z}\\
\mathbf{if}\;z \leq -8200000000:\\
\;\;\;\;-2\\

\mathbf{elif}\;z \leq -1.2 \cdot 10^{-144}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -5.5 \cdot 10^{-305}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.3 \cdot 10^{-172}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 8.8 \cdot 10^{-122}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.2 \cdot 10^{-15}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 8.5 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 2.2 \cdot 10^{+140}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -8.2e9 or 2.1999999999999998e140 < z

    1. Initial program 98.9%

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

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

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

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

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

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

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

    if -8.2e9 < z < -1.19999999999999997e-144 or -5.5e-305 < z < 4.2999999999999997e-172 or 8.8e-122 < z < 4.19999999999999962e-15 or 8.50000000000000035e61 < z < 2.1999999999999998e140

    1. Initial program 100.0%

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

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

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

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

    if -1.19999999999999997e-144 < z < -5.5e-305 or 4.2999999999999997e-172 < z < 8.8e-122 or 4.19999999999999962e-15 < z < 8.50000000000000035e61

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8200000000:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-144}:\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-305}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-172}:\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-122}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-15}:\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{+61}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+140}:\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]

Alternative 3: 79.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+91} \lor \neg \left(x \leq 6.6 \cdot 10^{+61} \lor \neg \left(x \leq 3 \cdot 10^{+84}\right) \land x \leq 6.8 \cdot 10^{+196}\right):\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -4.6e+91)
         (not (or (<= x 6.6e+61) (and (not (<= x 3e+84)) (<= x 6.8e+196)))))
   (/ (* 4.0 x) z)
   (- (* -4.0 (/ y z)) 2.0)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.6e+91) || !((x <= 6.6e+61) || (!(x <= 3e+84) && (x <= 6.8e+196)))) {
		tmp = (4.0 * x) / z;
	} else {
		tmp = (-4.0 * (y / z)) - 2.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-4.6d+91)) .or. (.not. (x <= 6.6d+61) .or. (.not. (x <= 3d+84)) .and. (x <= 6.8d+196))) then
        tmp = (4.0d0 * x) / z
    else
        tmp = ((-4.0d0) * (y / z)) - 2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.6e+91) || !((x <= 6.6e+61) || (!(x <= 3e+84) && (x <= 6.8e+196)))) {
		tmp = (4.0 * x) / z;
	} else {
		tmp = (-4.0 * (y / z)) - 2.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -4.6e+91) or not ((x <= 6.6e+61) or (not (x <= 3e+84) and (x <= 6.8e+196))):
		tmp = (4.0 * x) / z
	else:
		tmp = (-4.0 * (y / z)) - 2.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -4.6e+91) || !((x <= 6.6e+61) || (!(x <= 3e+84) && (x <= 6.8e+196))))
		tmp = Float64(Float64(4.0 * x) / z);
	else
		tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -4.6e+91) || ~(((x <= 6.6e+61) || (~((x <= 3e+84)) && (x <= 6.8e+196)))))
		tmp = (4.0 * x) / z;
	else
		tmp = (-4.0 * (y / z)) - 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e+91], N[Not[Or[LessEqual[x, 6.6e+61], And[N[Not[LessEqual[x, 3e+84]], $MachinePrecision], LessEqual[x, 6.8e+196]]]], $MachinePrecision]], N[(N[(4.0 * x), $MachinePrecision] / z), $MachinePrecision], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{+91} \lor \neg \left(x \leq 6.6 \cdot 10^{+61} \lor \neg \left(x \leq 3 \cdot 10^{+84}\right) \land x \leq 6.8 \cdot 10^{+196}\right):\\
\;\;\;\;\frac{4 \cdot x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.59999999999999982e91 or 6.5999999999999995e61 < x < 2.99999999999999996e84 or 6.8e196 < x

    1. Initial program 100.0%

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

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

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

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

    if -4.59999999999999982e91 < x < 6.5999999999999995e61 or 2.99999999999999996e84 < x < 6.8e196

    1. Initial program 99.4%

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

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
      4. *-lft-identity100.0%

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

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

        \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      7. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      8. fma-neg99.9%

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

        \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      10. /-rgt-identity99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      11. associate-/r/99.9%

        \[\leadsto \mathsf{fma}\left(x - y, \frac{4}{z}, -\color{blue}{\frac{z \cdot 0.5}{z} \cdot 4}\right) \]
      12. distribute-rgt-neg-in99.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    4. Taylor expanded in x around 0 87.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+91} \lor \neg \left(x \leq 6.6 \cdot 10^{+61} \lor \neg \left(x \leq 3 \cdot 10^{+84}\right) \land x \leq 6.8 \cdot 10^{+196}\right):\\ \;\;\;\;\frac{4 \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \end{array} \]

Alternative 4: 86.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{+87} \lor \neg \left(x \leq 1.05 \cdot 10^{+34}\right):\\
\;\;\;\;4 \cdot \frac{x}{z} - 2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.40000000000000005e87 or 1.05000000000000009e34 < 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. *-commutative100.0%

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
      4. *-lft-identity100.0%

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

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

        \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      7. associate-/r/99.7%

        \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      8. fma-neg99.7%

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

        \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      10. /-rgt-identity99.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      11. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    4. Taylor expanded in y around 0 87.6%

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

    if -7.40000000000000005e87 < x < 1.05000000000000009e34

    1. Initial program 99.3%

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

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
      4. *-lft-identity100.0%

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

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

        \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      7. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      8. fma-neg99.9%

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

        \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      10. /-rgt-identity99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      11. associate-/r/99.9%

        \[\leadsto \mathsf{fma}\left(x - y, \frac{4}{z}, -\color{blue}{\frac{z \cdot 0.5}{z} \cdot 4}\right) \]
      12. distribute-rgt-neg-in99.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    4. Taylor expanded in x around 0 89.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{+87} \lor \neg \left(x \leq 1.05 \cdot 10^{+34}\right):\\ \;\;\;\;4 \cdot \frac{x}{z} - 2\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \end{array} \]

Alternative 5: 86.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{+67}:\\ \;\;\;\;\frac{4 \cdot \left(x - y\right)}{z}\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+33}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z} - 2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -8.6e+67)
   (/ (* 4.0 (- x y)) z)
   (if (<= x 2.6e+33) (- (* -4.0 (/ y z)) 2.0) (- (* 4.0 (/ x z)) 2.0))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -8.6e+67) {
		tmp = (4.0 * (x - y)) / z;
	} else if (x <= 2.6e+33) {
		tmp = (-4.0 * (y / z)) - 2.0;
	} else {
		tmp = (4.0 * (x / z)) - 2.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-8.6d+67)) then
        tmp = (4.0d0 * (x - y)) / z
    else if (x <= 2.6d+33) then
        tmp = ((-4.0d0) * (y / z)) - 2.0d0
    else
        tmp = (4.0d0 * (x / z)) - 2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -8.6e+67) {
		tmp = (4.0 * (x - y)) / z;
	} else if (x <= 2.6e+33) {
		tmp = (-4.0 * (y / z)) - 2.0;
	} else {
		tmp = (4.0 * (x / z)) - 2.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -8.6e+67:
		tmp = (4.0 * (x - y)) / z
	elif x <= 2.6e+33:
		tmp = (-4.0 * (y / z)) - 2.0
	else:
		tmp = (4.0 * (x / z)) - 2.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -8.6e+67)
		tmp = Float64(Float64(4.0 * Float64(x - y)) / z);
	elseif (x <= 2.6e+33)
		tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0);
	else
		tmp = Float64(Float64(4.0 * Float64(x / z)) - 2.0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -8.6e+67)
		tmp = (4.0 * (x - y)) / z;
	elseif (x <= 2.6e+33)
		tmp = (-4.0 * (y / z)) - 2.0;
	else
		tmp = (4.0 * (x / z)) - 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -8.6e+67], N[(N[(4.0 * N[(x - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[x, 2.6e+33], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 2.6 \cdot 10^{+33}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.6000000000000002e67

    1. Initial program 100.0%

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

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

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

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

    if -8.6000000000000002e67 < x < 2.5999999999999997e33

    1. Initial program 99.3%

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

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
      4. *-lft-identity100.0%

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

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

        \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      7. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      8. fma-neg99.9%

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

        \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      10. /-rgt-identity99.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      11. associate-/r/99.9%

        \[\leadsto \mathsf{fma}\left(x - y, \frac{4}{z}, -\color{blue}{\frac{z \cdot 0.5}{z} \cdot 4}\right) \]
      12. distribute-rgt-neg-in99.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    4. Taylor expanded in x around 0 89.9%

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

    if 2.5999999999999997e33 < x

    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. *-commutative99.9%

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

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

        \[\leadsto \color{blue}{\frac{x - y}{\frac{z}{4}} - \frac{z \cdot 0.5}{\frac{z}{4}}} \]
      4. *-lft-identity100.0%

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

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

        \[\leadsto \frac{x - y}{\color{blue}{\frac{--1}{\frac{4}{z}}}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      7. associate-/r/99.7%

        \[\leadsto \color{blue}{\frac{x - y}{--1} \cdot \frac{4}{z}} - \frac{z \cdot 0.5}{\frac{z}{4}} \]
      8. fma-neg99.7%

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

        \[\leadsto \mathsf{fma}\left(\frac{x - y}{\color{blue}{1}}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      10. /-rgt-identity99.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, \frac{4}{z}, -\frac{z \cdot 0.5}{\frac{z}{4}}\right) \]
      11. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    4. Taylor expanded in y around 0 85.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{+67}:\\ \;\;\;\;\frac{4 \cdot \left(x - y\right)}{z}\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+33}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z} - 2\\ \end{array} \]

Alternative 6: 53.7% accurate, 1.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.4999999999999995e37 or 3.40000000000000006e59 < z

    1. Initial program 99.0%

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

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

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

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

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

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

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

    if -9.4999999999999995e37 < z < 3.40000000000000006e59

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{+37}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+59}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]

Alternative 7: 33.2% 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 99.6%

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

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

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

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

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

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

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

    \[\leadsto -2 \]

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

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

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