
(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 (+ 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 (if (<= x -2.4e+100) (* x y) (if (<= x -1.52e-22) (- x) (if (<= x 1.0) y (* x y)))))
double code(double x, double y) {
double tmp;
if (x <= -2.4e+100) {
tmp = x * y;
} else if (x <= -1.52e-22) {
tmp = -x;
} else if (x <= 1.0) {
tmp = y;
} 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 (x <= (-2.4d+100)) then
tmp = x * y
else if (x <= (-1.52d-22)) then
tmp = -x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.4e+100) {
tmp = x * y;
} else if (x <= -1.52e-22) {
tmp = -x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.4e+100: tmp = x * y elif x <= -1.52e-22: tmp = -x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.4e+100) tmp = Float64(x * y); elseif (x <= -1.52e-22) tmp = Float64(-x); elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.4e+100) tmp = x * y; elseif (x <= -1.52e-22) tmp = -x; elseif (x <= 1.0) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.4e+100], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.52e-22], (-x), If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+100}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.52 \cdot 10^{-22}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.40000000000000012e100 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 60.1%
Taylor expanded in x around inf 59.4%
if -2.40000000000000012e100 < x < -1.52000000000000005e-22Initial program 100.0%
Taylor expanded in y around 0 61.8%
neg-mul-161.8%
Simplified61.8%
if -1.52000000000000005e-22 < x < 1Initial program 100.0%
Taylor expanded in x around 0 75.3%
Final simplification67.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1650.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1650.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} 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 ((y <= (-1650.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1650.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1650.0) or not (y <= 1.0): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1650.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1650.0) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1650.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1650 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1650 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.9%
if -1650 < y < 1Initial program 100.0%
Taylor expanded in x around 0 99.2%
Taylor expanded in y around 0 99.2%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.15e+101) (not (<= x 1.02e+38))) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.15e+101) || !(x <= 1.02e+38)) {
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 <= (-1.15d+101)) .or. (.not. (x <= 1.02d+38))) 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 <= -1.15e+101) || !(x <= 1.02e+38)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.15e+101) or not (x <= 1.02e+38): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.15e+101) || !(x <= 1.02e+38)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.15e+101) || ~((x <= 1.02e+38))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.15e+101], N[Not[LessEqual[x, 1.02e+38]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+101} \lor \neg \left(x \leq 1.02 \cdot 10^{+38}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.1500000000000001e101 or 1.02000000000000006e38 < x Initial program 100.0%
Taylor expanded in y around inf 61.1%
Taylor expanded in x around inf 61.1%
if -1.1500000000000001e101 < x < 1.02000000000000006e38Initial program 100.0%
Taylor expanded in x around 0 92.2%
Taylor expanded in y around 0 92.2%
Final simplification80.6%
(FPCore (x y) :precision binary64 (if (<= y -4.2e-52) y (if (<= y 1.85e-94) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -4.2e-52) {
tmp = y;
} else if (y <= 1.85e-94) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-4.2d-52)) then
tmp = y
else if (y <= 1.85d-94) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e-52) {
tmp = y;
} else if (y <= 1.85e-94) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e-52: tmp = y elif y <= 1.85e-94: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e-52) tmp = y; elseif (y <= 1.85e-94) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e-52) tmp = y; elseif (y <= 1.85e-94) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e-52], y, If[LessEqual[y, 1.85e-94], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-52}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{-94}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.1999999999999997e-52 or 1.8499999999999999e-94 < y Initial program 100.0%
Taylor expanded in x around 0 53.2%
if -4.1999999999999997e-52 < y < 1.8499999999999999e-94Initial program 100.0%
Taylor expanded in y around 0 85.0%
neg-mul-185.0%
Simplified85.0%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 39.3%
herbie shell --seed 2024144
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))