
(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 3 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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.08e+18) (not (<= x 4e-25))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.08e+18) || !(x <= 4e-25)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.08d+18)) .or. (.not. (x <= 4d-25))) then
tmp = (x * y) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.08e+18) || !(x <= 4e-25)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.08e+18) or not (x <= 4e-25): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.08e+18) || !(x <= 4e-25)) tmp = Float64(Float64(x * y) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.08e+18) || ~((x <= 4e-25))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.08e+18], N[Not[LessEqual[x, 4e-25]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.08 \cdot 10^{+18} \lor \neg \left(x \leq 4 \cdot 10^{-25}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.08e18 or 4.00000000000000015e-25 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
if -1.08e18 < x < 4.00000000000000015e-25Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.7%
(FPCore (x y) :precision binary64 (- y x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 77.0%
Final simplification77.0%
herbie shell --seed 2024039
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))