
(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 5 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 (<= y -8e+76) (and (not (<= y -2.2e+16)) (<= y 4.3e+15))) (- y x) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= -8e+76) || (!(y <= -2.2e+16) && (y <= 4.3e+15))) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-8d+76)) .or. (.not. (y <= (-2.2d+16))) .and. (y <= 4.3d+15)) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -8e+76) || (!(y <= -2.2e+16) && (y <= 4.3e+15))) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8e+76) or (not (y <= -2.2e+16) and (y <= 4.3e+15)): tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((y <= -8e+76) || (!(y <= -2.2e+16) && (y <= 4.3e+15))) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -8e+76) || (~((y <= -2.2e+16)) && (y <= 4.3e+15))) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8e+76], And[N[Not[LessEqual[y, -2.2e+16]], $MachinePrecision], LessEqual[y, 4.3e+15]]], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+76} \lor \neg \left(y \leq -2.2 \cdot 10^{+16}\right) \land y \leq 4.3 \cdot 10^{+15}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.0000000000000004e76 or -2.2e16 < y < 4.3e15Initial program 100.0%
Taylor expanded in x around 0 85.6%
if -8.0000000000000004e76 < y < -2.2e16 or 4.3e15 < y Initial program 100.0%
Taylor expanded in x around inf 63.2%
*-commutative63.2%
Simplified63.2%
Taylor expanded in y around inf 63.2%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (or (<= x -32.0) (not (<= x 1.0))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -32.0) || !(x <= 1.0)) {
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 <= (-32.0d0)) .or. (.not. (x <= 1.0d0))) 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 <= -32.0) || !(x <= 1.0)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -32.0) or not (x <= 1.0): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -32.0) || !(x <= 1.0)) 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 <= -32.0) || ~((x <= 1.0))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -32.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -32 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -32 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.4%
*-commutative98.4%
Simplified98.4%
if -32 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.8%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 55.9%
*-commutative55.9%
Simplified55.9%
Taylor expanded in y around inf 55.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around inf 73.1%
*-commutative73.1%
Simplified73.1%
Taylor expanded in y around 0 71.3%
neg-mul-171.3%
Simplified71.3%
Final simplification63.1%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 64.1%
*-commutative64.1%
Simplified64.1%
Taylor expanded in y around 0 35.5%
neg-mul-135.5%
Simplified35.5%
Final simplification35.5%
herbie shell --seed 2024089
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))