
(FPCore (x y) :precision binary64 (- (* x 2.0) y))
double code(double x, double y) {
return (x * 2.0) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 2.0d0) - y
end function
public static double code(double x, double y) {
return (x * 2.0) - y;
}
def code(x, y): return (x * 2.0) - y
function code(x, y) return Float64(Float64(x * 2.0) - y) end
function tmp = code(x, y) tmp = (x * 2.0) - y; end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2 - y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* x 2.0) y))
double code(double x, double y) {
return (x * 2.0) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 2.0d0) - y
end function
public static double code(double x, double y) {
return (x * 2.0) - y;
}
def code(x, y): return (x * 2.0) - y
function code(x, y) return Float64(Float64(x * 2.0) - y) end
function tmp = code(x, y) tmp = (x * 2.0) - y; end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2 - y
\end{array}
(FPCore (x y) :precision binary64 (- (* x 2.0) y))
double code(double x, double y) {
return (x * 2.0) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 2.0d0) - y
end function
public static double code(double x, double y) {
return (x * 2.0) - y;
}
def code(x, y): return (x * 2.0) - y
function code(x, y) return Float64(Float64(x * 2.0) - y) end
function tmp = code(x, y) tmp = (x * 2.0) - y; end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2 - y
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.92e+37) (- 0.0 y) (if (<= y 2.4e+52) (* x 2.0) (- 0.0 y))))
double code(double x, double y) {
double tmp;
if (y <= -1.92e+37) {
tmp = 0.0 - y;
} else if (y <= 2.4e+52) {
tmp = x * 2.0;
} else {
tmp = 0.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.92d+37)) then
tmp = 0.0d0 - y
else if (y <= 2.4d+52) then
tmp = x * 2.0d0
else
tmp = 0.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.92e+37) {
tmp = 0.0 - y;
} else if (y <= 2.4e+52) {
tmp = x * 2.0;
} else {
tmp = 0.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.92e+37: tmp = 0.0 - y elif y <= 2.4e+52: tmp = x * 2.0 else: tmp = 0.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.92e+37) tmp = Float64(0.0 - y); elseif (y <= 2.4e+52) tmp = Float64(x * 2.0); else tmp = Float64(0.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.92e+37) tmp = 0.0 - y; elseif (y <= 2.4e+52) tmp = x * 2.0; else tmp = 0.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.92e+37], N[(0.0 - y), $MachinePrecision], If[LessEqual[y, 2.4e+52], N[(x * 2.0), $MachinePrecision], N[(0.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.92 \cdot 10^{+37}:\\
\;\;\;\;0 - y\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+52}:\\
\;\;\;\;x \cdot 2\\
\mathbf{else}:\\
\;\;\;\;0 - y\\
\end{array}
\end{array}
if y < -1.91999999999999994e37 or 2.4e52 < y Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6481.3%
Simplified81.3%
sub0-negN/A
neg-lowering-neg.f6481.3%
Applied egg-rr81.3%
if -1.91999999999999994e37 < y < 2.4e52Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f6479.5%
Simplified79.5%
Final simplification80.3%
(FPCore (x y) :precision binary64 (- 0.0 y))
double code(double x, double y) {
return 0.0 - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0 - y
end function
public static double code(double x, double y) {
return 0.0 - y;
}
def code(x, y): return 0.0 - y
function code(x, y) return Float64(0.0 - y) end
function tmp = code(x, y) tmp = 0.0 - y; end
code[x_, y_] := N[(0.0 - y), $MachinePrecision]
\begin{array}{l}
\\
0 - y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6449.3%
Simplified49.3%
sub0-negN/A
neg-lowering-neg.f6449.3%
Applied egg-rr49.3%
Final simplification49.3%
herbie shell --seed 2024152
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, C"
:precision binary64
(- (* x 2.0) y))