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

Percentage Accurate: 99.8% → 100.0%
Time: 7.8s
Alternatives: 8
Speedup: 1.4×

Specification

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

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

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

Alternative 1: 100.0% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 54.2% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{+108} \lor \neg \left(x \leq -1.8 \cdot 10^{+43}\right) \land \left(x \leq -0.0062 \lor \neg \left(x \leq 2.5 \cdot 10^{-13}\right)\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\

\mathbf{else}:\\
\;\;\;\;4\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.5000000000000002e108 or -1.80000000000000005e43 < x < -0.00619999999999999978 or 2.49999999999999995e-13 < x

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in x around inf 70.0%

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]

    if -3.5000000000000002e108 < x < -1.80000000000000005e43 or -0.00619999999999999978 < x < 2.49999999999999995e-13

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in y around inf 51.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{+108} \lor \neg \left(x \leq -1.8 \cdot 10^{+43}\right) \land \left(x \leq -0.0062 \lor \neg \left(x \leq 2.5 \cdot 10^{-13}\right)\right):\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 3: 57.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y} + 1\\ t_1 := 1 + z \cdot \frac{-4}{y}\\ \mathbf{if}\;z \leq -2.45 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-246}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-220}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (* 4.0 (/ x y)) 1.0)) (t_1 (+ 1.0 (* z (/ -4.0 y)))))
   (if (<= z -2.45e+25)
     t_1
     (if (<= z 6.2e-246)
       t_0
       (if (<= z 2.9e-220) 4.0 (if (<= z 4.6e+110) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + (z * (-4.0 / y));
	double tmp;
	if (z <= -2.45e+25) {
		tmp = t_1;
	} else if (z <= 6.2e-246) {
		tmp = t_0;
	} else if (z <= 2.9e-220) {
		tmp = 4.0;
	} else if (z <= 4.6e+110) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (4.0d0 * (x / y)) + 1.0d0
    t_1 = 1.0d0 + (z * ((-4.0d0) / y))
    if (z <= (-2.45d+25)) then
        tmp = t_1
    else if (z <= 6.2d-246) then
        tmp = t_0
    else if (z <= 2.9d-220) then
        tmp = 4.0d0
    else if (z <= 4.6d+110) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + (z * (-4.0 / y));
	double tmp;
	if (z <= -2.45e+25) {
		tmp = t_1;
	} else if (z <= 6.2e-246) {
		tmp = t_0;
	} else if (z <= 2.9e-220) {
		tmp = 4.0;
	} else if (z <= 4.6e+110) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (4.0 * (x / y)) + 1.0
	t_1 = 1.0 + (z * (-4.0 / y))
	tmp = 0
	if z <= -2.45e+25:
		tmp = t_1
	elif z <= 6.2e-246:
		tmp = t_0
	elif z <= 2.9e-220:
		tmp = 4.0
	elif z <= 4.6e+110:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(4.0 * Float64(x / y)) + 1.0)
	t_1 = Float64(1.0 + Float64(z * Float64(-4.0 / y)))
	tmp = 0.0
	if (z <= -2.45e+25)
		tmp = t_1;
	elseif (z <= 6.2e-246)
		tmp = t_0;
	elseif (z <= 2.9e-220)
		tmp = 4.0;
	elseif (z <= 4.6e+110)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (4.0 * (x / y)) + 1.0;
	t_1 = 1.0 + (z * (-4.0 / y));
	tmp = 0.0;
	if (z <= -2.45e+25)
		tmp = t_1;
	elseif (z <= 6.2e-246)
		tmp = t_0;
	elseif (z <= 2.9e-220)
		tmp = 4.0;
	elseif (z <= 4.6e+110)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.45e+25], t$95$1, If[LessEqual[z, 6.2e-246], t$95$0, If[LessEqual[z, 2.9e-220], 4.0, If[LessEqual[z, 4.6e+110], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq 6.2 \cdot 10^{-246}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 2.9 \cdot 10^{-220}:\\
\;\;\;\;4\\

\mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.45e25 or 4.6e110 < z

    1. Initial program 99.9%

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

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

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

      \[\leadsto 1 + \frac{4}{\color{blue}{\frac{y}{x - z}}} \]
    5. Taylor expanded in x around 0 72.3%

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

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

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

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

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

    if -2.45e25 < z < 6.2000000000000001e-246 or 2.8999999999999998e-220 < z < 4.6e110

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in x around inf 64.3%

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]

    if 6.2000000000000001e-246 < z < 2.8999999999999998e-220

    1. Initial program 99.5%

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.75 + x\right)} - z\right) \]
      3. fma-def99.5%

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in y around inf 100.0%

      \[\leadsto \color{blue}{4} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.45 \cdot 10^{+25}:\\ \;\;\;\;1 + z \cdot \frac{-4}{y}\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-246}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-220}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{else}:\\ \;\;\;\;1 + z \cdot \frac{-4}{y}\\ \end{array} \]

Alternative 4: 57.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y} + 1\\ t_1 := 1 + \frac{z \cdot -4}{y}\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-246}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.45 \cdot 10^{-220}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (* 4.0 (/ x y)) 1.0)) (t_1 (+ 1.0 (/ (* z -4.0) y))))
   (if (<= z -7.5e+24)
     t_1
     (if (<= z 4.3e-246)
       t_0
       (if (<= z 3.45e-220) 4.0 (if (<= z 4.6e+110) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + ((z * -4.0) / y);
	double tmp;
	if (z <= -7.5e+24) {
		tmp = t_1;
	} else if (z <= 4.3e-246) {
		tmp = t_0;
	} else if (z <= 3.45e-220) {
		tmp = 4.0;
	} else if (z <= 4.6e+110) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (4.0d0 * (x / y)) + 1.0d0
    t_1 = 1.0d0 + ((z * (-4.0d0)) / y)
    if (z <= (-7.5d+24)) then
        tmp = t_1
    else if (z <= 4.3d-246) then
        tmp = t_0
    else if (z <= 3.45d-220) then
        tmp = 4.0d0
    else if (z <= 4.6d+110) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + ((z * -4.0) / y);
	double tmp;
	if (z <= -7.5e+24) {
		tmp = t_1;
	} else if (z <= 4.3e-246) {
		tmp = t_0;
	} else if (z <= 3.45e-220) {
		tmp = 4.0;
	} else if (z <= 4.6e+110) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (4.0 * (x / y)) + 1.0
	t_1 = 1.0 + ((z * -4.0) / y)
	tmp = 0
	if z <= -7.5e+24:
		tmp = t_1
	elif z <= 4.3e-246:
		tmp = t_0
	elif z <= 3.45e-220:
		tmp = 4.0
	elif z <= 4.6e+110:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(4.0 * Float64(x / y)) + 1.0)
	t_1 = Float64(1.0 + Float64(Float64(z * -4.0) / y))
	tmp = 0.0
	if (z <= -7.5e+24)
		tmp = t_1;
	elseif (z <= 4.3e-246)
		tmp = t_0;
	elseif (z <= 3.45e-220)
		tmp = 4.0;
	elseif (z <= 4.6e+110)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (4.0 * (x / y)) + 1.0;
	t_1 = 1.0 + ((z * -4.0) / y);
	tmp = 0.0;
	if (z <= -7.5e+24)
		tmp = t_1;
	elseif (z <= 4.3e-246)
		tmp = t_0;
	elseif (z <= 3.45e-220)
		tmp = 4.0;
	elseif (z <= 4.6e+110)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.5e+24], t$95$1, If[LessEqual[z, 4.3e-246], t$95$0, If[LessEqual[z, 3.45e-220], 4.0, If[LessEqual[z, 4.6e+110], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq 4.3 \cdot 10^{-246}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 3.45 \cdot 10^{-220}:\\
\;\;\;\;4\\

\mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -7.50000000000000014e24 or 4.6e110 < z

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in z around inf 72.3%

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

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

        \[\leadsto 1 + \frac{\color{blue}{\left(4 \cdot -1\right)} \cdot z}{y} \]
      3. associate-*r*72.3%

        \[\leadsto 1 + \frac{\color{blue}{4 \cdot \left(-1 \cdot z\right)}}{y} \]
      4. neg-mul-172.3%

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

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

        \[\leadsto 1 + \color{blue}{\left(-z\right) \cdot \frac{4}{y}} \]
      7. associate-*r/72.3%

        \[\leadsto 1 + \color{blue}{\frac{\left(-z\right) \cdot 4}{y}} \]
      8. neg-mul-172.3%

        \[\leadsto 1 + \frac{\color{blue}{\left(-1 \cdot z\right)} \cdot 4}{y} \]
      9. *-commutative72.3%

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

        \[\leadsto 1 + \frac{\color{blue}{z \cdot \left(-1 \cdot 4\right)}}{y} \]
      11. metadata-eval72.3%

        \[\leadsto 1 + \frac{z \cdot \color{blue}{-4}}{y} \]
    6. Simplified72.3%

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

    if -7.50000000000000014e24 < z < 4.29999999999999992e-246 or 3.4499999999999999e-220 < z < 4.6e110

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in x around inf 64.3%

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]

    if 4.29999999999999992e-246 < z < 3.4499999999999999e-220

    1. Initial program 99.5%

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.75 + x\right)} - z\right) \]
      3. fma-def99.5%

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in y around inf 100.0%

      \[\leadsto \color{blue}{4} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+24}:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-246}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{elif}\;z \leq 3.45 \cdot 10^{-220}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+110}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \end{array} \]

Alternative 5: 86.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+25}:\\
\;\;\;\;4 - 4 \cdot \frac{z}{y}\\

\mathbf{elif}\;z \leq 8.8 \cdot 10^{+27}:\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5.1999999999999997e25

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
    5. Taylor expanded in x around 0 92.6%

      \[\leadsto 4 + 4 \cdot \color{blue}{\left(-1 \cdot \frac{z}{y}\right)} \]
    6. Step-by-step derivation
      1. neg-mul-192.6%

        \[\leadsto 4 + 4 \cdot \color{blue}{\left(-\frac{z}{y}\right)} \]
      2. distribute-neg-frac92.6%

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

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

    if -5.1999999999999997e25 < z < 8.7999999999999995e27

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
    5. Taylor expanded in x around inf 95.8%

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

    if 8.7999999999999995e27 < z

    1. Initial program 99.9%

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

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

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

      \[\leadsto 1 + \frac{4}{\color{blue}{\frac{y}{x - z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification92.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.2 \cdot 10^{+25}:\\ \;\;\;\;4 - 4 \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{+27}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\ \end{array} \]

Alternative 6: 81.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+96} \lor \neg \left(z \leq 5.2 \cdot 10^{+112}\right):\\
\;\;\;\;1 + \frac{z \cdot -4}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -8.99999999999999914e96 or 5.2000000000000001e112 < z

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
    4. Taylor expanded in z around inf 75.6%

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

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

        \[\leadsto 1 + \frac{\color{blue}{\left(4 \cdot -1\right)} \cdot z}{y} \]
      3. associate-*r*75.6%

        \[\leadsto 1 + \frac{\color{blue}{4 \cdot \left(-1 \cdot z\right)}}{y} \]
      4. neg-mul-175.6%

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

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

        \[\leadsto 1 + \color{blue}{\left(-z\right) \cdot \frac{4}{y}} \]
      7. associate-*r/75.6%

        \[\leadsto 1 + \color{blue}{\frac{\left(-z\right) \cdot 4}{y}} \]
      8. neg-mul-175.6%

        \[\leadsto 1 + \frac{\color{blue}{\left(-1 \cdot z\right)} \cdot 4}{y} \]
      9. *-commutative75.6%

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

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

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

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

    if -8.99999999999999914e96 < z < 5.2000000000000001e112

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
    5. Taylor expanded in x around inf 91.7%

      \[\leadsto 4 + 4 \cdot \color{blue}{\frac{x}{y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+96} \lor \neg \left(z \leq 5.2 \cdot 10^{+112}\right):\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \end{array} \]

Alternative 7: 85.5% accurate, 1.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.9999999999999993e23 or 4.80000000000000025e110 < z

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
    5. Taylor expanded in x around 0 89.5%

      \[\leadsto 4 + 4 \cdot \color{blue}{\left(-1 \cdot \frac{z}{y}\right)} \]
    6. Step-by-step derivation
      1. neg-mul-189.5%

        \[\leadsto 4 + 4 \cdot \color{blue}{\left(-\frac{z}{y}\right)} \]
      2. distribute-neg-frac89.5%

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

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

    if -7.9999999999999993e23 < z < 4.80000000000000025e110

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
    5. Taylor expanded in x around inf 93.5%

      \[\leadsto 4 + 4 \cdot \color{blue}{\frac{x}{y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.8%

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

Alternative 8: 33.6% accurate, 13.0× speedup?

\[\begin{array}{l} \\ 4 \end{array} \]
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
	return 4.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
end function
public static double code(double x, double y, double z) {
	return 4.0;
}
def code(x, y, z):
	return 4.0
function code(x, y, z)
	return 4.0
end
function tmp = code(x, y, z)
	tmp = 4.0;
end
code[x_, y_, z_] := 4.0
\begin{array}{l}

\\
4
\end{array}
Derivation
  1. Initial program 99.9%

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

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

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

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

    \[\leadsto \color{blue}{1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.75, x\right) - z\right)} \]
  4. Taylor expanded in y around inf 30.5%

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

    \[\leadsto 4 \]

Reproduce

?
herbie shell --seed 2023279 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
  :precision binary64
  (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))