
(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:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (+ 1.0 (/ 4.0 (/ y (- (+ x (* y 0.25)) z)))))
double code(double x, double y, double z) {
return 1.0 + (4.0 / (y / ((x + (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 + (4.0d0 / (y / ((x + (y * 0.25d0)) - z)))
end function
public static double code(double x, double y, double z) {
return 1.0 + (4.0 / (y / ((x + (y * 0.25)) - z)));
}
def code(x, y, z): return 1.0 + (4.0 / (y / ((x + (y * 0.25)) - z)))
function code(x, y, z) return Float64(1.0 + Float64(4.0 / Float64(y / Float64(Float64(x + Float64(y * 0.25)) - z)))) end
function tmp = code(x, y, z) tmp = 1.0 + (4.0 / (y / ((x + (y * 0.25)) - z))); end
code[x_, y_, z_] := N[(1.0 + N[(4.0 / N[(y / N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (+ 1.0 (* (/ 4.0 y) (- (fma y 0.25 x) z))))
double code(double x, double y, double z) {
return 1.0 + ((4.0 / y) * (fma(y, 0.25, x) - z));
}
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 / y) * Float64(fma(y, 0.25, x) - z))) end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 / y), $MachinePrecision] * N[(N[(y * 0.25 + x), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4}{y} \cdot \left(\mathsf{fma}\left(y, 0.25, x\right) - z\right)
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (fma (/ 4.0 y) (- (fma y 0.25 x) z) 1.0))
double code(double x, double y, double z) {
return fma((4.0 / y), (fma(y, 0.25, x) - z), 1.0);
}
function code(x, y, z) return fma(Float64(4.0 / y), Float64(fma(y, 0.25, x) - z), 1.0) end
code[x_, y_, z_] := N[(N[(4.0 / y), $MachinePrecision] * N[(N[(y * 0.25 + x), $MachinePrecision] - z), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{4}{y}, \mathsf{fma}\left(y, 0.25, x\right) - z, 1\right)
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (fma (- (fma y 0.25 x) z) (/ 4.0 y) 1.0))
double code(double x, double y, double z) {
return fma((fma(y, 0.25, x) - z), (4.0 / y), 1.0);
}
function code(x, y, z) return fma(Float64(fma(y, 0.25, x) - z), Float64(4.0 / y), 1.0) end
code[x_, y_, z_] := N[(N[(N[(y * 0.25 + x), $MachinePrecision] - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(y, 0.25, x\right) - z, \frac{4}{y}, 1\right)
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (/ 4.0 y) (- x z))))
double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
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 + ((4.0d0 / y) * (x - z))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((4.0 / y) * (x - z));
}
def code(x, y, z): return 2.0 + ((4.0 / y) * (x - z))
function code(x, y, z) return Float64(2.0 + Float64(Float64(4.0 / y) * Float64(x - z))) end
function tmp = code(x, y, z) tmp = 2.0 + ((4.0 / y) * (x - z)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(4.0 / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \frac{4}{y} \cdot \left(x - z\right)
\end{array}
Initial program 99.8%
herbie shell --seed 2023276
(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)))