
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (+ x 1.0) y))) (if (<= y -8.5e-147) t_0 (if (<= y 1.18e-23) (- (- (+ x 1.0) x) x) t_0))))
double code(double x, double y) {
double t_0 = (x + 1.0) * y;
double tmp;
if (y <= -8.5e-147) {
tmp = t_0;
} else if (y <= 1.18e-23) {
tmp = ((x + 1.0) - x) - x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (x + 1.0d0) * y
if (y <= (-8.5d-147)) then
tmp = t_0
else if (y <= 1.18d-23) then
tmp = ((x + 1.0d0) - x) - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + 1.0) * y;
double tmp;
if (y <= -8.5e-147) {
tmp = t_0;
} else if (y <= 1.18e-23) {
tmp = ((x + 1.0) - x) - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x + 1.0) * y tmp = 0 if y <= -8.5e-147: tmp = t_0 elif y <= 1.18e-23: tmp = ((x + 1.0) - x) - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x + 1.0) * y) tmp = 0.0 if (y <= -8.5e-147) tmp = t_0; elseif (y <= 1.18e-23) tmp = Float64(Float64(Float64(x + 1.0) - x) - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x + 1.0) * y; tmp = 0.0; if (y <= -8.5e-147) tmp = t_0; elseif (y <= 1.18e-23) tmp = ((x + 1.0) - x) - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -8.5e-147], t$95$0, If[LessEqual[y, 1.18e-23], N[(N[(N[(x + 1.0), $MachinePrecision] - x), $MachinePrecision] - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + 1\right) \cdot y\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{-23}:\\
\;\;\;\;\left(\left(x + 1\right) - x\right) - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5000000000000002e-147 or 1.18e-23 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites92.1%
if -8.5000000000000002e-147 < y < 1.18e-23Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.0%
Taylor expanded in x around 0
Applied rewrites56.5%
(FPCore (x y) :precision binary64 (* (+ x 1.0) y))
double code(double x, double y) {
return (x + 1.0) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + 1.0d0) * y
end function
public static double code(double x, double y) {
return (x + 1.0) * y;
}
def code(x, y): return (x + 1.0) * y
function code(x, y) return Float64(Float64(x + 1.0) * y) end
function tmp = code(x, y) tmp = (x + 1.0) * y; end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites67.0%
(FPCore (x y) :precision binary64 (+ x 1.0))
double code(double x, double y) {
return x + 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + 1.0d0
end function
public static double code(double x, double y) {
return x + 1.0;
}
def code(x, y): return x + 1.0
function code(x, y) return Float64(x + 1.0) end
function tmp = code(x, y) tmp = x + 1.0; end
code[x_, y_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites67.0%
Taylor expanded in x around 0
Applied rewrites3.1%
herbie shell --seed 2024321
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
:pre (TRUE)
(- (* (+ x 1.0) y) x))