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

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

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 2: 53.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := -4 \cdot \frac{y}{z}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.3 \cdot 10^{-169}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-262}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-212}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-158}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-95}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-31}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x z))) (t_1 (* -4.0 (/ y z))))
   (if (<= x -1e+14)
     t_0
     (if (<= x -2.3e-100)
       t_1
       (if (<= x -5.3e-169)
         -2.0
         (if (<= x 1.75e-262)
           t_1
           (if (<= x 3.9e-212)
             -2.0
             (if (<= x 1.75e-158)
               t_1
               (if (<= x 4e-95) -2.0 (if (<= x 3.4e-31) t_1 t_0))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = -4.0 * (y / z);
	double tmp;
	if (x <= -1e+14) {
		tmp = t_0;
	} else if (x <= -2.3e-100) {
		tmp = t_1;
	} else if (x <= -5.3e-169) {
		tmp = -2.0;
	} else if (x <= 1.75e-262) {
		tmp = t_1;
	} else if (x <= 3.9e-212) {
		tmp = -2.0;
	} else if (x <= 1.75e-158) {
		tmp = t_1;
	} else if (x <= 4e-95) {
		tmp = -2.0;
	} else if (x <= 3.4e-31) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / z)
    t_1 = (-4.0d0) * (y / z)
    if (x <= (-1d+14)) then
        tmp = t_0
    else if (x <= (-2.3d-100)) then
        tmp = t_1
    else if (x <= (-5.3d-169)) then
        tmp = -2.0d0
    else if (x <= 1.75d-262) then
        tmp = t_1
    else if (x <= 3.9d-212) then
        tmp = -2.0d0
    else if (x <= 1.75d-158) then
        tmp = t_1
    else if (x <= 4d-95) then
        tmp = -2.0d0
    else if (x <= 3.4d-31) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / z);
	double t_1 = -4.0 * (y / z);
	double tmp;
	if (x <= -1e+14) {
		tmp = t_0;
	} else if (x <= -2.3e-100) {
		tmp = t_1;
	} else if (x <= -5.3e-169) {
		tmp = -2.0;
	} else if (x <= 1.75e-262) {
		tmp = t_1;
	} else if (x <= 3.9e-212) {
		tmp = -2.0;
	} else if (x <= 1.75e-158) {
		tmp = t_1;
	} else if (x <= 4e-95) {
		tmp = -2.0;
	} else if (x <= 3.4e-31) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / z)
	t_1 = -4.0 * (y / z)
	tmp = 0
	if x <= -1e+14:
		tmp = t_0
	elif x <= -2.3e-100:
		tmp = t_1
	elif x <= -5.3e-169:
		tmp = -2.0
	elif x <= 1.75e-262:
		tmp = t_1
	elif x <= 3.9e-212:
		tmp = -2.0
	elif x <= 1.75e-158:
		tmp = t_1
	elif x <= 4e-95:
		tmp = -2.0
	elif x <= 3.4e-31:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / z))
	t_1 = Float64(-4.0 * Float64(y / z))
	tmp = 0.0
	if (x <= -1e+14)
		tmp = t_0;
	elseif (x <= -2.3e-100)
		tmp = t_1;
	elseif (x <= -5.3e-169)
		tmp = -2.0;
	elseif (x <= 1.75e-262)
		tmp = t_1;
	elseif (x <= 3.9e-212)
		tmp = -2.0;
	elseif (x <= 1.75e-158)
		tmp = t_1;
	elseif (x <= 4e-95)
		tmp = -2.0;
	elseif (x <= 3.4e-31)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / z);
	t_1 = -4.0 * (y / z);
	tmp = 0.0;
	if (x <= -1e+14)
		tmp = t_0;
	elseif (x <= -2.3e-100)
		tmp = t_1;
	elseif (x <= -5.3e-169)
		tmp = -2.0;
	elseif (x <= 1.75e-262)
		tmp = t_1;
	elseif (x <= 3.9e-212)
		tmp = -2.0;
	elseif (x <= 1.75e-158)
		tmp = t_1;
	elseif (x <= 4e-95)
		tmp = -2.0;
	elseif (x <= 3.4e-31)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+14], t$95$0, If[LessEqual[x, -2.3e-100], t$95$1, If[LessEqual[x, -5.3e-169], -2.0, If[LessEqual[x, 1.75e-262], t$95$1, If[LessEqual[x, 3.9e-212], -2.0, If[LessEqual[x, 1.75e-158], t$95$1, If[LessEqual[x, 4e-95], -2.0, If[LessEqual[x, 3.4e-31], t$95$1, t$95$0]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -2.3 \cdot 10^{-100}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -5.3 \cdot 10^{-169}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.75 \cdot 10^{-262}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 3.9 \cdot 10^{-212}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 1.75 \cdot 10^{-158}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 4 \cdot 10^{-95}:\\
\;\;\;\;-2\\

\mathbf{elif}\;x \leq 3.4 \cdot 10^{-31}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1e14 or 3.4000000000000001e-31 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1e14 < x < -2.29999999999999994e-100 or -5.3e-169 < x < 1.75000000000000006e-262 or 3.9e-212 < x < 1.75000000000000006e-158 or 3.99999999999999996e-95 < x < 3.4000000000000001e-31

    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. associate-*l/99.8%

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

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

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

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

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

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

    if -2.29999999999999994e-100 < x < -5.3e-169 or 1.75000000000000006e-262 < x < 3.9e-212 or 1.75000000000000006e-158 < x < 3.99999999999999996e-95

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+14}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-100}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;x \leq -5.3 \cdot 10^{-169}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-262}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-212}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-158}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-95}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-31}:\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z}\\ \end{array} \]

Alternative 3: 85.2% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.0000000000000004e65 or 2.2e16 < 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. associate-*l/99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2} \cdot \frac{-z}{-z}\right) \]
      16. *-inverses100.0%

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2}\right) \]
    3. Simplified100.0%

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

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

    if -6.0000000000000004e65 < z < 2.2e16

    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. associate-*l/99.8%

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

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

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

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

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

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

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

Alternative 4: 79.6% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;z \leq 2.3 \cdot 10^{+170}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.3000000000000001e172 or 2.3000000000000001e170 < 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. associate-*l/99.8%

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

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

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

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

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

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

    if -2.3000000000000001e172 < z < 2.3000000000000001e170

    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. associate-*l/99.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.3 \cdot 10^{+172}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+170}:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]

Alternative 5: 84.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.0085:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-36}:\\ \;\;\;\;-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 -0.0085)
   (* 4.0 (/ (- x y) z))
   (if (<= x 4.2e-36) (- (* -4.0 (/ y z)) 2.0) (- (* 4.0 (/ x z)) 2.0))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -0.0085) {
		tmp = 4.0 * ((x - y) / z);
	} else if (x <= 4.2e-36) {
		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 <= (-0.0085d0)) then
        tmp = 4.0d0 * ((x - y) / z)
    else if (x <= 4.2d-36) 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 <= -0.0085) {
		tmp = 4.0 * ((x - y) / z);
	} else if (x <= 4.2e-36) {
		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 <= -0.0085:
		tmp = 4.0 * ((x - y) / z)
	elif x <= 4.2e-36:
		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 <= -0.0085)
		tmp = Float64(4.0 * Float64(Float64(x - y) / z));
	elseif (x <= 4.2e-36)
		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 <= -0.0085)
		tmp = 4.0 * ((x - y) / z);
	elseif (x <= 4.2e-36)
		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, -0.0085], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.2e-36], 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 -0.0085:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\

\mathbf{elif}\;x \leq 4.2 \cdot 10^{-36}:\\
\;\;\;\;-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 < -0.0085000000000000006

    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. associate-*l/99.7%

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

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

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

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

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

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

    if -0.0085000000000000006 < x < 4.19999999999999982e-36

    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. associate-*l/99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2} \cdot \frac{-z}{-z}\right) \]
      16. *-inverses100.0%

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2}\right) \]
    3. Simplified100.0%

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

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

    if 4.19999999999999982e-36 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2} \cdot \frac{-z}{-z}\right) \]
      16. *-inverses100.0%

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

        \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2}\right) \]
    3. Simplified100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0085:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-36}:\\ \;\;\;\;-4 \cdot \frac{y}{z} - 2\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{z} - 2\\ \end{array} \]

Alternative 6: 52.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-21} \lor \neg \left(y \leq 2.6 \cdot 10^{+77}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.99999999999999926e-21 or 2.6000000000000002e77 < 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. associate-*l/99.8%

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

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

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

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

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

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

    if -7.99999999999999926e-21 < y < 2.6000000000000002e77

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{-21} \lor \neg \left(y \leq 2.6 \cdot 10^{+77}\right):\\ \;\;\;\;-4 \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]

Alternative 7: 99.8% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2} \cdot \frac{-z}{-z}\right) \]
    16. *-inverses100.0%

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

      \[\leadsto \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2}\right) \]
  3. Simplified100.0%

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - y}{z} + -2} \]
    2. associate-*r/100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - y\right)}{z}} + -2 \]
    3. associate-*l/99.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 \left(x - y\right) \cdot \frac{4}{z} + -2 \]

Alternative 8: 34.1% accurate, 11.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-2} \]
  5. Final simplification30.4%

    \[\leadsto -2 \]

Developer target: 97.9% accurate, 0.8× speedup?

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

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

Reproduce

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