
(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 7 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%
(FPCore (x y) :precision binary64 (if (<= x -6.4e+131) (* x y) (if (or (<= x -1.9e-28) (not (<= x 4.2e-16))) (- x) y)))
double code(double x, double y) {
double tmp;
if (x <= -6.4e+131) {
tmp = x * y;
} else if ((x <= -1.9e-28) || !(x <= 4.2e-16)) {
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 (x <= (-6.4d+131)) then
tmp = x * y
else if ((x <= (-1.9d-28)) .or. (.not. (x <= 4.2d-16))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.4e+131) {
tmp = x * y;
} else if ((x <= -1.9e-28) || !(x <= 4.2e-16)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.4e+131: tmp = x * y elif (x <= -1.9e-28) or not (x <= 4.2e-16): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -6.4e+131) tmp = Float64(x * y); elseif ((x <= -1.9e-28) || !(x <= 4.2e-16)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.4e+131) tmp = x * y; elseif ((x <= -1.9e-28) || ~((x <= 4.2e-16))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.4e+131], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, -1.9e-28], N[Not[LessEqual[x, 4.2e-16]], $MachinePrecision]], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{+131}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-28} \lor \neg \left(x \leq 4.2 \cdot 10^{-16}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.4000000000000004e131Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 62.8%
if -6.4000000000000004e131 < x < -1.90000000000000005e-28 or 4.2000000000000002e-16 < x Initial program 100.0%
Taylor expanded in y around 0 62.7%
neg-mul-162.7%
Simplified62.7%
if -1.90000000000000005e-28 < x < 4.2000000000000002e-16Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 81.6%
Final simplification71.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.02))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.02)) {
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 <= 0.02d0))) 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 <= 0.02)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.02): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.02)) 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 <= 0.02))) 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, 0.02]], $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 0.02\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.0200000000000000004 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
*-commutative98.1%
Simplified98.1%
if -1 < x < 0.0200000000000000004Initial program 100.0%
Taylor expanded in x around 0 98.6%
Final simplification98.3%
(FPCore (x y) :precision binary64 (if (<= y -1.95e-103) y (if (<= y 2.65e-21) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.95e-103) {
tmp = y;
} else if (y <= 2.65e-21) {
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 <= (-1.95d-103)) then
tmp = y
else if (y <= 2.65d-21) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.95e-103) {
tmp = y;
} else if (y <= 2.65e-21) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.95e-103: tmp = y elif y <= 2.65e-21: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.95e-103) tmp = y; elseif (y <= 2.65e-21) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.95e-103) tmp = y; elseif (y <= 2.65e-21) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.95e-103], y, If[LessEqual[y, 2.65e-21], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-103}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.9500000000000001e-103 or 2.65e-21 < y Initial program 100.0%
Taylor expanded in x around 0 62.8%
Taylor expanded in y around inf 57.3%
if -1.9500000000000001e-103 < y < 2.65e-21Initial program 100.0%
Taylor expanded in y around 0 86.3%
neg-mul-186.3%
Simplified86.3%
(FPCore (x y) :precision binary64 (if (<= x -5.5e+131) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if (x <= -5.5e+131) {
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 <= (-5.5d+131)) 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 <= -5.5e+131) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.5e+131: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.5e+131) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.5e+131) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.5e+131], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+131}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -5.49999999999999971e131Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 62.8%
if -5.49999999999999971e131 < x Initial program 100.0%
Taylor expanded in x around 0 84.2%
(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 77.6%
Taylor expanded in y around inf 40.5%
(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 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 39.0%
neg-mul-139.0%
Simplified39.0%
neg-sub039.0%
sub-neg39.0%
add-sqr-sqrt19.3%
sqrt-unprod19.4%
sqr-neg19.4%
sqrt-unprod1.2%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024111
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))