
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (* 4.0 (/ (- (- x y) (* z 0.5)) z)))
double code(double x, double y, double z) {
return 4.0 * (((x - y) - (z * 0.5)) / z);
}
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) - (z * 0.5d0)) / z)
end function
public static double code(double x, double y, double z) {
return 4.0 * (((x - y) - (z * 0.5)) / z);
}
def code(x, y, z): return 4.0 * (((x - y) - (z * 0.5)) / z)
function code(x, y, z) return Float64(4.0 * Float64(Float64(Float64(x - y) - Float64(z * 0.5)) / z)) end
function tmp = code(x, y, z) tmp = 4.0 * (((x - y) - (z * 0.5)) / z); end
code[x_, y_, z_] := N[(4.0 * N[(N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{\left(x - y\right) - z \cdot 0.5}{z}
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
Applied rewrites62.9%
Taylor expanded in x around inf
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ (- x y) z)))
(t_1 (- (- x y) (* z 0.5)))
(t_2 (/ (* 4.0 t_1) z)))
(if (<= t_2 -10.0) t_0 (if (<= t_2 -1.0) (/ t_1 z) t_0))))
double code(double x, double y, double z) {
double t_0 = 4.0 * ((x - y) / z);
double t_1 = (x - y) - (z * 0.5);
double t_2 = (4.0 * t_1) / z;
double tmp;
if (t_2 <= -10.0) {
tmp = t_0;
} else if (t_2 <= -1.0) {
tmp = t_1 / 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 4.0d0 * ((x - y) / z)
t_1 = (x - y) - (z * 0.5d0)
t_2 = (4.0d0 * t_1) / z
if (t_2 <= (-10.0d0)) then
tmp = t_0
else if (t_2 <= (-1.0d0)) then
tmp = t_1 / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * ((x - y) / z);
double t_1 = (x - y) - (z * 0.5);
double t_2 = (4.0 * t_1) / z;
double tmp;
if (t_2 <= -10.0) {
tmp = t_0;
} else if (t_2 <= -1.0) {
tmp = t_1 / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * ((x - y) / z) t_1 = (x - y) - (z * 0.5) t_2 = (4.0 * t_1) / z tmp = 0 if t_2 <= -10.0: tmp = t_0 elif t_2 <= -1.0: tmp = t_1 / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(Float64(x - y) / z)) t_1 = Float64(Float64(x - y) - Float64(z * 0.5)) t_2 = Float64(Float64(4.0 * t_1) / z) tmp = 0.0 if (t_2 <= -10.0) tmp = t_0; elseif (t_2 <= -1.0) tmp = Float64(t_1 / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * ((x - y) / z); t_1 = (x - y) - (z * 0.5); t_2 = (4.0 * t_1) / z; tmp = 0.0; if (t_2 <= -10.0) tmp = t_0; elseif (t_2 <= -1.0) tmp = t_1 / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(4.0 * t$95$1), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$2, -10.0], t$95$0, If[LessEqual[t$95$2, -1.0], N[(t$95$1 / z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x - y}{z}\\
t_1 := \left(x - y\right) - z \cdot 0.5\\
t_2 := \frac{4 \cdot t\_1}{z}\\
\mathbf{if}\;t\_2 \leq -10:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_2 \leq -1:\\
\;\;\;\;\frac{t\_1}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (-.f64 x y) (*.f64 z #s(literal 1/2 binary64)))) z) < -10 or -1 < (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (-.f64 x y) (*.f64 z #s(literal 1/2 binary64)))) z) Initial program 99.4%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
Applied rewrites96.7%
if -10 < (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (-.f64 x y) (*.f64 z #s(literal 1/2 binary64)))) z) < -1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites17.2%
(FPCore (x y z) :precision binary64 (* 4.0 (/ (- x y) z)))
double code(double x, double y, double z) {
return 4.0 * ((x - y) / z);
}
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) / z)
end function
public static double code(double x, double y, double z) {
return 4.0 * ((x - y) / z);
}
def code(x, y, z): return 4.0 * ((x - y) / z)
function code(x, y, z) return Float64(4.0 * Float64(Float64(x - y) / z)) end
function tmp = code(x, y, z) tmp = 4.0 * ((x - y) / z); end
code[x_, y_, z_] := N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x - y}{z}
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
Applied rewrites62.9%
(FPCore (x y z) :precision binary64 (/ (- x y) z))
double code(double x, double y, double z) {
return (x - y) / z;
}
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) / z
end function
public static double code(double x, double y, double z) {
return (x - y) / z;
}
def code(x, y, z): return (x - y) / z
function code(x, y, z) return Float64(Float64(x - y) / z) end
function tmp = code(x, y, z) tmp = (x - y) / z; end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z}
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites25.1%
(FPCore (x y z) :precision binary64 (- x y))
double code(double x, double y, double z) {
return x - y;
}
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
end function
public static double code(double x, double y, double z) {
return x - y;
}
def code(x, y, z): return x - y
function code(x, y, z) return Float64(x - y) end
function tmp = code(x, y, z) tmp = x - y; end
code[x_, y_, z_] := N[(x - y), $MachinePrecision]
\begin{array}{l}
\\
x - y
\end{array}
Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around 0
Applied rewrites3.4%
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
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)) - (2.0d0 + (4.0d0 * (y / z)))
end function
public static double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
def code(x, y, z): return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)))
function code(x, y, z) return Float64(Float64(4.0 * Float64(x / z)) - Float64(2.0 + Float64(4.0 * Float64(y / z)))) end
function tmp = code(x, y, z) tmp = (4.0 * (x / z)) - (2.0 + (4.0 * (y / z))); end
code[x_, y_, z_] := N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 + N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right)
\end{array}
herbie shell --seed 2024321
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- (* 4 (/ x z)) (+ 2 (* 4 (/ y z)))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))