
(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 8 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 (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, y\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.1e+290)
y
(if (<= y -9.2e+125)
(* x y)
(if (<= y -2.6e-29) y (if (<= y 1.0) (- x) (* x y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.1e+290) {
tmp = y;
} else if (y <= -9.2e+125) {
tmp = x * y;
} else if (y <= -2.6e-29) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} 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.1d+290)) then
tmp = y
else if (y <= (-9.2d+125)) then
tmp = x * y
else if (y <= (-2.6d-29)) then
tmp = y
else if (y <= 1.0d0) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.1e+290) {
tmp = y;
} else if (y <= -9.2e+125) {
tmp = x * y;
} else if (y <= -2.6e-29) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1e+290: tmp = y elif y <= -9.2e+125: tmp = x * y elif y <= -2.6e-29: tmp = y elif y <= 1.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1e+290) tmp = y; elseif (y <= -9.2e+125) tmp = Float64(x * y); elseif (y <= -2.6e-29) tmp = y; elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.1e+290) tmp = y; elseif (y <= -9.2e+125) tmp = x * y; elseif (y <= -2.6e-29) tmp = y; elseif (y <= 1.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1e+290], y, If[LessEqual[y, -9.2e+125], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.6e-29], y, If[LessEqual[y, 1.0], (-x), N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+290}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{+125}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-29}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.1e290 or -9.20000000000000051e125 < y < -2.6000000000000002e-29Initial program 100.0%
Taylor expanded in x around 0 75.3%
Taylor expanded in y around inf 74.0%
if -1.1e290 < y < -9.20000000000000051e125 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 57.7%
*-commutative57.7%
Simplified57.7%
Taylor expanded in y around inf 57.7%
if -2.6000000000000002e-29 < y < 1Initial program 100.0%
Taylor expanded in y around 0 76.6%
neg-mul-176.6%
Simplified76.6%
(FPCore (x y) :precision binary64 (if (<= y -3.9e+289) y (if (or (<= y -1e+194) (not (<= y 1.75e+19))) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (y <= -3.9e+289) {
tmp = y;
} else if ((y <= -1e+194) || !(y <= 1.75e+19)) {
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 (y <= (-3.9d+289)) then
tmp = y
else if ((y <= (-1d+194)) .or. (.not. (y <= 1.75d+19))) 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 (y <= -3.9e+289) {
tmp = y;
} else if ((y <= -1e+194) || !(y <= 1.75e+19)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.9e+289: tmp = y elif (y <= -1e+194) or not (y <= 1.75e+19): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -3.9e+289) tmp = y; elseif ((y <= -1e+194) || !(y <= 1.75e+19)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.9e+289) tmp = y; elseif ((y <= -1e+194) || ~((y <= 1.75e+19))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.9e+289], y, If[Or[LessEqual[y, -1e+194], N[Not[LessEqual[y, 1.75e+19]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+289}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1 \cdot 10^{+194} \lor \neg \left(y \leq 1.75 \cdot 10^{+19}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3.90000000000000033e289Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 100.0%
if -3.90000000000000033e289 < y < -9.99999999999999945e193 or 1.75e19 < y Initial program 100.0%
Taylor expanded in x around inf 62.5%
*-commutative62.5%
Simplified62.5%
Taylor expanded in y around inf 62.5%
if -9.99999999999999945e193 < y < 1.75e19Initial program 100.0%
Taylor expanded in x around 0 90.1%
Final simplification83.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 5.6e-25))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 5.6e-25)) {
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 <= 5.6d-25))) 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 <= 5.6e-25)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 5.6e-25): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 5.6e-25)) 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 <= 5.6e-25))) 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, 5.6e-25]], $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 5.6 \cdot 10^{-25}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 5.59999999999999976e-25 < x Initial program 100.0%
Taylor expanded in x around inf 98.6%
*-commutative98.6%
Simplified98.6%
if -1 < x < 5.59999999999999976e-25Initial program 100.0%
Taylor expanded in x around 0 99.4%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.4e-48) (not (<= x 1.55e-34))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.4e-48) || !(x <= 1.55e-34)) {
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 <= (-1.4d-48)) .or. (.not. (x <= 1.55d-34))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.4e-48) || !(x <= 1.55e-34)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.4e-48) or not (x <= 1.55e-34): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.4e-48) || !(x <= 1.55e-34)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.4e-48) || ~((x <= 1.55e-34))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.4e-48], N[Not[LessEqual[x, 1.55e-34]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-48} \lor \neg \left(x \leq 1.55 \cdot 10^{-34}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.40000000000000002e-48 or 1.5499999999999999e-34 < x Initial program 100.0%
Taylor expanded in y around 0 55.5%
neg-mul-155.5%
Simplified55.5%
if -1.40000000000000002e-48 < x < 1.5499999999999999e-34Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 78.0%
Final simplification65.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 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 76.8%
Taylor expanded in y around inf 37.7%
(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 41.0%
neg-mul-141.0%
Simplified41.0%
neg-sub041.0%
sub-neg41.0%
add-sqr-sqrt18.1%
sqrt-unprod15.9%
sqr-neg15.9%
sqrt-unprod1.4%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
+-lft-identity2.6%
Simplified2.6%
herbie shell --seed 2024110
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))