
(FPCore (x y) :precision binary64 (* (* x y) (- 1.0 y)))
double code(double x, double y) {
return (x * y) * (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) * (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x * y) * (1.0 - y);
}
def code(x, y): return (x * y) * (1.0 - y)
function code(x, y) return Float64(Float64(x * y) * Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x * y) * (1.0 - y); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* x y) (- 1.0 y)))
double code(double x, double y) {
return (x * y) * (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) * (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x * y) * (1.0 - y);
}
def code(x, y): return (x * y) * (1.0 - y)
function code(x, y) return Float64(Float64(x * y) * Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x * y) * (1.0 - y); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot \left(1 - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma y x (* y (* y (- x)))))
double code(double x, double y) {
return fma(y, x, (y * (y * -x)));
}
function code(x, y) return fma(y, x, Float64(y * Float64(y * Float64(-x)))) end
code[x_, y_] := N[(y * x + N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, y \cdot \left(y \cdot \left(-x\right)\right)\right)
\end{array}
Initial program 99.9%
associate-*l*96.2%
Simplified96.2%
associate-*r*99.9%
sub-neg99.9%
distribute-lft-in95.2%
*-commutative95.2%
*-un-lft-identity95.2%
*-commutative95.2%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (* y (- x))) (* y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (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 ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (y * -x)
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (y * -x);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (y * -x) else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(y * Float64(-x))); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (y * -x); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
associate-*l*92.8%
Simplified92.8%
associate-*r*99.8%
sub-neg99.8%
distribute-lft-in90.7%
*-commutative90.7%
*-un-lft-identity90.7%
*-commutative90.7%
fma-def99.8%
Applied egg-rr99.8%
fma-udef90.7%
*-commutative90.7%
distribute-rgt-neg-out90.7%
distribute-lft-neg-in90.7%
add-sqr-sqrt41.5%
sqrt-unprod36.8%
sqr-neg36.8%
sqrt-unprod0.3%
add-sqr-sqrt0.6%
cancel-sign-sub-inv0.6%
add-sqr-sqrt0.3%
cancel-sign-sub-inv0.3%
Applied egg-rr45.2%
add-sqr-sqrt26.4%
sqrt-unprod26.5%
sqr-neg26.5%
sqrt-unprod0.1%
add-sqr-sqrt0.3%
cancel-sign-sub0.3%
associate-*r*0.3%
distribute-rgt-out--0.3%
*-commutative0.3%
add-sqr-sqrt0.1%
sqrt-unprod22.7%
sqr-neg22.7%
sqrt-unprod22.6%
Applied egg-rr99.8%
Taylor expanded in y around inf 97.7%
associate-*r*97.7%
neg-mul-197.7%
*-commutative97.7%
Simplified97.7%
if -1 < y < 1Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 96.2%
Final simplification97.0%
(FPCore (x y) :precision binary64 (if (<= y 1.5e+126) (* x (* y (- 1.0 y))) (* y (* y (- x)))))
double code(double x, double y) {
double tmp;
if (y <= 1.5e+126) {
tmp = x * (y * (1.0 - y));
} else {
tmp = y * (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 <= 1.5d+126) then
tmp = x * (y * (1.0d0 - y))
else
tmp = y * (y * -x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.5e+126) {
tmp = x * (y * (1.0 - y));
} else {
tmp = y * (y * -x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.5e+126: tmp = x * (y * (1.0 - y)) else: tmp = y * (y * -x) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.5e+126) tmp = Float64(x * Float64(y * Float64(1.0 - y))); else tmp = Float64(y * Float64(y * Float64(-x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.5e+126) tmp = x * (y * (1.0 - y)); else tmp = y * (y * -x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.5e+126], N[(x * N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{+126}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if y < 1.5000000000000001e126Initial program 99.9%
associate-*l*98.6%
Simplified98.6%
if 1.5000000000000001e126 < y Initial program 99.9%
associate-*l*82.1%
Simplified82.1%
associate-*r*99.9%
sub-neg99.9%
distribute-lft-in67.5%
*-commutative67.5%
*-un-lft-identity67.5%
*-commutative67.5%
fma-def99.9%
Applied egg-rr99.9%
fma-udef67.5%
*-commutative67.5%
distribute-rgt-neg-out67.5%
distribute-lft-neg-in67.5%
add-sqr-sqrt67.4%
sqrt-unprod49.7%
sqr-neg49.7%
sqrt-unprod0.0%
add-sqr-sqrt0.2%
cancel-sign-sub-inv0.2%
add-sqr-sqrt0.1%
cancel-sign-sub-inv0.1%
Applied egg-rr37.6%
add-sqr-sqrt0.0%
sqrt-unprod0.1%
sqr-neg0.1%
sqrt-unprod0.1%
add-sqr-sqrt0.1%
cancel-sign-sub0.1%
associate-*r*0.1%
distribute-rgt-out--0.1%
*-commutative0.1%
add-sqr-sqrt0.0%
sqrt-unprod51.2%
sqr-neg51.2%
sqrt-unprod51.2%
Applied egg-rr99.9%
Taylor expanded in y around inf 99.9%
associate-*r*99.9%
neg-mul-199.9%
*-commutative99.9%
Simplified99.9%
Final simplification98.8%
(FPCore (x y) :precision binary64 (* y (- x (* y x))))
double code(double x, double y) {
return y * (x - (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (x - (y * x))
end function
public static double code(double x, double y) {
return y * (x - (y * x));
}
def code(x, y): return y * (x - (y * x))
function code(x, y) return Float64(y * Float64(x - Float64(y * x))) end
function tmp = code(x, y) tmp = y * (x - (y * x)); end
code[x_, y_] := N[(y * N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x - y \cdot x\right)
\end{array}
Initial program 99.9%
associate-*l*96.2%
Simplified96.2%
associate-*r*99.9%
sub-neg99.9%
distribute-lft-in95.2%
*-commutative95.2%
*-un-lft-identity95.2%
*-commutative95.2%
fma-def99.9%
Applied egg-rr99.9%
fma-udef95.2%
*-commutative95.2%
distribute-rgt-neg-out95.2%
distribute-lft-neg-in95.2%
add-sqr-sqrt43.6%
sqrt-unprod66.3%
sqr-neg66.3%
sqrt-unprod25.2%
add-sqr-sqrt46.9%
cancel-sign-sub-inv46.9%
add-sqr-sqrt35.3%
cancel-sign-sub-inv35.3%
Applied egg-rr47.5%
add-sqr-sqrt29.6%
sqrt-unprod37.9%
sqr-neg37.9%
sqrt-unprod12.2%
add-sqr-sqrt23.3%
cancel-sign-sub23.3%
associate-*r*23.3%
distribute-rgt-out--23.3%
*-commutative23.3%
add-sqr-sqrt15.0%
sqrt-unprod34.9%
sqr-neg34.9%
sqrt-unprod23.8%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* y x) (* y (- x))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = 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 (y <= 1.0d0) then
tmp = y * x
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = y * x;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = y * x else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(y * x); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = y * x; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], N[(y * x), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < 1Initial program 99.9%
associate-*l*98.4%
Simplified98.4%
Taylor expanded in y around 0 74.3%
if 1 < y Initial program 99.8%
associate-*l*90.1%
Simplified90.1%
associate-*r*99.8%
flip--89.9%
associate-*r/83.1%
metadata-eval83.1%
pow283.1%
+-commutative83.1%
Applied egg-rr83.1%
associate-*l*78.8%
associate-/l*80.0%
sub-neg80.0%
distribute-lft-in80.0%
*-rgt-identity80.0%
distribute-rgt-neg-in80.0%
unpow280.0%
cube-mult80.1%
unsub-neg80.1%
Simplified80.1%
Taylor expanded in y around 0 0.9%
associate-/r/0.9%
/-rgt-identity0.9%
add-sqr-sqrt0.3%
associate-*l*0.3%
add-sqr-sqrt0.3%
sqrt-unprod0.3%
sqr-neg0.3%
sqrt-unprod0.0%
add-sqr-sqrt9.8%
*-commutative9.8%
neg-mul-19.8%
associate-*l*9.8%
*-commutative9.8%
associate-*r*9.8%
add-sqr-sqrt23.5%
*-commutative23.5%
Applied egg-rr23.5%
neg-mul-123.5%
distribute-rgt-neg-in23.5%
Simplified23.5%
Final simplification61.0%
(FPCore (x y) :precision binary64 (* y x))
double code(double x, double y) {
return y * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * x
end function
public static double code(double x, double y) {
return y * x;
}
def code(x, y): return y * x
function code(x, y) return Float64(y * x) end
function tmp = code(x, y) tmp = y * x; end
code[x_, y_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 99.9%
associate-*l*96.2%
Simplified96.2%
Taylor expanded in y around 0 55.1%
Final simplification55.1%
(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 99.9%
associate-*l*96.2%
Simplified96.2%
associate-*r*99.9%
flip--96.2%
associate-*r/92.3%
metadata-eval92.3%
pow292.3%
+-commutative92.3%
Applied egg-rr92.3%
associate-*l*89.7%
associate-/l*91.2%
sub-neg91.2%
distribute-lft-in91.2%
*-rgt-identity91.2%
distribute-rgt-neg-in91.2%
unpow291.2%
cube-mult91.3%
unsub-neg91.3%
Simplified91.3%
Taylor expanded in y around 0 47.5%
Taylor expanded in y around inf 2.8%
Final simplification2.8%
herbie shell --seed 2023322
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))