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

Percentage Accurate: 99.9% → 99.9%
Time: 5.5s
Alternatives: 9
Speedup: 1.0×

Specification

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

\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\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 9 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Final simplification100.0%

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

Alternative 2: 56.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{z}{y} \cdot -4\\ t_1 := 1 + \frac{x}{\frac{y}{4}}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-259}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-292}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-208}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+27}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* (/ z y) -4.0))) (t_1 (+ 1.0 (/ x (/ y 4.0)))))
   (if (<= x -1e+15)
     t_1
     (if (<= x -2.15e-259)
       2.0
       (if (<= x 3.4e-292)
         t_0
         (if (<= x 2.7e-208)
           2.0
           (if (<= x 7.8e-59) t_0 (if (<= x 1.85e+27) 2.0 t_1))))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + ((z / y) * -4.0);
	double t_1 = 1.0 + (x / (y / 4.0));
	double tmp;
	if (x <= -1e+15) {
		tmp = t_1;
	} else if (x <= -2.15e-259) {
		tmp = 2.0;
	} else if (x <= 3.4e-292) {
		tmp = t_0;
	} else if (x <= 2.7e-208) {
		tmp = 2.0;
	} else if (x <= 7.8e-59) {
		tmp = t_0;
	} else if (x <= 1.85e+27) {
		tmp = 2.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 = 1.0d0 + ((z / y) * (-4.0d0))
    t_1 = 1.0d0 + (x / (y / 4.0d0))
    if (x <= (-1d+15)) then
        tmp = t_1
    else if (x <= (-2.15d-259)) then
        tmp = 2.0d0
    else if (x <= 3.4d-292) then
        tmp = t_0
    else if (x <= 2.7d-208) then
        tmp = 2.0d0
    else if (x <= 7.8d-59) then
        tmp = t_0
    else if (x <= 1.85d+27) then
        tmp = 2.0d0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 1.0 + ((z / y) * -4.0);
	double t_1 = 1.0 + (x / (y / 4.0));
	double tmp;
	if (x <= -1e+15) {
		tmp = t_1;
	} else if (x <= -2.15e-259) {
		tmp = 2.0;
	} else if (x <= 3.4e-292) {
		tmp = t_0;
	} else if (x <= 2.7e-208) {
		tmp = 2.0;
	} else if (x <= 7.8e-59) {
		tmp = t_0;
	} else if (x <= 1.85e+27) {
		tmp = 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + ((z / y) * -4.0)
	t_1 = 1.0 + (x / (y / 4.0))
	tmp = 0
	if x <= -1e+15:
		tmp = t_1
	elif x <= -2.15e-259:
		tmp = 2.0
	elif x <= 3.4e-292:
		tmp = t_0
	elif x <= 2.7e-208:
		tmp = 2.0
	elif x <= 7.8e-59:
		tmp = t_0
	elif x <= 1.85e+27:
		tmp = 2.0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(Float64(z / y) * -4.0))
	t_1 = Float64(1.0 + Float64(x / Float64(y / 4.0)))
	tmp = 0.0
	if (x <= -1e+15)
		tmp = t_1;
	elseif (x <= -2.15e-259)
		tmp = 2.0;
	elseif (x <= 3.4e-292)
		tmp = t_0;
	elseif (x <= 2.7e-208)
		tmp = 2.0;
	elseif (x <= 7.8e-59)
		tmp = t_0;
	elseif (x <= 1.85e+27)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + ((z / y) * -4.0);
	t_1 = 1.0 + (x / (y / 4.0));
	tmp = 0.0;
	if (x <= -1e+15)
		tmp = t_1;
	elseif (x <= -2.15e-259)
		tmp = 2.0;
	elseif (x <= 3.4e-292)
		tmp = t_0;
	elseif (x <= 2.7e-208)
		tmp = 2.0;
	elseif (x <= 7.8e-59)
		tmp = t_0;
	elseif (x <= 1.85e+27)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(x / N[(y / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+15], t$95$1, If[LessEqual[x, -2.15e-259], 2.0, If[LessEqual[x, 3.4e-292], t$95$0, If[LessEqual[x, 2.7e-208], 2.0, If[LessEqual[x, 7.8e-59], t$95$0, If[LessEqual[x, 1.85e+27], 2.0, t$95$1]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -2.15 \cdot 10^{-259}:\\
\;\;\;\;2\\

\mathbf{elif}\;x \leq 3.4 \cdot 10^{-292}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 2.7 \cdot 10^{-208}:\\
\;\;\;\;2\\

\mathbf{elif}\;x \leq 7.8 \cdot 10^{-59}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.85 \cdot 10^{+27}:\\
\;\;\;\;2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1e15 or 1.85000000000000001e27 < x

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative68.8%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot 4}}{y} \]
      3. associate-/l*68.8%

        \[\leadsto 1 + \color{blue}{\frac{x}{\frac{y}{4}}} \]
    6. Simplified68.8%

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

    if -1e15 < x < -2.15e-259 or 3.40000000000000017e-292 < x < 2.7e-208 or 7.80000000000000038e-59 < x < 1.85000000000000001e27

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      12. distribute-rgt-neg-in99.9%

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.9%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.9%

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

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

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

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

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

        \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    5. Applied egg-rr99.9%

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around inf 70.8%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
    7. Taylor expanded in y around inf 61.4%

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

    if -2.15e-259 < x < 3.40000000000000017e-292 or 2.7e-208 < x < 7.80000000000000038e-59

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+15}:\\ \;\;\;\;1 + \frac{x}{\frac{y}{4}}\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-259}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-292}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-208}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-59}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+27}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x}{\frac{y}{4}}\\ \end{array} \]

Alternative 3: 54.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := 1 + \frac{z}{y} \cdot -4\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+63}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-204}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-158}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))) (t_1 (+ 1.0 (* (/ z y) -4.0))))
   (if (<= y -2.3e+63)
     2.0
     (if (<= y -1.05e-204)
       t_1
       (if (<= y 1.2e-158)
         t_0
         (if (<= y 4e-35) t_1 (if (<= y 1.4e+45) t_0 2.0)))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = 1.0 + ((z / y) * -4.0);
	double tmp;
	if (y <= -2.3e+63) {
		tmp = 2.0;
	} else if (y <= -1.05e-204) {
		tmp = t_1;
	} else if (y <= 1.2e-158) {
		tmp = t_0;
	} else if (y <= 4e-35) {
		tmp = t_1;
	} else if (y <= 1.4e+45) {
		tmp = t_0;
	} 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 * (x / y)
    t_1 = 1.0d0 + ((z / y) * (-4.0d0))
    if (y <= (-2.3d+63)) then
        tmp = 2.0d0
    else if (y <= (-1.05d-204)) then
        tmp = t_1
    else if (y <= 1.2d-158) then
        tmp = t_0
    else if (y <= 4d-35) then
        tmp = t_1
    else if (y <= 1.4d+45) then
        tmp = t_0
    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 * (x / y);
	double t_1 = 1.0 + ((z / y) * -4.0);
	double tmp;
	if (y <= -2.3e+63) {
		tmp = 2.0;
	} else if (y <= -1.05e-204) {
		tmp = t_1;
	} else if (y <= 1.2e-158) {
		tmp = t_0;
	} else if (y <= 4e-35) {
		tmp = t_1;
	} else if (y <= 1.4e+45) {
		tmp = t_0;
	} else {
		tmp = 2.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = 1.0 + ((z / y) * -4.0)
	tmp = 0
	if y <= -2.3e+63:
		tmp = 2.0
	elif y <= -1.05e-204:
		tmp = t_1
	elif y <= 1.2e-158:
		tmp = t_0
	elif y <= 4e-35:
		tmp = t_1
	elif y <= 1.4e+45:
		tmp = t_0
	else:
		tmp = 2.0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	t_1 = Float64(1.0 + Float64(Float64(z / y) * -4.0))
	tmp = 0.0
	if (y <= -2.3e+63)
		tmp = 2.0;
	elseif (y <= -1.05e-204)
		tmp = t_1;
	elseif (y <= 1.2e-158)
		tmp = t_0;
	elseif (y <= 4e-35)
		tmp = t_1;
	elseif (y <= 1.4e+45)
		tmp = t_0;
	else
		tmp = 2.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	t_1 = 1.0 + ((z / y) * -4.0);
	tmp = 0.0;
	if (y <= -2.3e+63)
		tmp = 2.0;
	elseif (y <= -1.05e-204)
		tmp = t_1;
	elseif (y <= 1.2e-158)
		tmp = t_0;
	elseif (y <= 4e-35)
		tmp = t_1;
	elseif (y <= 1.4e+45)
		tmp = t_0;
	else
		tmp = 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.3e+63], 2.0, If[LessEqual[y, -1.05e-204], t$95$1, If[LessEqual[y, 1.2e-158], t$95$0, If[LessEqual[y, 4e-35], t$95$1, If[LessEqual[y, 1.4e+45], t$95$0, 2.0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -1.05 \cdot 10^{-204}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 1.2 \cdot 10^{-158}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 4 \cdot 10^{-35}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{+45}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.29999999999999993e63 or 1.4e45 < y

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      12. distribute-rgt-neg-in99.9%

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.9%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.9%

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

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

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

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

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

        \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    5. Applied egg-rr99.9%

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around inf 87.9%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
    7. Taylor expanded in y around inf 67.3%

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

    if -2.29999999999999993e63 < y < -1.05000000000000005e-204 or 1.20000000000000004e-158 < y < 4.00000000000000003e-35

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if -1.05000000000000005e-204 < y < 1.20000000000000004e-158 or 4.00000000000000003e-35 < y < 1.4e45

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative65.8%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot 4}}{y} \]
      3. associate-/l*65.8%

        \[\leadsto 1 + \color{blue}{\frac{x}{\frac{y}{4}}} \]
    6. Simplified65.8%

      \[\leadsto 1 + \color{blue}{\frac{x}{\frac{y}{4}}} \]
    7. Taylor expanded in x around inf 64.4%

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification60.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+63}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-204}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-158}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-35}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+45}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]

Alternative 4: 80.7% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+82} \lor \neg \left(z \leq 2.2 \cdot 10^{+96} \lor \neg \left(z \leq 4.5 \cdot 10^{+177}\right) \land z \leq 2.35 \cdot 10^{+201}\right):\\
\;\;\;\;1 + \frac{z}{y} \cdot -4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.9999999999999999e82 or 2.1999999999999999e96 < z < 4.4999999999999997e177 or 2.3499999999999999e201 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if -3.9999999999999999e82 < z < 2.1999999999999999e96 or 4.4999999999999997e177 < z < 2.3499999999999999e201

    1. Initial program 100.0%

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.25 + x\right)} - z\right) \]
      3. associate--l+99.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      12. distribute-rgt-neg-in99.9%

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.9%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.9%

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

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

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

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

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

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

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around inf 88.4%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
    7. Step-by-step derivation
      1. div-inv88.4%

        \[\leadsto 2 + \color{blue}{4 \cdot \frac{1}{\frac{y}{x}}} \]
      2. clear-num88.5%

        \[\leadsto 2 + 4 \cdot \color{blue}{\frac{x}{y}} \]
      3. *-commutative88.5%

        \[\leadsto 2 + \color{blue}{\frac{x}{y} \cdot 4} \]
    8. Applied egg-rr88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+82} \lor \neg \left(z \leq 2.2 \cdot 10^{+96} \lor \neg \left(z \leq 4.5 \cdot 10^{+177}\right) \land z \leq 2.35 \cdot 10^{+201}\right):\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{else}:\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \end{array} \]

Alternative 5: 86.3% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-9} \lor \neg \left(x \leq 4.8 \cdot 10^{+25}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.99999999999999953e-9 or 4.79999999999999992e25 < x

    1. Initial program 100.0%

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.25 + x\right)} - z\right) \]
      3. associate--l+99.8%

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

        \[\leadsto 1 + \color{blue}{\left(\frac{4}{y} \cdot \left(y \cdot 0.25\right) + \frac{4}{y} \cdot \left(x - z\right)\right)} \]
      5. associate-+r+99.8%

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.8%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.8%

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

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

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

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

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

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

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around inf 83.0%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
    7. Step-by-step derivation
      1. div-inv83.0%

        \[\leadsto 2 + \color{blue}{4 \cdot \frac{1}{\frac{y}{x}}} \]
      2. clear-num83.2%

        \[\leadsto 2 + 4 \cdot \color{blue}{\frac{x}{y}} \]
      3. *-commutative83.2%

        \[\leadsto 2 + \color{blue}{\frac{x}{y} \cdot 4} \]
    8. Applied egg-rr83.2%

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

    if -8.99999999999999953e-9 < x < 4.79999999999999992e25

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      12. distribute-rgt-neg-in99.9%

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.9%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.9%

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

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

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

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

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

        \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    5. Applied egg-rr99.9%

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around 0 92.3%

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

        \[\leadsto 2 + \frac{4}{\color{blue}{\frac{-1 \cdot y}{z}}} \]
      2. neg-mul-192.3%

        \[\leadsto 2 + \frac{4}{\frac{\color{blue}{-y}}{z}} \]
    8. Simplified92.3%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{-y}{z}}} \]
    9. Step-by-step derivation
      1. frac-2neg92.3%

        \[\leadsto 2 + \color{blue}{\frac{-4}{-\frac{-y}{z}}} \]
      2. div-inv92.3%

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

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\color{blue}{\frac{-\left(-y\right)}{z}}} \]
      4. remove-double-neg92.3%

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\frac{\color{blue}{y}}{z}} \]
      5. add-sqr-sqrt46.5%

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

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\frac{\color{blue}{\sqrt{y \cdot y}}}{z}} \]
      7. sqr-neg65.8%

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\frac{\sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}}}{z}} \]
      8. sqrt-unprod23.0%

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\frac{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{z}} \]
      9. add-sqr-sqrt52.5%

        \[\leadsto 2 + \left(-4\right) \cdot \frac{1}{\frac{\color{blue}{-y}}{z}} \]
      10. clear-num52.5%

        \[\leadsto 2 + \left(-4\right) \cdot \color{blue}{\frac{z}{-y}} \]
      11. cancel-sign-sub-inv52.5%

        \[\leadsto \color{blue}{2 - 4 \cdot \frac{z}{-y}} \]
      12. clear-num52.5%

        \[\leadsto 2 - 4 \cdot \color{blue}{\frac{1}{\frac{-y}{z}}} \]
      13. div-inv52.5%

        \[\leadsto 2 - \color{blue}{\frac{4}{\frac{-y}{z}}} \]
      14. div-inv52.5%

        \[\leadsto 2 - \color{blue}{4 \cdot \frac{1}{\frac{-y}{z}}} \]
      15. clear-num52.5%

        \[\leadsto 2 - 4 \cdot \color{blue}{\frac{z}{-y}} \]
      16. add-sqr-sqrt23.0%

        \[\leadsto 2 - 4 \cdot \frac{z}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      17. sqrt-unprod65.8%

        \[\leadsto 2 - 4 \cdot \frac{z}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      18. sqr-neg65.8%

        \[\leadsto 2 - 4 \cdot \frac{z}{\sqrt{\color{blue}{y \cdot y}}} \]
      19. sqrt-unprod46.5%

        \[\leadsto 2 - 4 \cdot \frac{z}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      20. add-sqr-sqrt92.3%

        \[\leadsto 2 - 4 \cdot \frac{z}{\color{blue}{y}} \]
    10. Applied egg-rr92.3%

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

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

Alternative 6: 53.4% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+71}:\\
\;\;\;\;2\\

\mathbf{elif}\;y \leq 3.4 \cdot 10^{+46}:\\
\;\;\;\;4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.5e71 or 3.3999999999999998e46 < y

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      12. distribute-rgt-neg-in99.9%

        \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      13. distribute-lft-neg-out99.9%

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

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

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

        \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
      17. distribute-lft-neg-out99.9%

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

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

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

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

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

        \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    5. Applied egg-rr99.9%

      \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
    6. Taylor expanded in x around inf 87.9%

      \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
    7. Taylor expanded in y around inf 67.3%

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

    if -5.5e71 < y < 3.3999999999999998e46

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative51.0%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot 4}}{y} \]
      3. associate-/l*51.0%

        \[\leadsto 1 + \color{blue}{\frac{x}{\frac{y}{4}}} \]
    6. Simplified51.0%

      \[\leadsto 1 + \color{blue}{\frac{x}{\frac{y}{4}}} \]
    7. Taylor expanded in x around inf 48.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{+71}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+46}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]

Alternative 7: 99.8% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.25 + x\right)} - z\right) \]
    3. associate--l+99.8%

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

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

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

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

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

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

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

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

      \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    12. distribute-rgt-neg-in99.9%

      \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    13. distribute-lft-neg-out99.9%

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

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

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

      \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    17. distribute-lft-neg-out99.9%

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

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

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

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

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

Alternative 8: 8.1% accurate, 13.0× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
  7. Taylor expanded in z around 0 8.3%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification8.3%

    \[\leadsto 1 \]

Alternative 9: 33.9% accurate, 13.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%

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

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

      \[\leadsto 1 + \frac{4}{y} \cdot \left(\color{blue}{\left(y \cdot 0.25 + x\right)} - z\right) \]
    3. associate--l+99.8%

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

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

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

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

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

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

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

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

      \[\leadsto \left(1 + \frac{y \cdot 0.25}{\color{blue}{\frac{y \cdot \left(-0.25\right)}{-1}}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    12. distribute-rgt-neg-in99.9%

      \[\leadsto \left(1 + \frac{y \cdot 0.25}{\frac{\color{blue}{-y \cdot 0.25}}{-1}}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    13. distribute-lft-neg-out99.9%

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

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

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

      \[\leadsto \left(1 + \frac{\color{blue}{-y \cdot 0.25}}{\left(-y\right) \cdot 0.25}\right) + \frac{4}{y} \cdot \left(x - z\right) \]
    17. distribute-lft-neg-out99.9%

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

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

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

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

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

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

    \[\leadsto 2 + \color{blue}{\frac{4}{\frac{y}{x - z}}} \]
  6. Taylor expanded in x around inf 72.3%

    \[\leadsto 2 + \frac{4}{\color{blue}{\frac{y}{x}}} \]
  7. Taylor expanded in y around inf 35.7%

    \[\leadsto \color{blue}{2} \]
  8. Final simplification35.7%

    \[\leadsto 2 \]

Reproduce

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