
(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 (- (* (+ 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 (<= y -1.8e+25)
(* x y)
(if (<= y -3.5e-17)
y
(if (<= y -2.4e-109)
(- x)
(if (<= y -1.4e-131)
y
(if (<= y 1.35e-16) (- x) (if (<= y 3.1e+245) y (* x y))))))))
double code(double x, double y) {
double tmp;
if (y <= -1.8e+25) {
tmp = x * y;
} else if (y <= -3.5e-17) {
tmp = y;
} else if (y <= -2.4e-109) {
tmp = -x;
} else if (y <= -1.4e-131) {
tmp = y;
} else if (y <= 1.35e-16) {
tmp = -x;
} else if (y <= 3.1e+245) {
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 (y <= (-1.8d+25)) then
tmp = x * y
else if (y <= (-3.5d-17)) then
tmp = y
else if (y <= (-2.4d-109)) then
tmp = -x
else if (y <= (-1.4d-131)) then
tmp = y
else if (y <= 1.35d-16) then
tmp = -x
else if (y <= 3.1d+245) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.8e+25) {
tmp = x * y;
} else if (y <= -3.5e-17) {
tmp = y;
} else if (y <= -2.4e-109) {
tmp = -x;
} else if (y <= -1.4e-131) {
tmp = y;
} else if (y <= 1.35e-16) {
tmp = -x;
} else if (y <= 3.1e+245) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.8e+25: tmp = x * y elif y <= -3.5e-17: tmp = y elif y <= -2.4e-109: tmp = -x elif y <= -1.4e-131: tmp = y elif y <= 1.35e-16: tmp = -x elif y <= 3.1e+245: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.8e+25) tmp = Float64(x * y); elseif (y <= -3.5e-17) tmp = y; elseif (y <= -2.4e-109) tmp = Float64(-x); elseif (y <= -1.4e-131) tmp = y; elseif (y <= 1.35e-16) tmp = Float64(-x); elseif (y <= 3.1e+245) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.8e+25) tmp = x * y; elseif (y <= -3.5e-17) tmp = y; elseif (y <= -2.4e-109) tmp = -x; elseif (y <= -1.4e-131) tmp = y; elseif (y <= 1.35e-16) tmp = -x; elseif (y <= 3.1e+245) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.8e+25], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.5e-17], y, If[LessEqual[y, -2.4e-109], (-x), If[LessEqual[y, -1.4e-131], y, If[LessEqual[y, 1.35e-16], (-x), If[LessEqual[y, 3.1e+245], y, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-17}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-109}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-131}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-16}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+245}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.80000000000000008e25 or 3.0999999999999999e245 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 59.2%
if -1.80000000000000008e25 < y < -3.5000000000000002e-17 or -2.39999999999999989e-109 < y < -1.4e-131 or 1.35e-16 < y < 3.0999999999999999e245Initial program 99.9%
Taylor expanded in x around 0 66.3%
if -3.5000000000000002e-17 < y < -2.39999999999999989e-109 or -1.4e-131 < y < 1.35e-16Initial program 100.0%
Taylor expanded in y around 0 79.1%
neg-mul-179.1%
Simplified79.1%
Final simplification70.3%
(FPCore (x y)
:precision binary64
(if (or (<= y -6.5e-33)
(not
(or (<= y -4.8e-110) (and (not (<= y -1.4e-131)) (<= y 6.8e-22)))))
(* (+ x 1.0) y)
(- x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.5e-33) || !((y <= -4.8e-110) || (!(y <= -1.4e-131) && (y <= 6.8e-22)))) {
tmp = (x + 1.0) * 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 <= (-6.5d-33)) .or. (.not. (y <= (-4.8d-110)) .or. (.not. (y <= (-1.4d-131))) .and. (y <= 6.8d-22))) then
tmp = (x + 1.0d0) * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6.5e-33) || !((y <= -4.8e-110) || (!(y <= -1.4e-131) && (y <= 6.8e-22)))) {
tmp = (x + 1.0) * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.5e-33) or not ((y <= -4.8e-110) or (not (y <= -1.4e-131) and (y <= 6.8e-22))): tmp = (x + 1.0) * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.5e-33) || !((y <= -4.8e-110) || (!(y <= -1.4e-131) && (y <= 6.8e-22)))) tmp = Float64(Float64(x + 1.0) * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.5e-33) || ~(((y <= -4.8e-110) || (~((y <= -1.4e-131)) && (y <= 6.8e-22))))) tmp = (x + 1.0) * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.5e-33], N[Not[Or[LessEqual[y, -4.8e-110], And[N[Not[LessEqual[y, -1.4e-131]], $MachinePrecision], LessEqual[y, 6.8e-22]]]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-33} \lor \neg \left(y \leq -4.8 \cdot 10^{-110} \lor \neg \left(y \leq -1.4 \cdot 10^{-131}\right) \land y \leq 6.8 \cdot 10^{-22}\right):\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -6.4999999999999993e-33 or -4.80000000000000013e-110 < y < -1.4e-131 or 6.7999999999999997e-22 < y Initial program 100.0%
Taylor expanded in y around inf 95.6%
if -6.4999999999999993e-33 < y < -4.80000000000000013e-110 or -1.4e-131 < y < 6.7999999999999997e-22Initial program 100.0%
Taylor expanded in y around 0 80.1%
neg-mul-180.1%
Simplified80.1%
Final simplification88.8%
(FPCore (x y) :precision binary64 (if (or (<= x -22500.0) (not (<= x 5.4e-18))) (* x (+ y -1.0)) (* (+ x 1.0) y)))
double code(double x, double y) {
double tmp;
if ((x <= -22500.0) || !(x <= 5.4e-18)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-22500.0d0)) .or. (.not. (x <= 5.4d-18))) then
tmp = x * (y + (-1.0d0))
else
tmp = (x + 1.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -22500.0) || !(x <= 5.4e-18)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -22500.0) or not (x <= 5.4e-18): tmp = x * (y + -1.0) else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -22500.0) || !(x <= 5.4e-18)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(Float64(x + 1.0) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -22500.0) || ~((x <= 5.4e-18))) tmp = x * (y + -1.0); else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -22500.0], N[Not[LessEqual[x, 5.4e-18]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -22500 \lor \neg \left(x \leq 5.4 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if x < -22500 or 5.39999999999999977e-18 < x Initial program 100.0%
Taylor expanded in x around inf 99.8%
if -22500 < x < 5.39999999999999977e-18Initial program 100.0%
Taylor expanded in y around inf 75.3%
Final simplification86.9%
(FPCore (x y) :precision binary64 (if (<= x -5.4e-18) (- x) (if (<= x 3.4e-15) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -5.4e-18) {
tmp = -x;
} else if (x <= 3.4e-15) {
tmp = 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 (x <= (-5.4d-18)) then
tmp = -x
else if (x <= 3.4d-15) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.4e-18) {
tmp = -x;
} else if (x <= 3.4e-15) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.4e-18: tmp = -x elif x <= 3.4e-15: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.4e-18) tmp = Float64(-x); elseif (x <= 3.4e-15) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.4e-18) tmp = -x; elseif (x <= 3.4e-15) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.4e-18], (-x), If[LessEqual[x, 3.4e-15], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-18}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-15}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -5.39999999999999977e-18 or 3.4e-15 < x Initial program 100.0%
Taylor expanded in y around 0 51.3%
neg-mul-151.3%
Simplified51.3%
if -5.39999999999999977e-18 < x < 3.4e-15Initial program 100.0%
Taylor expanded in x around 0 75.5%
Final simplification63.8%
(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 40.7%
Final simplification40.7%
herbie shell --seed 2023185
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))