
(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 6 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 (fma x (+ -1.0 y) y))
double code(double x, double y) {
return fma(x, (-1.0 + y), y);
}
function code(x, y) return fma(x, Float64(-1.0 + y), y) end
code[x_, y_] := N[(x * N[(-1.0 + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, -1 + y, y\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-rgt-in100.0%
associate-+l+100.0%
+-commutative100.0%
*-lft-identity100.0%
neg-mul-1100.0%
*-commutative100.0%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
*-lft-identity100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -480000000000.0)
(and (not (<= x 280000000000.0)) (<= x 2.8e+218)))
(* x y)
(- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -480000000000.0) || (!(x <= 280000000000.0) && (x <= 2.8e+218))) {
tmp = x * y;
} 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 <= (-480000000000.0d0)) .or. (.not. (x <= 280000000000.0d0)) .and. (x <= 2.8d+218)) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -480000000000.0) || (!(x <= 280000000000.0) && (x <= 2.8e+218))) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -480000000000.0) or (not (x <= 280000000000.0) and (x <= 2.8e+218)): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -480000000000.0) || (!(x <= 280000000000.0) && (x <= 2.8e+218))) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -480000000000.0) || (~((x <= 280000000000.0)) && (x <= 2.8e+218))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -480000000000.0], And[N[Not[LessEqual[x, 280000000000.0]], $MachinePrecision], LessEqual[x, 2.8e+218]]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -480000000000 \lor \neg \left(x \leq 280000000000\right) \land x \leq 2.8 \cdot 10^{+218}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -4.8e11 or 2.8e11 < x < 2.7999999999999998e218Initial program 100.0%
Taylor expanded in x around inf 99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in y around inf 61.9%
if -4.8e11 < x < 2.8e11 or 2.7999999999999998e218 < x Initial program 100.0%
Taylor expanded in x around 0 93.1%
Final simplification80.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.2e-11))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.2e-11)) {
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.0d0)) .or. (.not. (x <= 4.2d-11))) 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.0) || !(x <= 4.2e-11)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.2e-11): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.2e-11)) 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.0) || ~((x <= 4.2e-11))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.2e-11]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.2 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 4.1999999999999997e-11 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
*-commutative99.3%
Simplified99.3%
if -1 < x < 4.1999999999999997e-11Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -9.0) (not (<= y 1.0))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -9.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 <= (-9.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 <= -9.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9.0) or not (y <= 1.0): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -9.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 <= -9.0) || ~((y <= 1.0))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -9 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 53.5%
*-commutative53.5%
Simplified53.5%
Taylor expanded in y around inf 52.8%
if -9 < y < 1Initial program 100.0%
Taylor expanded in x around inf 68.7%
*-commutative68.7%
Simplified68.7%
Taylor expanded in y around 0 67.3%
mul-1-neg67.3%
Simplified67.3%
Final simplification59.6%
(FPCore (x y) :precision binary64 (- (* y (+ x 1.0)) x))
double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (x + 1.0d0)) - x
end function
public static double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
def code(x, y): return (y * (x + 1.0)) - x
function code(x, y) return Float64(Float64(y * Float64(x + 1.0)) - x) end
function tmp = code(x, y) tmp = (y * (x + 1.0)) - x; end
code[x_, y_] := N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x + 1\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(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 60.7%
*-commutative60.7%
Simplified60.7%
Taylor expanded in y around 0 33.0%
mul-1-neg33.0%
Simplified33.0%
Final simplification33.0%
herbie shell --seed 2023301
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))