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

Percentage Accurate: 99.9% → 99.9%
Time: 1.7s
Alternatives: 11
Speedup: 1.0×

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 11 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: 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}
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: 12.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := 1 + \frac{y \cdot 0.25}{y}\\
\mathbf{if}\;y \leq -0.032:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.16 \cdot 10^{+30}:\\
\;\;\;\;1 + \left(1 + \left(\left(x + y \cdot 0.25\right) - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.032000000000000001 or 1.16e30 < y

    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 0

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

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

    if -0.032000000000000001 < y < 1.16e30

    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 0

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

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

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

      \[\leadsto 1 + \left(1 + \color{blue}{\left(\left(x + y \cdot 0.25\right) - z\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 72.1% accurate, 1.1× speedup?

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

\\
\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. Taylor expanded in x around 0

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

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

Alternative 4: 9.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.032:\\ \;\;\;\;\frac{y \cdot 0.25}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(1 + \left(\left(x + y \cdot 0.25\right) - z\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -0.032) (/ (* y 0.25) y) (+ 1.0 (+ 1.0 (- (+ x (* y 0.25)) z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -0.032) {
		tmp = (y * 0.25) / y;
	} else {
		tmp = 1.0 + (1.0 + ((x + (y * 0.25)) - z));
	}
	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 <= (-0.032d0)) then
        tmp = (y * 0.25d0) / y
    else
        tmp = 1.0d0 + (1.0d0 + ((x + (y * 0.25d0)) - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -0.032) {
		tmp = (y * 0.25) / y;
	} else {
		tmp = 1.0 + (1.0 + ((x + (y * 0.25)) - z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -0.032:
		tmp = (y * 0.25) / y
	else:
		tmp = 1.0 + (1.0 + ((x + (y * 0.25)) - z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -0.032)
		tmp = Float64(Float64(y * 0.25) / y);
	else
		tmp = Float64(1.0 + Float64(1.0 + Float64(Float64(x + Float64(y * 0.25)) - z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -0.032)
		tmp = (y * 0.25) / y;
	else
		tmp = 1.0 + (1.0 + ((x + (y * 0.25)) - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -0.032], N[(N[(y * 0.25), $MachinePrecision] / y), $MachinePrecision], N[(1.0 + N[(1.0 + N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.032:\\
\;\;\;\;\frac{y \cdot 0.25}{y}\\

\mathbf{else}:\\
\;\;\;\;1 + \left(1 + \left(\left(x + y \cdot 0.25\right) - z\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.032000000000000001

    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 0

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
    6. Applied rewrites12.0%

      \[\leadsto \color{blue}{\frac{y \cdot 0.25}{y}} \]

    if -0.032000000000000001 < y

    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 0

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

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

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

      \[\leadsto 1 + \left(1 + \color{blue}{\left(\left(x + y \cdot 0.25\right) - z\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 9.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -16000000:\\ \;\;\;\;\frac{y \cdot 0.25}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(1 + \left(y \cdot 0.25 - z\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -16000000.0) (/ (* y 0.25) y) (+ 1.0 (+ 1.0 (- (* y 0.25) z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -16000000.0) {
		tmp = (y * 0.25) / y;
	} else {
		tmp = 1.0 + (1.0 + ((y * 0.25) - z));
	}
	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 <= (-16000000.0d0)) then
        tmp = (y * 0.25d0) / y
    else
        tmp = 1.0d0 + (1.0d0 + ((y * 0.25d0) - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -16000000.0) {
		tmp = (y * 0.25) / y;
	} else {
		tmp = 1.0 + (1.0 + ((y * 0.25) - z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -16000000.0:
		tmp = (y * 0.25) / y
	else:
		tmp = 1.0 + (1.0 + ((y * 0.25) - z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -16000000.0)
		tmp = Float64(Float64(y * 0.25) / y);
	else
		tmp = Float64(1.0 + Float64(1.0 + Float64(Float64(y * 0.25) - z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -16000000.0)
		tmp = (y * 0.25) / y;
	else
		tmp = 1.0 + (1.0 + ((y * 0.25) - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -16000000.0], N[(N[(y * 0.25), $MachinePrecision] / y), $MachinePrecision], N[(1.0 + N[(1.0 + N[(N[(y * 0.25), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000000:\\
\;\;\;\;\frac{y \cdot 0.25}{y}\\

\mathbf{else}:\\
\;\;\;\;1 + \left(1 + \left(y \cdot 0.25 - z\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.6e7

    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 0

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

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

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
    6. Applied rewrites12.5%

      \[\leadsto \color{blue}{\frac{y \cdot 0.25}{y}} \]

    if -1.6e7 < y

    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 0

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

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

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

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

      \[\leadsto 1 + \left(1 + \left(\frac{1}{4} \cdot y - z\right)\right) \]
    8. Applied rewrites12.8%

      \[\leadsto 1 + \left(1 + \left(y \cdot 0.25 - z\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 6.9% accurate, 2.1× speedup?

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

\\
1 + \left(1 + \left(y \cdot 0.25 - z\right)\right)
\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 0

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

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

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

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

    \[\leadsto 1 + \left(1 + \left(\frac{1}{4} \cdot y - z\right)\right) \]
  8. Applied rewrites9.9%

    \[\leadsto 1 + \left(1 + \left(y \cdot 0.25 - z\right)\right) \]
  9. Add Preprocessing

Alternative 7: 6.6% accurate, 2.6× speedup?

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

\\
1 + \left(1 + y \cdot 0.25\right)
\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 0

    \[\leadsto 1 + \color{blue}{4 \cdot \frac{\frac{1}{4} \cdot y - z}{y}} \]
  4. Applied rewrites5.0%

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

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

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

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

    \[\leadsto 1 + \left(1 + \color{blue}{y \cdot 0.25}\right) \]
  9. Add Preprocessing

Alternative 8: 3.5% accurate, 3.4× speedup?

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

\\
1 + y \cdot 0.25
\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 0

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

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

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

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

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

    \[\leadsto 1 + y \cdot \color{blue}{0.25} \]
  9. Add Preprocessing

Alternative 9: 3.1% accurate, 3.4× speedup?

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

\\
x + y \cdot 0.25
\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 0

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

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

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

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

    \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
  8. Applied rewrites3.4%

    \[\leadsto \color{blue}{x + y \cdot 0.25} \]
  9. Add Preprocessing

Alternative 10: 3.1% accurate, 3.4× speedup?

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

\\
y \cdot 0.25 - z
\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 0

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

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

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

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

    \[\leadsto \frac{1}{4} \cdot y - z \]
  8. Applied rewrites3.2%

    \[\leadsto y \cdot 0.25 - z \]
  9. Add Preprocessing

Alternative 11: 2.7% accurate, 5.2× speedup?

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

\\
y \cdot 0.25
\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 0

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

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

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

    \[\leadsto y \cdot \color{blue}{0.25} \]
  7. Add Preprocessing

Reproduce

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