
(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 (if (or (<= y -1.3e+170) (not (<= y 3.1e+109))) (* y (* y (- x))) (* x (- y (* y y)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.3e+170) || !(y <= 3.1e+109)) {
tmp = y * (y * -x);
} else {
tmp = x * (y - (y * 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.3d+170)) .or. (.not. (y <= 3.1d+109))) then
tmp = y * (y * -x)
else
tmp = x * (y - (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.3e+170) || !(y <= 3.1e+109)) {
tmp = y * (y * -x);
} else {
tmp = x * (y - (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.3e+170) or not (y <= 3.1e+109): tmp = y * (y * -x) else: tmp = x * (y - (y * y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.3e+170) || !(y <= 3.1e+109)) tmp = Float64(y * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(y - Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.3e+170) || ~((y <= 3.1e+109))) tmp = y * (y * -x); else tmp = x * (y - (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.3e+170], N[Not[LessEqual[y, 3.1e+109]], $MachinePrecision]], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(y - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+170} \lor \neg \left(y \leq 3.1 \cdot 10^{+109}\right):\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - y \cdot y\right)\\
\end{array}
\end{array}
if y < -1.2999999999999999e170 or 3.09999999999999992e109 < y Initial program 99.9%
distribute-rgt-out--84.8%
*-lft-identity84.8%
*-commutative84.8%
associate-*r*55.0%
*-commutative55.0%
distribute-rgt-out--70.2%
Simplified70.2%
Taylor expanded in y around inf 70.2%
unpow270.2%
associate-*r*70.2%
associate-*r*99.9%
mul-1-neg99.9%
Simplified99.9%
if -1.2999999999999999e170 < y < 3.09999999999999992e109Initial program 99.9%
distribute-rgt-out--98.3%
*-lft-identity98.3%
*-commutative98.3%
associate-*r*98.3%
*-commutative98.3%
distribute-rgt-out--99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* x (* y (- y))) (* y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * (y * -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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * (y * -y)
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 = x * (y * -y);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = x * (y * -y) else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(x * Float64(y * Float64(-y))); 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 = x * (y * -y); 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[(x * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
distribute-rgt-out--89.4%
*-lft-identity89.4%
*-commutative89.4%
associate-*r*73.7%
*-commutative73.7%
distribute-rgt-out--84.2%
Simplified84.2%
Taylor expanded in y around inf 80.4%
unpow280.4%
mul-1-neg80.4%
distribute-rgt-neg-out80.4%
Simplified80.4%
if -1 < y < 1Initial program 99.9%
distribute-rgt-out--100.0%
*-lft-identity100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
Final simplification89.4%
(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%
distribute-rgt-out--89.4%
*-lft-identity89.4%
*-commutative89.4%
associate-*r*73.7%
*-commutative73.7%
distribute-rgt-out--84.2%
Simplified84.2%
Taylor expanded in y around inf 80.4%
unpow280.4%
associate-*r*80.4%
associate-*r*96.1%
mul-1-neg96.1%
Simplified96.1%
if -1 < y < 1Initial program 99.9%
distribute-rgt-out--100.0%
*-lft-identity100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
Final simplification97.0%
(FPCore (x y) :precision binary64 (* y (* (- 1.0 y) x)))
double code(double x, double y) {
return y * ((1.0 - y) * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * ((1.0d0 - y) * x)
end function
public static double code(double x, double y) {
return y * ((1.0 - y) * x);
}
def code(x, y): return y * ((1.0 - y) * x)
function code(x, y) return Float64(y * Float64(Float64(1.0 - y) * x)) end
function tmp = code(x, y) tmp = y * ((1.0 - y) * x); end
code[x_, y_] := N[(y * N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(\left(1 - y\right) \cdot x\right)
\end{array}
Initial program 99.9%
distribute-rgt-out--94.8%
*-lft-identity94.8%
*-commutative94.8%
associate-*r*87.2%
*-commutative87.2%
distribute-rgt-out--92.2%
Simplified92.2%
Taylor expanded in x around 0 92.2%
unpow292.2%
sub-neg92.2%
distribute-rgt-neg-out92.2%
distribute-lft-out87.2%
*-rgt-identity87.2%
associate-*r*94.8%
distribute-lft-in99.9%
sub-neg99.9%
associate-*r*92.3%
*-commutative92.3%
associate-*l*99.9%
Simplified99.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%
distribute-rgt-out--99.9%
*-lft-identity99.9%
*-commutative99.9%
associate-*r*94.7%
*-commutative94.7%
distribute-rgt-out--94.8%
Simplified94.8%
Taylor expanded in y around 0 71.6%
if 1 < y Initial program 99.8%
distribute-rgt-out--77.4%
*-lft-identity77.4%
*-commutative77.4%
associate-*r*61.2%
*-commutative61.2%
distribute-rgt-out--83.7%
Simplified83.7%
flip--42.2%
associate-*r/42.1%
pow242.1%
pow242.1%
pow-prod-up42.2%
metadata-eval42.2%
+-commutative42.2%
fma-def42.2%
Applied egg-rr42.2%
associate-/l*42.2%
Simplified42.2%
Taylor expanded in y around 0 0.9%
frac-2neg0.9%
div-inv0.9%
neg-mul-10.9%
div-inv0.9%
clear-num0.9%
div-inv0.9%
metadata-eval0.9%
*-commutative0.9%
neg-mul-10.9%
add-sqr-sqrt0.0%
sqrt-unprod41.2%
sqr-neg41.2%
sqrt-prod28.0%
add-sqr-sqrt28.0%
Applied egg-rr28.0%
Final simplification61.7%
(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%
distribute-rgt-out--94.8%
*-lft-identity94.8%
*-commutative94.8%
associate-*r*87.2%
*-commutative87.2%
distribute-rgt-out--92.2%
Simplified92.2%
Taylor expanded in y around 0 55.6%
Final simplification55.6%
(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%
distribute-rgt-out--94.8%
*-lft-identity94.8%
*-commutative94.8%
associate-*r*87.2%
*-commutative87.2%
distribute-rgt-out--92.2%
Simplified92.2%
Taylor expanded in x around 0 92.2%
unpow292.2%
sub-neg92.2%
distribute-rgt-neg-out92.2%
distribute-lft-out87.2%
*-rgt-identity87.2%
associate-*r*94.8%
distribute-lft-in99.9%
sub-neg99.9%
associate-*r*92.3%
*-commutative92.3%
associate-*l*99.9%
Simplified99.9%
*-commutative99.9%
associate-*l*99.9%
flip--92.2%
metadata-eval92.2%
+-commutative92.2%
associate-/r/91.4%
associate-/l*89.8%
*-commutative89.8%
associate-*l*85.7%
Applied egg-rr85.7%
Taylor expanded in y around 0 51.3%
Taylor expanded in y around inf 2.9%
Final simplification2.9%
herbie shell --seed 2023275
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))