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

Percentage Accurate: 99.8% → 99.9%
Time: 5.2s
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.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 \color{blue}{4 + 4 \cdot \frac{x - z}{y}} \]
  5. Step-by-step derivation
    1. associate-*r/100.0%

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

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

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

Alternative 2: 57.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{z}{y} \cdot -4\\ t_1 := 1 + 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -2.8 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-256}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-291}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-265}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-215}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+51}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+52}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* (/ z y) -4.0))) (t_1 (+ 1.0 (* 4.0 (/ x y)))))
   (if (<= x -2.8e-10)
     t_1
     (if (<= x -2e-256)
       t_0
       (if (<= x -3.5e-291)
         4.0
         (if (<= x 8.2e-265)
           t_0
           (if (<= x 1.6e-215)
             4.0
             (if (<= x 1.06e+24)
               t_0
               (if (<= x 1.55e+51) 4.0 (if (<= x 6e+52) t_0 t_1))))))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + ((z / y) * -4.0);
	double t_1 = 1.0 + (4.0 * (x / y));
	double tmp;
	if (x <= -2.8e-10) {
		tmp = t_1;
	} else if (x <= -2e-256) {
		tmp = t_0;
	} else if (x <= -3.5e-291) {
		tmp = 4.0;
	} else if (x <= 8.2e-265) {
		tmp = t_0;
	} else if (x <= 1.6e-215) {
		tmp = 4.0;
	} else if (x <= 1.06e+24) {
		tmp = t_0;
	} else if (x <= 1.55e+51) {
		tmp = 4.0;
	} else if (x <= 6e+52) {
		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 / y) * (-4.0d0))
    t_1 = 1.0d0 + (4.0d0 * (x / y))
    if (x <= (-2.8d-10)) then
        tmp = t_1
    else if (x <= (-2d-256)) then
        tmp = t_0
    else if (x <= (-3.5d-291)) then
        tmp = 4.0d0
    else if (x <= 8.2d-265) then
        tmp = t_0
    else if (x <= 1.6d-215) then
        tmp = 4.0d0
    else if (x <= 1.06d+24) then
        tmp = t_0
    else if (x <= 1.55d+51) then
        tmp = 4.0d0
    else if (x <= 6d+52) 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 / y) * -4.0);
	double t_1 = 1.0 + (4.0 * (x / y));
	double tmp;
	if (x <= -2.8e-10) {
		tmp = t_1;
	} else if (x <= -2e-256) {
		tmp = t_0;
	} else if (x <= -3.5e-291) {
		tmp = 4.0;
	} else if (x <= 8.2e-265) {
		tmp = t_0;
	} else if (x <= 1.6e-215) {
		tmp = 4.0;
	} else if (x <= 1.06e+24) {
		tmp = t_0;
	} else if (x <= 1.55e+51) {
		tmp = 4.0;
	} else if (x <= 6e+52) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + ((z / y) * -4.0)
	t_1 = 1.0 + (4.0 * (x / y))
	tmp = 0
	if x <= -2.8e-10:
		tmp = t_1
	elif x <= -2e-256:
		tmp = t_0
	elif x <= -3.5e-291:
		tmp = 4.0
	elif x <= 8.2e-265:
		tmp = t_0
	elif x <= 1.6e-215:
		tmp = 4.0
	elif x <= 1.06e+24:
		tmp = t_0
	elif x <= 1.55e+51:
		tmp = 4.0
	elif x <= 6e+52:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(Float64(z / y) * -4.0))
	t_1 = Float64(1.0 + Float64(4.0 * Float64(x / y)))
	tmp = 0.0
	if (x <= -2.8e-10)
		tmp = t_1;
	elseif (x <= -2e-256)
		tmp = t_0;
	elseif (x <= -3.5e-291)
		tmp = 4.0;
	elseif (x <= 8.2e-265)
		tmp = t_0;
	elseif (x <= 1.6e-215)
		tmp = 4.0;
	elseif (x <= 1.06e+24)
		tmp = t_0;
	elseif (x <= 1.55e+51)
		tmp = 4.0;
	elseif (x <= 6e+52)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + ((z / y) * -4.0);
	t_1 = 1.0 + (4.0 * (x / y));
	tmp = 0.0;
	if (x <= -2.8e-10)
		tmp = t_1;
	elseif (x <= -2e-256)
		tmp = t_0;
	elseif (x <= -3.5e-291)
		tmp = 4.0;
	elseif (x <= 8.2e-265)
		tmp = t_0;
	elseif (x <= 1.6e-215)
		tmp = 4.0;
	elseif (x <= 1.06e+24)
		tmp = t_0;
	elseif (x <= 1.55e+51)
		tmp = 4.0;
	elseif (x <= 6e+52)
		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 / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.8e-10], t$95$1, If[LessEqual[x, -2e-256], t$95$0, If[LessEqual[x, -3.5e-291], 4.0, If[LessEqual[x, 8.2e-265], t$95$0, If[LessEqual[x, 1.6e-215], 4.0, If[LessEqual[x, 1.06e+24], t$95$0, If[LessEqual[x, 1.55e+51], 4.0, If[LessEqual[x, 6e+52], t$95$0, t$95$1]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -2 \cdot 10^{-256}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -3.5 \cdot 10^{-291}:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 8.2 \cdot 10^{-265}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{-215}:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 1.06 \cdot 10^{+24}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.55 \cdot 10^{+51}:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 6 \cdot 10^{+52}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.80000000000000015e-10 or 6e52 < x

    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 x around inf 70.9%

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

    if -2.80000000000000015e-10 < x < -1.99999999999999995e-256 or -3.49999999999999996e-291 < x < 8.2e-265 or 1.6000000000000001e-215 < x < 1.06e24 or 1.55000000000000006e51 < x < 6e52

    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 z around inf 65.2%

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

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

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

    if -1.99999999999999995e-256 < x < -3.49999999999999996e-291 or 8.2e-265 < x < 1.6000000000000001e-215 or 1.06e24 < x < 1.55000000000000006e51

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{-10}:\\ \;\;\;\;1 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-256}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-291}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-265}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-215}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+24}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+51}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+52}:\\ \;\;\;\;1 + \frac{z}{y} \cdot -4\\ \mathbf{else}:\\ \;\;\;\;1 + 4 \cdot \frac{x}{y}\\ \end{array} \]

Alternative 3: 54.2% accurate, 1.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.40000000000000006e75 or 3.49999999999999977e68 < 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 inf 69.6%

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

    if -1.40000000000000006e75 < y < 3.49999999999999977e68

    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 49.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{+75}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+68}:\\ \;\;\;\;1 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 4: 53.1% accurate, 1.4× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.00000000000000029e74 or 3.2500000000000002e68 < 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 inf 69.6%

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

    if -7.00000000000000029e74 < y < 3.2500000000000002e68

    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 49.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7 \cdot 10^{+74}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 3.25 \cdot 10^{+68}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 5: 7.5% accurate, 13.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 99.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 x around inf 40.8%

    \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]
  5. Taylor expanded in x around 0 7.5%

    \[\leadsto \color{blue}{1} \]
  6. Final simplification7.5%

    \[\leadsto 1 \]

Alternative 6: 33.5% 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.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 inf 33.1%

    \[\leadsto \color{blue}{4} \]
  5. Final simplification33.1%

    \[\leadsto 4 \]

Reproduce

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