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

Percentage Accurate: 99.9% → 100.0%
Time: 4.9s
Alternatives: 7
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 57.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + 4 \cdot \frac{x}{y}\\ t_1 := 1 + -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -1.2 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-286}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 30000000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* 4.0 (/ x y)))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
   (if (<= z -1.2e+49)
     t_1
     (if (<= z -6e-142)
       t_0
       (if (<= z 2.1e-286) 2.0 (if (<= z 30000000000000.0) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + (4.0 * (x / y));
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -1.2e+49) {
		tmp = t_1;
	} else if (z <= -6e-142) {
		tmp = t_0;
	} else if (z <= 2.1e-286) {
		tmp = 2.0;
	} else if (z <= 30000000000000.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 + (4.0d0 * (x / y))
    t_1 = 1.0d0 + ((-4.0d0) * (z / y))
    if (z <= (-1.2d+49)) then
        tmp = t_1
    else if (z <= (-6d-142)) then
        tmp = t_0
    else if (z <= 2.1d-286) then
        tmp = 2.0d0
    else if (z <= 30000000000000.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 + (4.0 * (x / y));
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -1.2e+49) {
		tmp = t_1;
	} else if (z <= -6e-142) {
		tmp = t_0;
	} else if (z <= 2.1e-286) {
		tmp = 2.0;
	} else if (z <= 30000000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + (4.0 * (x / y))
	t_1 = 1.0 + (-4.0 * (z / y))
	tmp = 0
	if z <= -1.2e+49:
		tmp = t_1
	elif z <= -6e-142:
		tmp = t_0
	elif z <= 2.1e-286:
		tmp = 2.0
	elif z <= 30000000000000.0:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(4.0 * Float64(x / y)))
	t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y)))
	tmp = 0.0
	if (z <= -1.2e+49)
		tmp = t_1;
	elseif (z <= -6e-142)
		tmp = t_0;
	elseif (z <= 2.1e-286)
		tmp = 2.0;
	elseif (z <= 30000000000000.0)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + (4.0 * (x / y));
	t_1 = 1.0 + (-4.0 * (z / y));
	tmp = 0.0;
	if (z <= -1.2e+49)
		tmp = t_1;
	elseif (z <= -6e-142)
		tmp = t_0;
	elseif (z <= 2.1e-286)
		tmp = 2.0;
	elseif (z <= 30000000000000.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[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.2e+49], t$95$1, If[LessEqual[z, -6e-142], t$95$0, If[LessEqual[z, 2.1e-286], 2.0, If[LessEqual[z, 30000000000000.0], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -6 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 2.1 \cdot 10^{-286}:\\
\;\;\;\;2\\

\mathbf{elif}\;z \leq 30000000000000:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.2e49 < z < -6.0000000000000002e-142 or 2.09999999999999988e-286 < z < 3e13

    1. Initial program 100.0%

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

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

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

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

    if -6.0000000000000002e-142 < z < 2.09999999999999988e-286

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+49}:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-142}:\\ \;\;\;\;1 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-286}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 30000000000000:\\ \;\;\;\;1 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \end{array} \]

Alternative 3: 52.4% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+127} \lor \neg \left(x \leq 3.4 \cdot 10^{-94}\right):\\
\;\;\;\;1 + 4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.09999999999999992e127 or 3.3999999999999998e-94 < x

    1. Initial program 100.0%

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

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

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

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

    if -2.09999999999999992e127 < x < 3.3999999999999998e-94

    1. Initial program 100.0%

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

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

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

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

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

Alternative 4: 80.9% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+124} \lor \neg \left(z \leq 5.8 \cdot 10^{+106}\right):\\
\;\;\;\;1 + -4 \cdot \frac{z}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.30000000000000015e124 or 5.8000000000000004e106 < z

    1. Initial program 100.0%

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

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

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

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

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

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

    if -3.30000000000000015e124 < z < 5.8000000000000004e106

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} + 2 \]
    8. Step-by-step derivation
      1. *-commutative89.4%

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

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

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

Alternative 5: 83.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+127} \lor \neg \left(x \leq 2.8 \cdot 10^{-95}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.2000000000000002e127 or 2.7999999999999999e-95 < x

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} + 2 \]
    8. Step-by-step derivation
      1. *-commutative87.0%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot 4} + 2 \]
    9. Simplified87.0%

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

    if -2.2000000000000002e127 < x < 2.7999999999999999e-95

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    7. Taylor expanded in x around 0 93.3%

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

        \[\leadsto \color{blue}{\frac{z}{y} \cdot -4} + 2 \]
      2. associate-/r/93.3%

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{-4}}} + 2 \]
    9. Simplified93.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+127} \lor \neg \left(x \leq 2.8 \cdot 10^{-95}\right):\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + \frac{z}{\frac{y}{-4}}\\ \end{array} \]

Alternative 6: 99.8% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 7: 34.0% accurate, 13.0× speedup?

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

\\
2
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto \color{blue}{2} \]
  5. Final simplification35.8%

    \[\leadsto 2 \]

Reproduce

?
herbie shell --seed 2023271 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, C"
  :precision binary64
  (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))