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

Percentage Accurate: 99.8% → 99.9%
Time: 5.9s
Alternatives: 6
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 6 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: 99.9% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
    17. distribute-rgt-neg-in99.7%

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

      \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
    19. metadata-eval99.7%

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

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

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

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

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

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

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

Alternative 2: 56.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y} + 1\\ t_1 := 1 + \frac{z \cdot -4}{y}\\ \mathbf{if}\;z \leq -17500000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-145}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-152}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+84}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (* 4.0 (/ x y)) 1.0)) (t_1 (+ 1.0 (/ (* z -4.0) y))))
   (if (<= z -17500000000000.0)
     t_1
     (if (<= z -1.4e-41)
       t_0
       (if (<= z -7e-145)
         4.0
         (if (<= z 1.06e-301)
           t_0
           (if (<= z 4e-152) 4.0 (if (<= z 1.45e+84) t_0 t_1))))))))
double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + ((z * -4.0) / y);
	double tmp;
	if (z <= -17500000000000.0) {
		tmp = t_1;
	} else if (z <= -1.4e-41) {
		tmp = t_0;
	} else if (z <= -7e-145) {
		tmp = 4.0;
	} else if (z <= 1.06e-301) {
		tmp = t_0;
	} else if (z <= 4e-152) {
		tmp = 4.0;
	} else if (z <= 1.45e+84) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (4.0d0 * (x / y)) + 1.0d0
    t_1 = 1.0d0 + ((z * (-4.0d0)) / y)
    if (z <= (-17500000000000.0d0)) then
        tmp = t_1
    else if (z <= (-1.4d-41)) then
        tmp = t_0
    else if (z <= (-7d-145)) then
        tmp = 4.0d0
    else if (z <= 1.06d-301) then
        tmp = t_0
    else if (z <= 4d-152) then
        tmp = 4.0d0
    else if (z <= 1.45d+84) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (4.0 * (x / y)) + 1.0;
	double t_1 = 1.0 + ((z * -4.0) / y);
	double tmp;
	if (z <= -17500000000000.0) {
		tmp = t_1;
	} else if (z <= -1.4e-41) {
		tmp = t_0;
	} else if (z <= -7e-145) {
		tmp = 4.0;
	} else if (z <= 1.06e-301) {
		tmp = t_0;
	} else if (z <= 4e-152) {
		tmp = 4.0;
	} else if (z <= 1.45e+84) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (4.0 * (x / y)) + 1.0
	t_1 = 1.0 + ((z * -4.0) / y)
	tmp = 0
	if z <= -17500000000000.0:
		tmp = t_1
	elif z <= -1.4e-41:
		tmp = t_0
	elif z <= -7e-145:
		tmp = 4.0
	elif z <= 1.06e-301:
		tmp = t_0
	elif z <= 4e-152:
		tmp = 4.0
	elif z <= 1.45e+84:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(4.0 * Float64(x / y)) + 1.0)
	t_1 = Float64(1.0 + Float64(Float64(z * -4.0) / y))
	tmp = 0.0
	if (z <= -17500000000000.0)
		tmp = t_1;
	elseif (z <= -1.4e-41)
		tmp = t_0;
	elseif (z <= -7e-145)
		tmp = 4.0;
	elseif (z <= 1.06e-301)
		tmp = t_0;
	elseif (z <= 4e-152)
		tmp = 4.0;
	elseif (z <= 1.45e+84)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (4.0 * (x / y)) + 1.0;
	t_1 = 1.0 + ((z * -4.0) / y);
	tmp = 0.0;
	if (z <= -17500000000000.0)
		tmp = t_1;
	elseif (z <= -1.4e-41)
		tmp = t_0;
	elseif (z <= -7e-145)
		tmp = 4.0;
	elseif (z <= 1.06e-301)
		tmp = t_0;
	elseif (z <= 4e-152)
		tmp = 4.0;
	elseif (z <= 1.45e+84)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -17500000000000.0], t$95$1, If[LessEqual[z, -1.4e-41], t$95$0, If[LessEqual[z, -7e-145], 4.0, If[LessEqual[z, 1.06e-301], t$95$0, If[LessEqual[z, 4e-152], 4.0, If[LessEqual[z, 1.45e+84], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -1.4 \cdot 10^{-41}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -7 \cdot 10^{-145}:\\
\;\;\;\;4\\

\mathbf{elif}\;z \leq 1.06 \cdot 10^{-301}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 1.45 \cdot 10^{+84}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.75e13 or 1.44999999999999994e84 < z

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75e13 < z < -1.4000000000000001e-41 or -6.99999999999999994e-145 < z < 1.06e-301 or 4.00000000000000026e-152 < z < 1.44999999999999994e84

    1. Initial program 98.7%

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

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

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

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

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

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

    if -1.4000000000000001e-41 < z < -6.99999999999999994e-145 or 1.06e-301 < z < 4.00000000000000026e-152

    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/99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
      17. distribute-rgt-neg-in99.6%

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

        \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
      19. metadata-eval99.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -17500000000000:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-41}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-145}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-152}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+84}:\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 77.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -17500000000000 \lor \neg \left(z \leq 3 \cdot 10^{+84} \lor \neg \left(z \leq 1.52 \cdot 10^{+147}\right) \land z \leq 1.18 \cdot 10^{+210}\right):\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -17500000000000.0)
         (not (or (<= z 3e+84) (and (not (<= z 1.52e+147)) (<= z 1.18e+210)))))
   (+ 1.0 (/ (* z -4.0) y))
   (+ 4.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -17500000000000.0) || !((z <= 3e+84) || (!(z <= 1.52e+147) && (z <= 1.18e+210)))) {
		tmp = 1.0 + ((z * -4.0) / y);
	} else {
		tmp = 4.0 + (4.0 * (x / y));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-17500000000000.0d0)) .or. (.not. (z <= 3d+84) .or. (.not. (z <= 1.52d+147)) .and. (z <= 1.18d+210))) then
        tmp = 1.0d0 + ((z * (-4.0d0)) / y)
    else
        tmp = 4.0d0 + (4.0d0 * (x / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -17500000000000.0) || !((z <= 3e+84) || (!(z <= 1.52e+147) && (z <= 1.18e+210)))) {
		tmp = 1.0 + ((z * -4.0) / y);
	} else {
		tmp = 4.0 + (4.0 * (x / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -17500000000000.0) or not ((z <= 3e+84) or (not (z <= 1.52e+147) and (z <= 1.18e+210))):
		tmp = 1.0 + ((z * -4.0) / y)
	else:
		tmp = 4.0 + (4.0 * (x / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -17500000000000.0) || !((z <= 3e+84) || (!(z <= 1.52e+147) && (z <= 1.18e+210))))
		tmp = Float64(1.0 + Float64(Float64(z * -4.0) / y));
	else
		tmp = Float64(4.0 + Float64(4.0 * Float64(x / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -17500000000000.0) || ~(((z <= 3e+84) || (~((z <= 1.52e+147)) && (z <= 1.18e+210)))))
		tmp = 1.0 + ((z * -4.0) / y);
	else
		tmp = 4.0 + (4.0 * (x / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -17500000000000.0], N[Not[Or[LessEqual[z, 3e+84], And[N[Not[LessEqual[z, 1.52e+147]], $MachinePrecision], LessEqual[z, 1.18e+210]]]], $MachinePrecision]], N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -17500000000000 \lor \neg \left(z \leq 3 \cdot 10^{+84} \lor \neg \left(z \leq 1.52 \cdot 10^{+147}\right) \land z \leq 1.18 \cdot 10^{+210}\right):\\
\;\;\;\;1 + \frac{z \cdot -4}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.75e13 or 2.99999999999999996e84 < z < 1.51999999999999992e147 or 1.18e210 < z

    1. Initial program 99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75e13 < z < 2.99999999999999996e84 or 1.51999999999999992e147 < z < 1.18e210

    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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
      17. distribute-rgt-neg-in99.7%

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

        \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
      19. metadata-eval99.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -17500000000000 \lor \neg \left(z \leq 3 \cdot 10^{+84} \lor \neg \left(z \leq 1.52 \cdot 10^{+147}\right) \land z \leq 1.18 \cdot 10^{+210}\right):\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 55.5% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+42} \lor \neg \left(x \leq 11800000\right):\\
\;\;\;\;4 \cdot \frac{x}{y} + 1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.25000000000000002e42 or 1.18e7 < x

    1. Initial program 99.2%

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

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

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

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

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

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

    if -1.25000000000000002e42 < x < 1.18e7

    1. Initial program 99.2%

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

        \[\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}{\frac{4}{y} \cdot \left(\left(x + y \cdot 0.75\right) - z\right)} + 1 \]
      3. *-commutative99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
      17. distribute-rgt-neg-in99.7%

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

        \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
      19. metadata-eval99.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+42} \lor \neg \left(x \leq 11800000\right):\\ \;\;\;\;4 \cdot \frac{x}{y} + 1\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 85.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{+52} \lor \neg \left(x \leq 4.5 \cdot 10^{+155}\right):\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.12000000000000002e52 or 4.49999999999999973e155 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
      17. distribute-rgt-neg-in99.6%

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

        \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
      19. metadata-eval99.7%

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

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

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

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

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

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

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

    if -1.12000000000000002e52 < x < 4.49999999999999973e155

    1. Initial program 98.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative98.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}{\frac{4}{y} \cdot \left(\left(x + y \cdot 0.75\right) - z\right)} + 1 \]
      3. *-commutative99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
      17. distribute-rgt-neg-in99.7%

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

        \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
      19. metadata-eval99.7%

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

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

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

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

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

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

      \[\leadsto 4 + \color{blue}{-4 \cdot \frac{z}{y}} \]
    9. Step-by-step derivation
      1. metadata-eval87.8%

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

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

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

        \[\leadsto 4 + \left(-\color{blue}{\frac{4}{y} \cdot z}\right) \]
      5. *-commutative87.8%

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

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

        \[\leadsto 4 + z \cdot \color{blue}{\frac{-4}{y}} \]
      8. metadata-eval87.8%

        \[\leadsto 4 + z \cdot \frac{\color{blue}{-4}}{y} \]
    10. Simplified87.8%

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

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

Alternative 6: 34.4% 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.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x - \left(\color{blue}{\left(-y \cdot 0.75\right)} - \left(-z\right)\right), \frac{4}{y}, 1\right) \]
    17. distribute-rgt-neg-in99.7%

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

      \[\leadsto \mathsf{fma}\left(x - \color{blue}{\mathsf{fma}\left(y, -0.75, -\left(-z\right)\right)}, \frac{4}{y}, 1\right) \]
    19. metadata-eval99.7%

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

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

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

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

    \[\leadsto 4 \]
  7. Add Preprocessing

Reproduce

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