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

Percentage Accurate: 99.8% → 100.0%
Time: 9.2s
Alternatives: 11
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(4, 0.75 + \frac{x - z}{y}, 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma 4.0 (+ 0.75 (/ (- x z) y)) 1.0))
double code(double x, double y, double z) {
	return fma(4.0, (0.75 + ((x - z) / y)), 1.0);
}
function code(x, y, z)
	return fma(4.0, Float64(0.75 + Float64(Float64(x - z) / y)), 1.0)
end
code[x_, y_, z_] := N[(4.0 * N[(0.75 + N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(4, 0.75 + \frac{x - z}{y}, 1\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(4, \color{blue}{\frac{y \cdot 0.75}{y} - \frac{z + \left(-x\right)}{y}}, 1\right) \]
    10. sub-neg99.9%

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

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

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

      \[\leadsto \mathsf{fma}\left(4, \color{blue}{0.75} + \left(-\frac{z + \left(-x\right)}{y}\right), 1\right) \]
    14. distribute-frac-neg2100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{z + \left(-x\right)}{-y}}, 1\right) \]
    15. remove-double-neg100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{\left(-\left(-z\right)\right)} + \left(-x\right)}{-y}, 1\right) \]
    16. distribute-neg-out100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{-\left(\left(-z\right) + x\right)}}{-y}, 1\right) \]
    17. +-commutative100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x + \left(-z\right)\right)}}{-y}, 1\right) \]
    18. sub-neg100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x - z\right)}}{-y}, 1\right) \]
    19. distribute-frac-neg100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\left(-\frac{x - z}{-y}\right)}, 1\right) \]
    20. distribute-frac-neg2100.0%

      \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{x - z}{-\left(-y\right)}}, 1\right) \]
    21. remove-double-neg100.0%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(4, 0.75 + \frac{x - z}{y}, 1\right)} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{x - z}{y}, 1\right) \]
  6. Add Preprocessing

Alternative 2: 54.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := \frac{z \cdot -4}{y}\\ \mathbf{if}\;y \leq -1.26 \cdot 10^{+85}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -6.4 \cdot 10^{+18}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-7}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{-260}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{-285}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-201}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 290000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+54}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+62}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))) (t_1 (/ (* z -4.0) y)))
   (if (<= y -1.26e+85)
     4.0
     (if (<= y -6.4e+18)
       t_1
       (if (<= y -1.4e-7)
         4.0
         (if (<= y -2.9e-193)
           t_0
           (if (<= y -1.12e-260)
             t_1
             (if (<= y -9.8e-285)
               t_0
               (if (<= y 7e-201)
                 t_1
                 (if (<= y 4.7e-147)
                   t_0
                   (if (<= y 290000.0)
                     t_1
                     (if (<= y 1.15e+54)
                       t_0
                       (if (<= y 1.95e+62) t_1 4.0)))))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = (z * -4.0) / y;
	double tmp;
	if (y <= -1.26e+85) {
		tmp = 4.0;
	} else if (y <= -6.4e+18) {
		tmp = t_1;
	} else if (y <= -1.4e-7) {
		tmp = 4.0;
	} else if (y <= -2.9e-193) {
		tmp = t_0;
	} else if (y <= -1.12e-260) {
		tmp = t_1;
	} else if (y <= -9.8e-285) {
		tmp = t_0;
	} else if (y <= 7e-201) {
		tmp = t_1;
	} else if (y <= 4.7e-147) {
		tmp = t_0;
	} else if (y <= 290000.0) {
		tmp = t_1;
	} else if (y <= 1.15e+54) {
		tmp = t_0;
	} else if (y <= 1.95e+62) {
		tmp = t_1;
	} else {
		tmp = 4.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    t_1 = (z * (-4.0d0)) / y
    if (y <= (-1.26d+85)) then
        tmp = 4.0d0
    else if (y <= (-6.4d+18)) then
        tmp = t_1
    else if (y <= (-1.4d-7)) then
        tmp = 4.0d0
    else if (y <= (-2.9d-193)) then
        tmp = t_0
    else if (y <= (-1.12d-260)) then
        tmp = t_1
    else if (y <= (-9.8d-285)) then
        tmp = t_0
    else if (y <= 7d-201) then
        tmp = t_1
    else if (y <= 4.7d-147) then
        tmp = t_0
    else if (y <= 290000.0d0) then
        tmp = t_1
    else if (y <= 1.15d+54) then
        tmp = t_0
    else if (y <= 1.95d+62) then
        tmp = t_1
    else
        tmp = 4.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 * -4.0) / y;
	double tmp;
	if (y <= -1.26e+85) {
		tmp = 4.0;
	} else if (y <= -6.4e+18) {
		tmp = t_1;
	} else if (y <= -1.4e-7) {
		tmp = 4.0;
	} else if (y <= -2.9e-193) {
		tmp = t_0;
	} else if (y <= -1.12e-260) {
		tmp = t_1;
	} else if (y <= -9.8e-285) {
		tmp = t_0;
	} else if (y <= 7e-201) {
		tmp = t_1;
	} else if (y <= 4.7e-147) {
		tmp = t_0;
	} else if (y <= 290000.0) {
		tmp = t_1;
	} else if (y <= 1.15e+54) {
		tmp = t_0;
	} else if (y <= 1.95e+62) {
		tmp = t_1;
	} else {
		tmp = 4.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = (z * -4.0) / y
	tmp = 0
	if y <= -1.26e+85:
		tmp = 4.0
	elif y <= -6.4e+18:
		tmp = t_1
	elif y <= -1.4e-7:
		tmp = 4.0
	elif y <= -2.9e-193:
		tmp = t_0
	elif y <= -1.12e-260:
		tmp = t_1
	elif y <= -9.8e-285:
		tmp = t_0
	elif y <= 7e-201:
		tmp = t_1
	elif y <= 4.7e-147:
		tmp = t_0
	elif y <= 290000.0:
		tmp = t_1
	elif y <= 1.15e+54:
		tmp = t_0
	elif y <= 1.95e+62:
		tmp = t_1
	else:
		tmp = 4.0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	t_1 = Float64(Float64(z * -4.0) / y)
	tmp = 0.0
	if (y <= -1.26e+85)
		tmp = 4.0;
	elseif (y <= -6.4e+18)
		tmp = t_1;
	elseif (y <= -1.4e-7)
		tmp = 4.0;
	elseif (y <= -2.9e-193)
		tmp = t_0;
	elseif (y <= -1.12e-260)
		tmp = t_1;
	elseif (y <= -9.8e-285)
		tmp = t_0;
	elseif (y <= 7e-201)
		tmp = t_1;
	elseif (y <= 4.7e-147)
		tmp = t_0;
	elseif (y <= 290000.0)
		tmp = t_1;
	elseif (y <= 1.15e+54)
		tmp = t_0;
	elseif (y <= 1.95e+62)
		tmp = t_1;
	else
		tmp = 4.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	t_1 = (z * -4.0) / y;
	tmp = 0.0;
	if (y <= -1.26e+85)
		tmp = 4.0;
	elseif (y <= -6.4e+18)
		tmp = t_1;
	elseif (y <= -1.4e-7)
		tmp = 4.0;
	elseif (y <= -2.9e-193)
		tmp = t_0;
	elseif (y <= -1.12e-260)
		tmp = t_1;
	elseif (y <= -9.8e-285)
		tmp = t_0;
	elseif (y <= 7e-201)
		tmp = t_1;
	elseif (y <= 4.7e-147)
		tmp = t_0;
	elseif (y <= 290000.0)
		tmp = t_1;
	elseif (y <= 1.15e+54)
		tmp = t_0;
	elseif (y <= 1.95e+62)
		tmp = t_1;
	else
		tmp = 4.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 * -4.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -1.26e+85], 4.0, If[LessEqual[y, -6.4e+18], t$95$1, If[LessEqual[y, -1.4e-7], 4.0, If[LessEqual[y, -2.9e-193], t$95$0, If[LessEqual[y, -1.12e-260], t$95$1, If[LessEqual[y, -9.8e-285], t$95$0, If[LessEqual[y, 7e-201], t$95$1, If[LessEqual[y, 4.7e-147], t$95$0, If[LessEqual[y, 290000.0], t$95$1, If[LessEqual[y, 1.15e+54], t$95$0, If[LessEqual[y, 1.95e+62], t$95$1, 4.0]]]]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -1.4 \cdot 10^{-7}:\\
\;\;\;\;4\\

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

\mathbf{elif}\;y \leq -1.12 \cdot 10^{-260}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -9.8 \cdot 10^{-285}:\\
\;\;\;\;t\_0\\

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

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

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

\mathbf{elif}\;y \leq 1.15 \cdot 10^{+54}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.26000000000000003e85 or -6.4e18 < y < -1.4000000000000001e-7 or 1.95e62 < y

    1. Initial program 99.9%

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

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

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

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

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

    if -1.26000000000000003e85 < y < -6.4e18 or -2.90000000000000007e-193 < y < -1.12000000000000004e-260 or -9.79999999999999949e-285 < y < 7.00000000000000016e-201 or 4.69999999999999989e-147 < y < 2.9e5 or 1.14999999999999997e54 < y < 1.95e62

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{z}{y} \cdot -4} \]
      2. associate-*l/69.8%

        \[\leadsto \color{blue}{\frac{z \cdot -4}{y}} \]
    7. Simplified69.8%

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

    if -1.4000000000000001e-7 < y < -2.90000000000000007e-193 or -1.12000000000000004e-260 < y < -9.79999999999999949e-285 or 7.00000000000000016e-201 < y < 4.69999999999999989e-147 or 2.9e5 < y < 1.14999999999999997e54

    1. Initial program 98.5%

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

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

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

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

      \[\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 -1.26 \cdot 10^{+85}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -6.4 \cdot 10^{+18}:\\ \;\;\;\;\frac{z \cdot -4}{y}\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-7}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-193}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{-260}:\\ \;\;\;\;\frac{z \cdot -4}{y}\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{-285}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-201}:\\ \;\;\;\;\frac{z \cdot -4}{y}\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-147}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 290000:\\ \;\;\;\;\frac{z \cdot -4}{y}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+54}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+62}:\\ \;\;\;\;\frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 53.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := z \cdot \frac{-4}{y}\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+84}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{+19}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-17}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-191}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-261}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-280}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-200}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-146}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 11.6:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+62}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))) (t_1 (* z (/ -4.0 y))))
   (if (<= y -4.8e+84)
     4.0
     (if (<= y -2.75e+19)
       t_1
       (if (<= y -9e-17)
         4.0
         (if (<= y -1.6e-191)
           t_0
           (if (<= y -5.5e-261)
             t_1
             (if (<= y -5.5e-280)
               t_0
               (if (<= y 1.05e-200)
                 t_1
                 (if (<= y 3e-146)
                   t_0
                   (if (<= y 11.6) t_1 (if (<= y 4.5e+62) t_0 4.0))))))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = z * (-4.0 / y);
	double tmp;
	if (y <= -4.8e+84) {
		tmp = 4.0;
	} else if (y <= -2.75e+19) {
		tmp = t_1;
	} else if (y <= -9e-17) {
		tmp = 4.0;
	} else if (y <= -1.6e-191) {
		tmp = t_0;
	} else if (y <= -5.5e-261) {
		tmp = t_1;
	} else if (y <= -5.5e-280) {
		tmp = t_0;
	} else if (y <= 1.05e-200) {
		tmp = t_1;
	} else if (y <= 3e-146) {
		tmp = t_0;
	} else if (y <= 11.6) {
		tmp = t_1;
	} else if (y <= 4.5e+62) {
		tmp = t_0;
	} else {
		tmp = 4.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    t_1 = z * ((-4.0d0) / y)
    if (y <= (-4.8d+84)) then
        tmp = 4.0d0
    else if (y <= (-2.75d+19)) then
        tmp = t_1
    else if (y <= (-9d-17)) then
        tmp = 4.0d0
    else if (y <= (-1.6d-191)) then
        tmp = t_0
    else if (y <= (-5.5d-261)) then
        tmp = t_1
    else if (y <= (-5.5d-280)) then
        tmp = t_0
    else if (y <= 1.05d-200) then
        tmp = t_1
    else if (y <= 3d-146) then
        tmp = t_0
    else if (y <= 11.6d0) then
        tmp = t_1
    else if (y <= 4.5d+62) then
        tmp = t_0
    else
        tmp = 4.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 * (-4.0 / y);
	double tmp;
	if (y <= -4.8e+84) {
		tmp = 4.0;
	} else if (y <= -2.75e+19) {
		tmp = t_1;
	} else if (y <= -9e-17) {
		tmp = 4.0;
	} else if (y <= -1.6e-191) {
		tmp = t_0;
	} else if (y <= -5.5e-261) {
		tmp = t_1;
	} else if (y <= -5.5e-280) {
		tmp = t_0;
	} else if (y <= 1.05e-200) {
		tmp = t_1;
	} else if (y <= 3e-146) {
		tmp = t_0;
	} else if (y <= 11.6) {
		tmp = t_1;
	} else if (y <= 4.5e+62) {
		tmp = t_0;
	} else {
		tmp = 4.0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = z * (-4.0 / y)
	tmp = 0
	if y <= -4.8e+84:
		tmp = 4.0
	elif y <= -2.75e+19:
		tmp = t_1
	elif y <= -9e-17:
		tmp = 4.0
	elif y <= -1.6e-191:
		tmp = t_0
	elif y <= -5.5e-261:
		tmp = t_1
	elif y <= -5.5e-280:
		tmp = t_0
	elif y <= 1.05e-200:
		tmp = t_1
	elif y <= 3e-146:
		tmp = t_0
	elif y <= 11.6:
		tmp = t_1
	elif y <= 4.5e+62:
		tmp = t_0
	else:
		tmp = 4.0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	t_1 = Float64(z * Float64(-4.0 / y))
	tmp = 0.0
	if (y <= -4.8e+84)
		tmp = 4.0;
	elseif (y <= -2.75e+19)
		tmp = t_1;
	elseif (y <= -9e-17)
		tmp = 4.0;
	elseif (y <= -1.6e-191)
		tmp = t_0;
	elseif (y <= -5.5e-261)
		tmp = t_1;
	elseif (y <= -5.5e-280)
		tmp = t_0;
	elseif (y <= 1.05e-200)
		tmp = t_1;
	elseif (y <= 3e-146)
		tmp = t_0;
	elseif (y <= 11.6)
		tmp = t_1;
	elseif (y <= 4.5e+62)
		tmp = t_0;
	else
		tmp = 4.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	t_1 = z * (-4.0 / y);
	tmp = 0.0;
	if (y <= -4.8e+84)
		tmp = 4.0;
	elseif (y <= -2.75e+19)
		tmp = t_1;
	elseif (y <= -9e-17)
		tmp = 4.0;
	elseif (y <= -1.6e-191)
		tmp = t_0;
	elseif (y <= -5.5e-261)
		tmp = t_1;
	elseif (y <= -5.5e-280)
		tmp = t_0;
	elseif (y <= 1.05e-200)
		tmp = t_1;
	elseif (y <= 3e-146)
		tmp = t_0;
	elseif (y <= 11.6)
		tmp = t_1;
	elseif (y <= 4.5e+62)
		tmp = t_0;
	else
		tmp = 4.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[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.8e+84], 4.0, If[LessEqual[y, -2.75e+19], t$95$1, If[LessEqual[y, -9e-17], 4.0, If[LessEqual[y, -1.6e-191], t$95$0, If[LessEqual[y, -5.5e-261], t$95$1, If[LessEqual[y, -5.5e-280], t$95$0, If[LessEqual[y, 1.05e-200], t$95$1, If[LessEqual[y, 3e-146], t$95$0, If[LessEqual[y, 11.6], t$95$1, If[LessEqual[y, 4.5e+62], t$95$0, 4.0]]]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -9 \cdot 10^{-17}:\\
\;\;\;\;4\\

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

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

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

\mathbf{elif}\;y \leq 1.05 \cdot 10^{-200}:\\
\;\;\;\;t\_1\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.7999999999999999e84 or -2.75e19 < y < -8.99999999999999957e-17 or 4.49999999999999999e62 < y

    1. Initial program 99.9%

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

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

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

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

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

    if -4.7999999999999999e84 < y < -2.75e19 or -1.6000000000000002e-191 < y < -5.50000000000000042e-261 or -5.50000000000000001e-280 < y < 1.05e-200 or 3.00000000000000019e-146 < y < 11.5999999999999996

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y}} \]
    6. Step-by-step derivation
      1. *-commutative96.6%

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

      \[\leadsto \color{blue}{\frac{x - z}{y} \cdot 4} \]
    8. Step-by-step derivation
      1. div-sub91.1%

        \[\leadsto \color{blue}{\left(\frac{x}{y} - \frac{z}{y}\right)} \cdot 4 \]
    9. Applied egg-rr91.1%

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

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
    11. Step-by-step derivation
      1. metadata-eval70.2%

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

        \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
      3. *-lft-identity70.2%

        \[\leadsto -4 \cdot \frac{\color{blue}{1 \cdot z}}{y} \]
      4. associate-*l/70.0%

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

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

        \[\leadsto -\color{blue}{z \cdot \left(4 \cdot \frac{1}{y}\right)} \]
      7. distribute-rgt-neg-in70.0%

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

        \[\leadsto z \cdot \left(-\color{blue}{\frac{4 \cdot 1}{y}}\right) \]
      9. metadata-eval70.0%

        \[\leadsto z \cdot \left(-\frac{\color{blue}{4}}{y}\right) \]
      10. distribute-neg-frac70.0%

        \[\leadsto z \cdot \color{blue}{\frac{-4}{y}} \]
      11. metadata-eval70.0%

        \[\leadsto z \cdot \frac{\color{blue}{-4}}{y} \]
    12. Simplified70.0%

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

    if -8.99999999999999957e-17 < y < -1.6000000000000002e-191 or -5.50000000000000042e-261 < y < -5.50000000000000001e-280 or 1.05e-200 < y < 3.00000000000000019e-146 or 11.5999999999999996 < y < 4.49999999999999999e62

    1. Initial program 98.6%

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

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

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

      \[\leadsto \color{blue}{1 + 4 \cdot \frac{x + \left(y \cdot 0.75 - z\right)}{y}} \]
    4. Add Preprocessing
    5. 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 -4.8 \cdot 10^{+84}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{+19}:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-17}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-191}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-261}:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-280}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-200}:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-146}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 11.6:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+62}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.8% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{z}{y} \cdot -4} \]
      2. associate-*l/79.4%

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

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

    if -1.2e40 < z < 1.00000000000000004e-10 or 8e14 < z < 1.7500000000000001e158

    1. Initial program 99.4%

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

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

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

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

      \[\leadsto \color{blue}{\frac{4 \cdot y + 4 \cdot \left(x - z\right)}{y}} \]
    6. Step-by-step derivation
      1. distribute-lft-out99.4%

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

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

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

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

Alternative 5: 84.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+77} \lor \neg \left(y \leq -3.5 \cdot 10^{+20} \lor \neg \left(y \leq -7.5 \cdot 10^{-74}\right) \land y \leq 3.1 \cdot 10^{+56}\right):\\
\;\;\;\;4 \cdot \frac{x + y}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.4500000000000001e77 or -3.5e20 < y < -7.5e-74 or 3.10000000000000005e56 < y

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{\frac{4 \cdot y + 4 \cdot \left(x - z\right)}{y}} \]
    6. Step-by-step derivation
      1. distribute-lft-out99.9%

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

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

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

    if -1.4500000000000001e77 < y < -3.5e20 or -7.5e-74 < y < 3.10000000000000005e56

    1. Initial program 99.3%

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y}} \]
    6. Step-by-step derivation
      1. *-commutative95.9%

        \[\leadsto \color{blue}{\frac{x - z}{y} \cdot 4} \]
    7. Simplified95.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+77} \lor \neg \left(y \leq -3.5 \cdot 10^{+20} \lor \neg \left(y \leq -7.5 \cdot 10^{-74}\right) \land y \leq 3.1 \cdot 10^{+56}\right):\\ \;\;\;\;4 \cdot \frac{x + y}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x + y}{y}\\ t_1 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;y \leq -1.2 \cdot 10^{+77}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -5.6 \cdot 10^{+20}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-75}:\\ \;\;\;\;4 + \frac{4 \cdot x}{y}\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{+59}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ (+ x y) y))) (t_1 (* 4.0 (/ (- x z) y))))
   (if (<= y -1.2e+77)
     t_0
     (if (<= y -5.6e+20)
       t_1
       (if (<= y -6e-75)
         (+ 4.0 (/ (* 4.0 x) y))
         (if (<= y 1.06e+59) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * ((x + y) / y);
	double t_1 = 4.0 * ((x - z) / y);
	double tmp;
	if (y <= -1.2e+77) {
		tmp = t_0;
	} else if (y <= -5.6e+20) {
		tmp = t_1;
	} else if (y <= -6e-75) {
		tmp = 4.0 + ((4.0 * x) / y);
	} else if (y <= 1.06e+59) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * ((x + y) / y)
    t_1 = 4.0d0 * ((x - z) / y)
    if (y <= (-1.2d+77)) then
        tmp = t_0
    else if (y <= (-5.6d+20)) then
        tmp = t_1
    else if (y <= (-6d-75)) then
        tmp = 4.0d0 + ((4.0d0 * x) / y)
    else if (y <= 1.06d+59) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 4.0 * ((x + y) / y);
	double t_1 = 4.0 * ((x - z) / y);
	double tmp;
	if (y <= -1.2e+77) {
		tmp = t_0;
	} else if (y <= -5.6e+20) {
		tmp = t_1;
	} else if (y <= -6e-75) {
		tmp = 4.0 + ((4.0 * x) / y);
	} else if (y <= 1.06e+59) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * ((x + y) / y)
	t_1 = 4.0 * ((x - z) / y)
	tmp = 0
	if y <= -1.2e+77:
		tmp = t_0
	elif y <= -5.6e+20:
		tmp = t_1
	elif y <= -6e-75:
		tmp = 4.0 + ((4.0 * x) / y)
	elif y <= 1.06e+59:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(Float64(x + y) / y))
	t_1 = Float64(4.0 * Float64(Float64(x - z) / y))
	tmp = 0.0
	if (y <= -1.2e+77)
		tmp = t_0;
	elseif (y <= -5.6e+20)
		tmp = t_1;
	elseif (y <= -6e-75)
		tmp = Float64(4.0 + Float64(Float64(4.0 * x) / y));
	elseif (y <= 1.06e+59)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * ((x + y) / y);
	t_1 = 4.0 * ((x - z) / y);
	tmp = 0.0;
	if (y <= -1.2e+77)
		tmp = t_0;
	elseif (y <= -5.6e+20)
		tmp = t_1;
	elseif (y <= -6e-75)
		tmp = 4.0 + ((4.0 * x) / y);
	elseif (y <= 1.06e+59)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.2e+77], t$95$0, If[LessEqual[y, -5.6e+20], t$95$1, If[LessEqual[y, -6e-75], N[(4.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.06e+59], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -6 \cdot 10^{-75}:\\
\;\;\;\;4 + \frac{4 \cdot x}{y}\\

\mathbf{elif}\;y \leq 1.06 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.1999999999999999e77 or 1.0600000000000001e59 < y

    1. Initial program 99.9%

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

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

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

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

      \[\leadsto \color{blue}{\frac{4 \cdot y + 4 \cdot \left(x - z\right)}{y}} \]
    6. Step-by-step derivation
      1. distribute-lft-out99.9%

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

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

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

    if -1.1999999999999999e77 < y < -5.6e20 or -5.9999999999999997e-75 < y < 1.0600000000000001e59

    1. Initial program 99.3%

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y}} \]
    6. Step-by-step derivation
      1. *-commutative95.9%

        \[\leadsto \color{blue}{\frac{x - z}{y} \cdot 4} \]
    7. Simplified95.9%

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

    if -5.6e20 < y < -5.9999999999999997e-75

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\frac{y \cdot 0.75}{y} - \frac{z + \left(-x\right)}{y}}, 1\right) \]
      10. sub-neg99.9%

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{0.75} + \left(-\frac{z + \left(-x\right)}{y}\right), 1\right) \]
      14. distribute-frac-neg2100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{z + \left(-x\right)}{-y}}, 1\right) \]
      15. remove-double-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{\left(-\left(-z\right)\right)} + \left(-x\right)}{-y}, 1\right) \]
      16. distribute-neg-out100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{-\left(\left(-z\right) + x\right)}}{-y}, 1\right) \]
      17. +-commutative100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x + \left(-z\right)\right)}}{-y}, 1\right) \]
      18. sub-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x - z\right)}}{-y}, 1\right) \]
      19. distribute-frac-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\left(-\frac{x - z}{-y}\right)}, 1\right) \]
      20. distribute-frac-neg2100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{x - z}{-\left(-y\right)}}, 1\right) \]
      21. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{1 + 4 \cdot \left(0.75 + \frac{x}{y}\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in89.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{+77}:\\ \;\;\;\;4 \cdot \frac{x + y}{y}\\ \mathbf{elif}\;y \leq -5.6 \cdot 10^{+20}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-75}:\\ \;\;\;\;4 + \frac{4 \cdot x}{y}\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{+59}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x + y}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 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):\\ \;\;\;\;4 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x + y}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -9.8e+39) (not (<= z 7.8e-17)))
   (+ 4.0 (/ (* z -4.0) y))
   (* 4.0 (/ (+ x y) y))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -9.8e+39) || !(z <= 7.8e-17)) {
		tmp = 4.0 + ((z * -4.0) / y);
	} else {
		tmp = 4.0 * ((x + y) / 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 = 4.0d0 + ((z * (-4.0d0)) / y)
    else
        tmp = 4.0d0 * ((x + y) / 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 = 4.0 + ((z * -4.0) / y);
	} else {
		tmp = 4.0 * ((x + y) / y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -9.8e+39) or not (z <= 7.8e-17):
		tmp = 4.0 + ((z * -4.0) / y)
	else:
		tmp = 4.0 * ((x + y) / y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -9.8e+39) || !(z <= 7.8e-17))
		tmp = Float64(4.0 + Float64(Float64(z * -4.0) / y));
	else
		tmp = Float64(4.0 * Float64(Float64(x + y) / 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 = 4.0 + ((z * -4.0) / y);
	else
		tmp = 4.0 * ((x + y) / 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[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x + y), $MachinePrecision] / y), $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):\\
\;\;\;\;4 + \frac{z \cdot -4}{y}\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x + y}{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.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \frac{\color{blue}{y \cdot 0.75 - \left(z + \left(-x\right)\right)}}{y}, 1\right) \]
      9. div-sub100.0%

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{\frac{y \cdot 0.75}{y} - \frac{z + \left(-x\right)}{y}}, 1\right) \]
      10. sub-neg100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(4, \color{blue}{0.75} + \left(-\frac{z + \left(-x\right)}{y}\right), 1\right) \]
      14. distribute-frac-neg2100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{z + \left(-x\right)}{-y}}, 1\right) \]
      15. remove-double-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{\left(-\left(-z\right)\right)} + \left(-x\right)}{-y}, 1\right) \]
      16. distribute-neg-out100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{\color{blue}{-\left(\left(-z\right) + x\right)}}{-y}, 1\right) \]
      17. +-commutative100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x + \left(-z\right)\right)}}{-y}, 1\right) \]
      18. sub-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \frac{-\color{blue}{\left(x - z\right)}}{-y}, 1\right) \]
      19. distribute-frac-neg100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\left(-\frac{x - z}{-y}\right)}, 1\right) \]
      20. distribute-frac-neg2100.0%

        \[\leadsto \mathsf{fma}\left(4, 0.75 + \color{blue}{\frac{x - z}{-\left(-y\right)}}, 1\right) \]
      21. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{1 + 4 \cdot \left(0.75 - \frac{z}{y}\right)} \]
    6. Step-by-step derivation
      1. sub-neg91.2%

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

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

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

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

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

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

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

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

        \[\leadsto 4 + \color{blue}{\frac{z}{y} \cdot -4} \]
      10. associate-*l/91.2%

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

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

    if -9.79999999999999974e39 < z < 7.79999999999999979e-17

    1. Initial program 99.3%

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

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

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

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

      \[\leadsto \color{blue}{\frac{4 \cdot y + 4 \cdot \left(x - z\right)}{y}} \]
    6. Step-by-step derivation
      1. distribute-lft-out99.3%

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x + y}{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):\\ \;\;\;\;4 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x + y}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 53.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-7}:\\
\;\;\;\;4\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.55e-7 or 5.50000000000000036e61 < y

    1. Initial program 99.9%

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

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

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

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

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

    if -1.55e-7 < y < 5.50000000000000036e61

    1. Initial program 99.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{-7}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+61}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 99.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 10: 99.8% accurate, 1.4× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{4 \cdot y + 4 \cdot \left(x - z\right)}{y}} \]
  6. Step-by-step derivation
    1. distribute-lft-out99.6%

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

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

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

Alternative 11: 34.6% accurate, 13.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto 4 \]
  7. 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, A"
  :precision binary64
  (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))