
(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 -1.05e-44) t_0 (if (<= y 6e-129) (- (- (+ x 1.0) x) x) t_0))))
double code(double x, double y) {
double t_0 = (x + 1.0) * y;
double tmp;
if (y <= -1.05e-44) {
tmp = t_0;
} else if (y <= 6e-129) {
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 <= (-1.05d-44)) then
tmp = t_0
else if (y <= 6d-129) 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 <= -1.05e-44) {
tmp = t_0;
} else if (y <= 6e-129) {
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 <= -1.05e-44: tmp = t_0 elif y <= 6e-129: 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 <= -1.05e-44) tmp = t_0; elseif (y <= 6e-129) 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 <= -1.05e-44) tmp = t_0; elseif (y <= 6e-129) 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, -1.05e-44], t$95$0, If[LessEqual[y, 6e-129], 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 -1.05 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-129}:\\
\;\;\;\;\left(\left(x + 1\right) - x\right) - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.05000000000000001e-44 or 5.9999999999999996e-129 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites91.9%
if -1.05000000000000001e-44 < y < 5.9999999999999996e-129Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites2.9%
Taylor expanded in x around 0
Applied rewrites57.4%
(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 rewrites63.8%
(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 rewrites63.8%
Taylor expanded in x around 0
Applied rewrites3.0%
herbie shell --seed 2024313
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))