
(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 (- (* y (+ 1.0 x)) x))
double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 + x)) - x
end function
public static double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
def code(x, y): return (y * (1.0 + x)) - x
function code(x, y) return Float64(Float64(y * Float64(1.0 + x)) - x) end
function tmp = code(x, y) tmp = (y * (1.0 + x)) - x; end
code[x_, y_] := N[(N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(1 + x\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 2.15e-5))) (- (* y x) x) (- (* 1.0 y) x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 2.15e-5)) {
tmp = (y * x) - x;
} else {
tmp = (1.0 * 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 <= 2.15d-5))) then
tmp = (y * x) - x
else
tmp = (1.0d0 * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 2.15e-5)) {
tmp = (y * x) - x;
} else {
tmp = (1.0 * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 2.15e-5): tmp = (y * x) - x else: tmp = (1.0 * y) - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 2.15e-5)) tmp = Float64(Float64(y * x) - x); else tmp = Float64(Float64(1.0 * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 2.15e-5))) tmp = (y * x) - x; else tmp = (1.0 * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 2.15e-5]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 2.15 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y - x\\
\end{array}
\end{array}
if x < -1 or 2.1500000000000001e-5 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64100.0
Applied rewrites100.0%
if -1 < x < 2.1500000000000001e-5Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.8%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= x -2.15e-18) (not (<= x 1.4e-9))) (- (* y x) x) (fma x y y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.15e-18) || !(x <= 1.4e-9)) {
tmp = (y * x) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -2.15e-18) || !(x <= 1.4e-9)) tmp = Float64(Float64(y * x) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -2.15e-18], N[Not[LessEqual[x, 1.4e-9]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-18} \lor \neg \left(x \leq 1.4 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if x < -2.1500000000000001e-18 or 1.39999999999999992e-9 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6499.8
Applied rewrites99.8%
if -2.1500000000000001e-18 < x < 1.39999999999999992e-9Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6482.0
Applied rewrites82.0%
Final simplification90.2%
(FPCore (x y) :precision binary64 (if (or (<= y -1.9e-148) (not (<= y 2.8e-75))) (fma x y y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.9e-148) || !(y <= 2.8e-75)) {
tmp = fma(x, y, y);
} else {
tmp = -x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((y <= -1.9e-148) || !(y <= 2.8e-75)) tmp = fma(x, y, y); else tmp = Float64(-x); end return tmp end
code[x_, y_] := If[Or[LessEqual[y, -1.9e-148], N[Not[LessEqual[y, 2.8e-75]], $MachinePrecision]], N[(x * y + y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-148} \lor \neg \left(y \leq 2.8 \cdot 10^{-75}\right):\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1.90000000000000007e-148 or 2.79999999999999998e-75 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6494.0
Applied rewrites94.0%
if -1.90000000000000007e-148 < y < 2.79999999999999998e-75Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6481.2
Applied rewrites81.2%
Final simplification89.9%
(FPCore (x y) :precision binary64 (if (or (<= y -7500000000000.0) (not (<= y 1.0))) (* y x) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -7500000000000.0) || !(y <= 1.0)) {
tmp = y * x;
} 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 <= (-7500000000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * x
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7500000000000.0) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7500000000000.0) or not (y <= 1.0): tmp = y * x else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7500000000000.0) || !(y <= 1.0)) tmp = Float64(y * x); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7500000000000.0) || ~((y <= 1.0))) tmp = y * x; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7500000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7500000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -7.5e12 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.5
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites49.9%
if -7.5e12 < y < 1Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6465.9
Applied rewrites65.9%
Final simplification57.2%
(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 y around 0
mul-1-negN/A
lower-neg.f6431.7
Applied rewrites31.7%
herbie shell --seed 2024271
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))