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

Percentage Accurate: 99.8% → 99.8%
Time: 4.6s
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.8% 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: 99.8% 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}
Derivation
  1. Initial program 100.0%

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 79.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+38} \lor \neg \left(x \leq 2.7 \cdot 10^{+40}\right) \land \left(x \leq 3.4 \cdot 10^{+67} \lor \neg \left(x \leq 2.45 \cdot 10^{+163}\right)\right):\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + \frac{z}{y} \cdot -4\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.45e+38)
         (and (not (<= x 2.7e+40)) (or (<= x 3.4e+67) (not (<= x 2.45e+163)))))
   (+ 1.0 (/ (* 4.0 x) y))
   (+ 2.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.45e+38) || (!(x <= 2.7e+40) && ((x <= 3.4e+67) || !(x <= 2.45e+163)))) {
		tmp = 1.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 <= (-1.45d+38)) .or. (.not. (x <= 2.7d+40)) .and. (x <= 3.4d+67) .or. (.not. (x <= 2.45d+163))) then
        tmp = 1.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 <= -1.45e+38) || (!(x <= 2.7e+40) && ((x <= 3.4e+67) || !(x <= 2.45e+163)))) {
		tmp = 1.0 + ((4.0 * x) / y);
	} else {
		tmp = 2.0 + ((z / y) * -4.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1.45e+38) or (not (x <= 2.7e+40) and ((x <= 3.4e+67) or not (x <= 2.45e+163))):
		tmp = 1.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 <= -1.45e+38) || (!(x <= 2.7e+40) && ((x <= 3.4e+67) || !(x <= 2.45e+163))))
		tmp = Float64(1.0 + Float64(Float64(4.0 * x) / y));
	else
		tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1.45e+38) || (~((x <= 2.7e+40)) && ((x <= 3.4e+67) || ~((x <= 2.45e+163)))))
		tmp = 1.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, -1.45e+38], And[N[Not[LessEqual[x, 2.7e+40]], $MachinePrecision], Or[LessEqual[x, 3.4e+67], N[Not[LessEqual[x, 2.45e+163]], $MachinePrecision]]]], N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{+38} \lor \neg \left(x \leq 2.7 \cdot 10^{+40}\right) \land \left(x \leq 3.4 \cdot 10^{+67} \lor \neg \left(x \leq 2.45 \cdot 10^{+163}\right)\right):\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.45000000000000003e38 or 2.70000000000000009e40 < x < 3.4000000000000002e67 or 2.45e163 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 80.3%

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

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative80.3%

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

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

    if -1.45000000000000003e38 < x < 2.70000000000000009e40 or 3.4000000000000002e67 < x < 2.45e163

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4}{y} \cdot \left(x - z\right) + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      12. *-rgt-identity99.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+38} \lor \neg \left(x \leq 2.7 \cdot 10^{+40}\right) \land \left(x \leq 3.4 \cdot 10^{+67} \lor \neg \left(x \leq 2.45 \cdot 10^{+163}\right)\right):\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + \frac{z}{y} \cdot -4\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 86.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{+35} \lor \neg \left(x \leq 4.1 \cdot 10^{+37}\right):\\ \;\;\;\;2 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + \frac{z}{y} \cdot -4\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -4.8e+35) (not (<= x 4.1e+37)))
   (+ 2.0 (/ (* 4.0 x) y))
   (+ 2.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.8e+35) || !(x <= 4.1e+37)) {
		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 <= (-4.8d+35)) .or. (.not. (x <= 4.1d+37))) 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 <= -4.8e+35) || !(x <= 4.1e+37)) {
		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 <= -4.8e+35) or not (x <= 4.1e+37):
		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 <= -4.8e+35) || !(x <= 4.1e+37))
		tmp = Float64(2.0 + Float64(Float64(4.0 * x) / y));
	else
		tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -4.8e+35) || ~((x <= 4.1e+37)))
		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, -4.8e+35], N[Not[LessEqual[x, 4.1e+37]], $MachinePrecision]], N[(2.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+35} \lor \neg \left(x \leq 4.1 \cdot 10^{+37}\right):\\
\;\;\;\;2 + \frac{4 \cdot x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.80000000000000029e35 or 4.0999999999999998e37 < 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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4}{y} \cdot \left(x - z\right) + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      12. *-rgt-identity99.8%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot x}{y}} + 2 \]
      3. *-commutative90.1%

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

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

    if -4.80000000000000029e35 < x < 4.0999999999999998e37

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4}{y} \cdot \left(x - z\right) + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      12. *-rgt-identity99.8%

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

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

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

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

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

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

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

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

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

Alternative 4: 55.0% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+16} \lor \neg \left(x \leq 3.1 \cdot 10^{-27}\right):\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3e16 or 3.0999999999999998e-27 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 64.4%

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

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative64.4%

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

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

    if -3e16 < x < 3.0999999999999998e-27

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 55.6%

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

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

Alternative 5: 99.8% accurate, 1.4× speedup?

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

\\
\frac{4}{y} \cdot \left(x - z\right) + 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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{4}{y} \cdot \left(x - z\right) + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
    12. *-rgt-identity99.8%

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

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

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

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

Alternative 6: 34.3% 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. Add Preprocessing
  3. Taylor expanded in y around inf 42.1%

    \[\leadsto \color{blue}{2} \]
  4. Add Preprocessing

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

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 36.9%

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

      \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
    2. *-commutative36.9%

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

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

    \[\leadsto \color{blue}{1} \]
  7. Add Preprocessing

Reproduce

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