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

Percentage Accurate: 99.9% → 100.0%
Time: 7.8s
Alternatives: 9
Speedup: 1.4×

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: 100.0% accurate, 1.4× speedup?

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

\\
\frac{x - z}{y \cdot 0.25} + 2
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. clear-num99.8%

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

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

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

      \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
    5. *-un-lft-identity100.0%

      \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
  6. Applied egg-rr100.0%

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

    \[\leadsto \frac{x - z}{y \cdot 0.25} + 2 \]
  8. Add Preprocessing

Alternative 2: 53.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := \frac{z}{y} \cdot -4\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+84}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -6.4 \cdot 10^{+18}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -8.6 \cdot 10^{-8}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-261}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-280}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-201}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-146}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2200:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+62}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))) (t_1 (* (/ z y) -4.0)))
   (if (<= y -8.5e+84)
     2.0
     (if (<= y -6.4e+18)
       t_1
       (if (<= y -8.6e-8)
         2.0
         (if (<= y -4.3e-193)
           t_0
           (if (<= y -1.6e-261)
             t_1
             (if (<= y -8.5e-280)
               t_0
               (if (<= y 2.8e-201)
                 t_1
                 (if (<= y 5.8e-146)
                   t_0
                   (if (<= y 2200.0) t_1 (if (<= y 1.1e+62) t_0 2.0))))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = (z / y) * -4.0;
	double tmp;
	if (y <= -8.5e+84) {
		tmp = 2.0;
	} else if (y <= -6.4e+18) {
		tmp = t_1;
	} else if (y <= -8.6e-8) {
		tmp = 2.0;
	} else if (y <= -4.3e-193) {
		tmp = t_0;
	} else if (y <= -1.6e-261) {
		tmp = t_1;
	} else if (y <= -8.5e-280) {
		tmp = t_0;
	} else if (y <= 2.8e-201) {
		tmp = t_1;
	} else if (y <= 5.8e-146) {
		tmp = t_0;
	} else if (y <= 2200.0) {
		tmp = t_1;
	} else if (y <= 1.1e+62) {
		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 = (z / y) * (-4.0d0)
    if (y <= (-8.5d+84)) then
        tmp = 2.0d0
    else if (y <= (-6.4d+18)) then
        tmp = t_1
    else if (y <= (-8.6d-8)) then
        tmp = 2.0d0
    else if (y <= (-4.3d-193)) then
        tmp = t_0
    else if (y <= (-1.6d-261)) then
        tmp = t_1
    else if (y <= (-8.5d-280)) then
        tmp = t_0
    else if (y <= 2.8d-201) then
        tmp = t_1
    else if (y <= 5.8d-146) then
        tmp = t_0
    else if (y <= 2200.0d0) then
        tmp = t_1
    else if (y <= 1.1d+62) 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 = (z / y) * -4.0;
	double tmp;
	if (y <= -8.5e+84) {
		tmp = 2.0;
	} else if (y <= -6.4e+18) {
		tmp = t_1;
	} else if (y <= -8.6e-8) {
		tmp = 2.0;
	} else if (y <= -4.3e-193) {
		tmp = t_0;
	} else if (y <= -1.6e-261) {
		tmp = t_1;
	} else if (y <= -8.5e-280) {
		tmp = t_0;
	} else if (y <= 2.8e-201) {
		tmp = t_1;
	} else if (y <= 5.8e-146) {
		tmp = t_0;
	} else if (y <= 2200.0) {
		tmp = t_1;
	} else if (y <= 1.1e+62) {
		tmp = t_0;
	} else {
		tmp = 2.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = (z / y) * -4.0
	tmp = 0
	if y <= -8.5e+84:
		tmp = 2.0
	elif y <= -6.4e+18:
		tmp = t_1
	elif y <= -8.6e-8:
		tmp = 2.0
	elif y <= -4.3e-193:
		tmp = t_0
	elif y <= -1.6e-261:
		tmp = t_1
	elif y <= -8.5e-280:
		tmp = t_0
	elif y <= 2.8e-201:
		tmp = t_1
	elif y <= 5.8e-146:
		tmp = t_0
	elif y <= 2200.0:
		tmp = t_1
	elif y <= 1.1e+62:
		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(Float64(z / y) * -4.0)
	tmp = 0.0
	if (y <= -8.5e+84)
		tmp = 2.0;
	elseif (y <= -6.4e+18)
		tmp = t_1;
	elseif (y <= -8.6e-8)
		tmp = 2.0;
	elseif (y <= -4.3e-193)
		tmp = t_0;
	elseif (y <= -1.6e-261)
		tmp = t_1;
	elseif (y <= -8.5e-280)
		tmp = t_0;
	elseif (y <= 2.8e-201)
		tmp = t_1;
	elseif (y <= 5.8e-146)
		tmp = t_0;
	elseif (y <= 2200.0)
		tmp = t_1;
	elseif (y <= 1.1e+62)
		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 = (z / y) * -4.0;
	tmp = 0.0;
	if (y <= -8.5e+84)
		tmp = 2.0;
	elseif (y <= -6.4e+18)
		tmp = t_1;
	elseif (y <= -8.6e-8)
		tmp = 2.0;
	elseif (y <= -4.3e-193)
		tmp = t_0;
	elseif (y <= -1.6e-261)
		tmp = t_1;
	elseif (y <= -8.5e-280)
		tmp = t_0;
	elseif (y <= 2.8e-201)
		tmp = t_1;
	elseif (y <= 5.8e-146)
		tmp = t_0;
	elseif (y <= 2200.0)
		tmp = t_1;
	elseif (y <= 1.1e+62)
		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[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]}, If[LessEqual[y, -8.5e+84], 2.0, If[LessEqual[y, -6.4e+18], t$95$1, If[LessEqual[y, -8.6e-8], 2.0, If[LessEqual[y, -4.3e-193], t$95$0, If[LessEqual[y, -1.6e-261], t$95$1, If[LessEqual[y, -8.5e-280], t$95$0, If[LessEqual[y, 2.8e-201], t$95$1, If[LessEqual[y, 5.8e-146], t$95$0, If[LessEqual[y, 2200.0], t$95$1, If[LessEqual[y, 1.1e+62], t$95$0, 2.0]]]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -6.4 \cdot 10^{+18}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -8.6 \cdot 10^{-8}:\\
\;\;\;\;2\\

\mathbf{elif}\;y \leq -4.3 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -1.6 \cdot 10^{-261}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -8.5 \cdot 10^{-280}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 2.8 \cdot 10^{-201}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 5.8 \cdot 10^{-146}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 2200:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 1.1 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.5000000000000008e84 or -6.4e18 < y < -8.6000000000000002e-8 or 1.10000000000000007e62 < y

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 78.2%

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

    if -8.5000000000000008e84 < y < -6.4e18 or -4.3000000000000002e-193 < y < -1.60000000000000002e-261 or -8.50000000000000037e-280 < y < 2.7999999999999999e-201 or 5.80000000000000022e-146 < y < 2200

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
      5. *-un-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{x - z}{y \cdot 0.25}} + 2 \]
    7. Taylor expanded in z around inf 70.3%

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

    if -8.6000000000000002e-8 < y < -4.3000000000000002e-193 or -1.60000000000000002e-261 < y < -8.50000000000000037e-280 or 2.7999999999999999e-201 < y < 5.80000000000000022e-146 or 2200 < y < 1.10000000000000007e62

    1. Initial program 98.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
      5. *-un-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{x - z}{y \cdot 0.25}} + 2 \]
    7. Taylor expanded in x around inf 68.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+84}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -6.4 \cdot 10^{+18}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq -8.6 \cdot 10^{-8}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-193}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-261}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-280}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-201}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-146}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 2200:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+62}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 54.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := 1 + z \cdot \frac{-4}{y}\\ t_2 := \frac{z}{y} \cdot -4\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{+84}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-13}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-191}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -1.46 \cdot 10^{-257}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-281}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-200}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+62}:\\ \;\;\;\;t\_1\\ \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 (/ -4.0 y))))
        (t_2 (* (/ z y) -4.0)))
   (if (<= y -5.8e+84)
     2.0
     (if (<= y -9e-13)
       t_1
       (if (<= y -1.35e-191)
         t_0
         (if (<= y -1.46e-257)
           t_2
           (if (<= y -3.8e-281)
             t_0
             (if (<= y 1.85e-200)
               t_2
               (if (<= y 3e-147) t_0 (if (<= y 3.2e+62) t_1 2.0))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = 1.0 + (z * (-4.0 / y));
	double t_2 = (z / y) * -4.0;
	double tmp;
	if (y <= -5.8e+84) {
		tmp = 2.0;
	} else if (y <= -9e-13) {
		tmp = t_1;
	} else if (y <= -1.35e-191) {
		tmp = t_0;
	} else if (y <= -1.46e-257) {
		tmp = t_2;
	} else if (y <= -3.8e-281) {
		tmp = t_0;
	} else if (y <= 1.85e-200) {
		tmp = t_2;
	} else if (y <= 3e-147) {
		tmp = t_0;
	} else if (y <= 3.2e+62) {
		tmp = t_1;
	} else {
		tmp = 2.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    t_1 = 1.0d0 + (z * ((-4.0d0) / y))
    t_2 = (z / y) * (-4.0d0)
    if (y <= (-5.8d+84)) then
        tmp = 2.0d0
    else if (y <= (-9d-13)) then
        tmp = t_1
    else if (y <= (-1.35d-191)) then
        tmp = t_0
    else if (y <= (-1.46d-257)) then
        tmp = t_2
    else if (y <= (-3.8d-281)) then
        tmp = t_0
    else if (y <= 1.85d-200) then
        tmp = t_2
    else if (y <= 3d-147) then
        tmp = t_0
    else if (y <= 3.2d+62) then
        tmp = t_1
    else
        tmp = 2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = 1.0 + (z * (-4.0 / y));
	double t_2 = (z / y) * -4.0;
	double tmp;
	if (y <= -5.8e+84) {
		tmp = 2.0;
	} else if (y <= -9e-13) {
		tmp = t_1;
	} else if (y <= -1.35e-191) {
		tmp = t_0;
	} else if (y <= -1.46e-257) {
		tmp = t_2;
	} else if (y <= -3.8e-281) {
		tmp = t_0;
	} else if (y <= 1.85e-200) {
		tmp = t_2;
	} else if (y <= 3e-147) {
		tmp = t_0;
	} else if (y <= 3.2e+62) {
		tmp = t_1;
	} else {
		tmp = 2.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = 1.0 + (z * (-4.0 / y))
	t_2 = (z / y) * -4.0
	tmp = 0
	if y <= -5.8e+84:
		tmp = 2.0
	elif y <= -9e-13:
		tmp = t_1
	elif y <= -1.35e-191:
		tmp = t_0
	elif y <= -1.46e-257:
		tmp = t_2
	elif y <= -3.8e-281:
		tmp = t_0
	elif y <= 1.85e-200:
		tmp = t_2
	elif y <= 3e-147:
		tmp = t_0
	elif y <= 3.2e+62:
		tmp = t_1
	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(z * Float64(-4.0 / y)))
	t_2 = Float64(Float64(z / y) * -4.0)
	tmp = 0.0
	if (y <= -5.8e+84)
		tmp = 2.0;
	elseif (y <= -9e-13)
		tmp = t_1;
	elseif (y <= -1.35e-191)
		tmp = t_0;
	elseif (y <= -1.46e-257)
		tmp = t_2;
	elseif (y <= -3.8e-281)
		tmp = t_0;
	elseif (y <= 1.85e-200)
		tmp = t_2;
	elseif (y <= 3e-147)
		tmp = t_0;
	elseif (y <= 3.2e+62)
		tmp = t_1;
	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 * (-4.0 / y));
	t_2 = (z / y) * -4.0;
	tmp = 0.0;
	if (y <= -5.8e+84)
		tmp = 2.0;
	elseif (y <= -9e-13)
		tmp = t_1;
	elseif (y <= -1.35e-191)
		tmp = t_0;
	elseif (y <= -1.46e-257)
		tmp = t_2;
	elseif (y <= -3.8e-281)
		tmp = t_0;
	elseif (y <= 1.85e-200)
		tmp = t_2;
	elseif (y <= 3e-147)
		tmp = t_0;
	elseif (y <= 3.2e+62)
		tmp = t_1;
	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[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]}, If[LessEqual[y, -5.8e+84], 2.0, If[LessEqual[y, -9e-13], t$95$1, If[LessEqual[y, -1.35e-191], t$95$0, If[LessEqual[y, -1.46e-257], t$95$2, If[LessEqual[y, -3.8e-281], t$95$0, If[LessEqual[y, 1.85e-200], t$95$2, If[LessEqual[y, 3e-147], t$95$0, If[LessEqual[y, 3.2e+62], t$95$1, 2.0]]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -9 \cdot 10^{-13}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -1.35 \cdot 10^{-191}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -1.46 \cdot 10^{-257}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;y \leq -3.8 \cdot 10^{-281}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.85 \cdot 10^{-200}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;y \leq 3 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 3.2 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -5.79999999999999977e84 or 3.19999999999999984e62 < y

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 79.7%

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

    if -5.79999999999999977e84 < y < -9e-13 or 3.0000000000000002e-147 < y < 3.19999999999999984e62

    1. Initial program 98.7%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 59.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 1 + z \cdot \left(-\color{blue}{\frac{4 \cdot 1}{y}}\right) \]
      12. metadata-eval59.2%

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

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

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

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

    if -9e-13 < y < -1.34999999999999999e-191 or -1.4600000000000001e-257 < y < -3.79999999999999976e-281 or 1.85000000000000005e-200 < y < 3.0000000000000002e-147

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
      5. *-un-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{x - z}{y \cdot 0.25}} + 2 \]
    7. Taylor expanded in x around inf 72.0%

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

    if -1.34999999999999999e-191 < y < -1.4600000000000001e-257 or -3.79999999999999976e-281 < y < 1.85000000000000005e-200

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.8%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
      5. *-un-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{x - z}{y \cdot 0.25}} + 2 \]
    7. Taylor expanded in z around inf 71.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+84}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-13}:\\ \;\;\;\;1 + z \cdot \frac{-4}{y}\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-191}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq -1.46 \cdot 10^{-257}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-281}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-200}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-147}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+62}:\\ \;\;\;\;1 + z \cdot \frac{-4}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+40} \lor \neg \left(z \leq 10^{-10} \lor \neg \left(z \leq 8 \cdot 10^{+14}\right) \land z \leq 1.65 \cdot 10^{+158}\right):\\
\;\;\;\;1 + z \cdot \frac{-4}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.14999999999999997e40 or 1.00000000000000004e-10 < z < 8e14 or 1.65000000000000009e158 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 81.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 1 + z \cdot \left(-\color{blue}{\frac{4 \cdot 1}{y}}\right) \]
      12. metadata-eval81.2%

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

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

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

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

    if -1.14999999999999997e40 < z < 1.00000000000000004e-10 or 8e14 < z < 1.65000000000000009e158

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 89.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+40} \lor \neg \left(z \leq 10^{-10} \lor \neg \left(z \leq 8 \cdot 10^{+14}\right) \land z \leq 1.65 \cdot 10^{+158}\right):\\ \;\;\;\;1 + z \cdot \frac{-4}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 52.3% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;y \leq -3.2 \cdot 10^{+20} \lor \neg \left(y \leq -7.5 \cdot 10^{-74}\right) \land y \leq 7.8 \cdot 10^{+62}:\\
\;\;\;\;\frac{z}{y} \cdot -4\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.39999999999999997e83 or -3.2e20 < y < -7.5e-74 or 7.8e62 < y

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 74.7%

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

    if -4.39999999999999997e83 < y < -3.2e20 or -7.5e-74 < y < 7.8e62

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.7%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x - z\right)}{y \cdot 0.25}} + 2 \]
      5. *-un-lft-identity100.0%

        \[\leadsto \frac{\color{blue}{x - z}}{y \cdot 0.25} + 2 \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{x - z}{y \cdot 0.25}} + 2 \]
    7. Taylor expanded in z around inf 52.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.4 \cdot 10^{+83}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{+20} \lor \neg \left(y \leq -7.5 \cdot 10^{-74}\right) \land y \leq 7.8 \cdot 10^{+62}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 86.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{+39} \lor \neg \left(z \leq 7.8 \cdot 10^{-17}\right):\\ \;\;\;\;2 + \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 -9.8e+39) (not (<= z 7.8e-17)))
   (+ 2.0 (* (/ z y) -4.0))
   (+ 2.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -9.8e+39) || !(z <= 7.8e-17)) {
		tmp = 2.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 <= (-9.8d+39)) .or. (.not. (z <= 7.8d-17))) then
        tmp = 2.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 <= -9.8e+39) || !(z <= 7.8e-17)) {
		tmp = 2.0 + ((z / y) * -4.0);
	} else {
		tmp = 2.0 + (4.0 * (x / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -9.8e+39) or not (z <= 7.8e-17):
		tmp = 2.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 <= -9.8e+39) || !(z <= 7.8e-17))
		tmp = Float64(2.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 <= -9.8e+39) || ~((z <= 7.8e-17)))
		tmp = 2.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, -9.8e+39], N[Not[LessEqual[z, 7.8e-17]], $MachinePrecision]], N[(2.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 -9.8 \cdot 10^{+39} \lor \neg \left(z \leq 7.8 \cdot 10^{-17}\right):\\
\;\;\;\;2 + \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 < -9.79999999999999974e39 or 7.79999999999999979e-17 < 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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 91.2%

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

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

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

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

    if -9.79999999999999974e39 < z < 7.79999999999999979e-17

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right) + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 93.2%

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

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

Alternative 7: 99.8% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Add Preprocessing
  3. Taylor expanded in z around inf 41.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 1 + z \cdot \left(-\color{blue}{\frac{4 \cdot 1}{y}}\right) \]
    12. metadata-eval41.2%

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

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

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

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

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

    \[\leadsto 1 \]
  8. Add Preprocessing

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

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf 35.1%

    \[\leadsto \color{blue}{2} \]
  4. Final simplification35.1%

    \[\leadsto 2 \]
  5. Add Preprocessing

Reproduce

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