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

Percentage Accurate: 99.8% → 100.0%
Time: 5.9s
Alternatives: 9
Speedup: 1.2×

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 9 alternatives:

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

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 57.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{z \cdot -4}{y}\\ t_1 := 1 + \frac{4 \cdot x}{y}\\ \mathbf{if}\;x \leq -6 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-271}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-181}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 210:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ (* z -4.0) y))) (t_1 (+ 1.0 (/ (* 4.0 x) y))))
   (if (<= x -6e-5)
     t_1
     (if (<= x 5.6e-271)
       t_0
       (if (<= x 5.8e-181) 4.0 (if (<= x 210.0) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + ((z * -4.0) / y);
	double t_1 = 1.0 + ((4.0 * x) / y);
	double tmp;
	if (x <= -6e-5) {
		tmp = t_1;
	} else if (x <= 5.6e-271) {
		tmp = t_0;
	} else if (x <= 5.8e-181) {
		tmp = 4.0;
	} else if (x <= 210.0) {
		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 = 1.0d0 + ((z * (-4.0d0)) / y)
    t_1 = 1.0d0 + ((4.0d0 * x) / y)
    if (x <= (-6d-5)) then
        tmp = t_1
    else if (x <= 5.6d-271) then
        tmp = t_0
    else if (x <= 5.8d-181) then
        tmp = 4.0d0
    else if (x <= 210.0d0) 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 = 1.0 + ((z * -4.0) / y);
	double t_1 = 1.0 + ((4.0 * x) / y);
	double tmp;
	if (x <= -6e-5) {
		tmp = t_1;
	} else if (x <= 5.6e-271) {
		tmp = t_0;
	} else if (x <= 5.8e-181) {
		tmp = 4.0;
	} else if (x <= 210.0) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + ((z * -4.0) / y)
	t_1 = 1.0 + ((4.0 * x) / y)
	tmp = 0
	if x <= -6e-5:
		tmp = t_1
	elif x <= 5.6e-271:
		tmp = t_0
	elif x <= 5.8e-181:
		tmp = 4.0
	elif x <= 210.0:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(Float64(z * -4.0) / y))
	t_1 = Float64(1.0 + Float64(Float64(4.0 * x) / y))
	tmp = 0.0
	if (x <= -6e-5)
		tmp = t_1;
	elseif (x <= 5.6e-271)
		tmp = t_0;
	elseif (x <= 5.8e-181)
		tmp = 4.0;
	elseif (x <= 210.0)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + ((z * -4.0) / y);
	t_1 = 1.0 + ((4.0 * x) / y);
	tmp = 0.0;
	if (x <= -6e-5)
		tmp = t_1;
	elseif (x <= 5.6e-271)
		tmp = t_0;
	elseif (x <= 5.8e-181)
		tmp = 4.0;
	elseif (x <= 210.0)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e-5], t$95$1, If[LessEqual[x, 5.6e-271], t$95$0, If[LessEqual[x, 5.8e-181], 4.0, If[LessEqual[x, 210.0], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 5.6 \cdot 10^{-271}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 5.8 \cdot 10^{-181}:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 210:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.00000000000000015e-5 or 210 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-*l/99.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. Taylor expanded in x around inf 65.5%

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

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

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

    if -6.00000000000000015e-5 < x < 5.5999999999999995e-271 or 5.7999999999999996e-181 < x < 210

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 5.5999999999999995e-271 < x < 5.7999999999999996e-181

    1. Initial program 99.9%

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

        \[\leadsto 1 + \color{blue}{\frac{4}{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. Taylor expanded in y around 0 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{-5}:\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-271}:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-181}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 210:\\ \;\;\;\;1 + \frac{z \cdot -4}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \end{array} \]

Alternative 3: 84.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \left(3 + -4 \cdot \frac{z}{y}\right)\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{+105}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 2.85 \cdot 10^{+166}:\\ \;\;\;\;1 + 4 \cdot \frac{x - z}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (+ 3.0 (* -4.0 (/ z y))))))
   (if (<= y -4.8e+235)
     t_0
     (if (<= y -1.3e+105)
       (+ 4.0 (* 4.0 (/ x y)))
       (if (<= y 2.85e+166) (+ 1.0 (* 4.0 (/ (- x z) y))) t_0)))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + (3.0 + (-4.0 * (z / y)));
	double tmp;
	if (y <= -4.8e+235) {
		tmp = t_0;
	} else if (y <= -1.3e+105) {
		tmp = 4.0 + (4.0 * (x / y));
	} else if (y <= 2.85e+166) {
		tmp = 1.0 + (4.0 * ((x - z) / y));
	} 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) :: tmp
    t_0 = 1.0d0 + (3.0d0 + ((-4.0d0) * (z / y)))
    if (y <= (-4.8d+235)) then
        tmp = t_0
    else if (y <= (-1.3d+105)) then
        tmp = 4.0d0 + (4.0d0 * (x / y))
    else if (y <= 2.85d+166) then
        tmp = 1.0d0 + (4.0d0 * ((x - z) / y))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 1.0 + (3.0 + (-4.0 * (z / y)));
	double tmp;
	if (y <= -4.8e+235) {
		tmp = t_0;
	} else if (y <= -1.3e+105) {
		tmp = 4.0 + (4.0 * (x / y));
	} else if (y <= 2.85e+166) {
		tmp = 1.0 + (4.0 * ((x - z) / y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + (3.0 + (-4.0 * (z / y)))
	tmp = 0
	if y <= -4.8e+235:
		tmp = t_0
	elif y <= -1.3e+105:
		tmp = 4.0 + (4.0 * (x / y))
	elif y <= 2.85e+166:
		tmp = 1.0 + (4.0 * ((x - z) / y))
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(3.0 + Float64(-4.0 * Float64(z / y))))
	tmp = 0.0
	if (y <= -4.8e+235)
		tmp = t_0;
	elseif (y <= -1.3e+105)
		tmp = Float64(4.0 + Float64(4.0 * Float64(x / y)));
	elseif (y <= 2.85e+166)
		tmp = Float64(1.0 + Float64(4.0 * Float64(Float64(x - z) / y)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + (3.0 + (-4.0 * (z / y)));
	tmp = 0.0;
	if (y <= -4.8e+235)
		tmp = t_0;
	elseif (y <= -1.3e+105)
		tmp = 4.0 + (4.0 * (x / y));
	elseif (y <= 2.85e+166)
		tmp = 1.0 + (4.0 * ((x - z) / y));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(3.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.8e+235], t$95$0, If[LessEqual[y, -1.3e+105], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.85e+166], N[(1.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \left(3 + -4 \cdot \frac{z}{y}\right)\\
\mathbf{if}\;y \leq -4.8 \cdot 10^{+235}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y \leq 2.85 \cdot 10^{+166}:\\
\;\;\;\;1 + 4 \cdot \frac{x - z}{y}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.7999999999999998e235 or 2.84999999999999989e166 < 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.7%

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

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

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

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

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

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

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

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

    if -4.7999999999999998e235 < y < -1.3000000000000001e105

    1. Initial program 99.9%

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

        \[\leadsto 1 + \color{blue}{\frac{4}{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.9%

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

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

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

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

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

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

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

    if -1.3000000000000001e105 < y < 2.84999999999999989e166

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{+235}:\\ \;\;\;\;1 + \left(3 + -4 \cdot \frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{+105}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 2.85 \cdot 10^{+166}:\\ \;\;\;\;1 + 4 \cdot \frac{x - z}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(3 + -4 \cdot \frac{z}{y}\right)\\ \end{array} \]

Alternative 4: 86.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-14} \lor \neg \left(z \leq 25500000\right):\\
\;\;\;\;1 + 4 \cdot \frac{x - z}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.4999999999999998e-14 or 2.55e7 < 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/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.7%

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

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

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

    if -4.4999999999999998e-14 < z < 2.55e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 81.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{+96} \lor \neg \left(z \leq 3.4 \cdot 10^{+137}\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 -1.05e+96) (not (<= z 3.4e+137)))
   (+ 1.0 (/ (* z -4.0) y))
   (+ 4.0 (* 4.0 (/ x y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.05e+96) || !(z <= 3.4e+137)) {
		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 <= (-1.05d+96)) .or. (.not. (z <= 3.4d+137))) 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 <= -1.05e+96) || !(z <= 3.4e+137)) {
		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 <= -1.05e+96) or not (z <= 3.4e+137):
		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 <= -1.05e+96) || !(z <= 3.4e+137))
		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 <= -1.05e+96) || ~((z <= 3.4e+137)))
		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, -1.05e+96], N[Not[LessEqual[z, 3.4e+137]], $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 -1.05 \cdot 10^{+96} \lor \neg \left(z \leq 3.4 \cdot 10^{+137}\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.0500000000000001e96 or 3.39999999999999986e137 < 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/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. Taylor expanded in z around inf 75.4%

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

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

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

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

    if -1.0500000000000001e96 < z < 3.39999999999999986e137

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 52.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+103}:\\
\;\;\;\;4\\

\mathbf{elif}\;y \leq 2.15 \cdot 10^{+166}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.6000000000000002e103 or 2.15e166 < 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.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. Taylor expanded in y around 0 100.0%

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

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

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

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

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

    if -2.6000000000000002e103 < y < 2.15e166

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+103}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{+166}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 7: 52.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+103}:\\
\;\;\;\;4\\

\mathbf{elif}\;y \leq 2.15 \cdot 10^{+166}:\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -6.50000000000000001e103 or 2.15e166 < 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.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. Taylor expanded in y around 0 100.0%

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

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

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

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

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

    if -6.50000000000000001e103 < y < 2.15e166

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+103}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{+166}:\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 8: 52.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{+61}:\\
\;\;\;\;4\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.90000000000000025e61 or 1.95e49 < 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.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. Taylor expanded in y around 0 100.0%

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

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

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

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

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

    if -4.90000000000000025e61 < y < 1.95e49

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+61}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+49}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 9: 33.1% 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 100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto 4 \]

Reproduce

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