
(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 (* 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%
associate-*l*93.6%
Simplified93.6%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -3e+153) (not (<= y 5e+138))) (* y (* y (- x))) (* x (* y (- 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -3e+153) || !(y <= 5e+138)) {
tmp = y * (y * -x);
} else {
tmp = x * (y * (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 ((y <= (-3d+153)) .or. (.not. (y <= 5d+138))) then
tmp = y * (y * -x)
else
tmp = x * (y * (1.0d0 - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3e+153) || !(y <= 5e+138)) {
tmp = y * (y * -x);
} else {
tmp = x * (y * (1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3e+153) or not (y <= 5e+138): tmp = y * (y * -x) else: tmp = x * (y * (1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -3e+153) || !(y <= 5e+138)) tmp = Float64(y * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(y * Float64(1.0 - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3e+153) || ~((y <= 5e+138))) tmp = y * (y * -x); else tmp = x * (y * (1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3e+153], N[Not[LessEqual[y, 5e+138]], $MachinePrecision]], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+153} \lor \neg \left(y \leq 5 \cdot 10^{+138}\right):\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\end{array}
\end{array}
if y < -3.00000000000000019e153 or 5.00000000000000016e138 < y Initial program 99.9%
associate-*l*74.9%
Simplified74.9%
Taylor expanded in y around inf 74.9%
unpow274.9%
associate-*r*74.9%
mul-1-neg74.9%
distribute-rgt-neg-out74.9%
associate-*l*99.9%
Simplified99.9%
if -3.00000000000000019e153 < y < 5.00000000000000016e138Initial program 99.9%
associate-*l*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(-Float64(y * 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 y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
associate-*l*87.5%
Simplified87.5%
Taylor expanded in y around inf 85.8%
unpow285.8%
mul-1-neg85.8%
distribute-rgt-neg-out85.8%
Simplified85.8%
if -1 < y < 1Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 96.3%
Final simplification91.0%
(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*87.5%
Simplified87.5%
Taylor expanded in y around inf 85.8%
unpow285.8%
associate-*r*85.8%
mul-1-neg85.8%
distribute-rgt-neg-out85.8%
associate-*l*98.1%
Simplified98.1%
if -1 < y < 1Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around 0 96.3%
Final simplification97.2%
(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*95.5%
Simplified95.5%
Taylor expanded in y around 0 74.1%
if 1 < y Initial program 99.8%
associate-*l*88.1%
Simplified88.1%
associate-*r*99.8%
flip--88.1%
associate-*r/85.2%
metadata-eval85.2%
+-commutative85.2%
Applied egg-rr85.2%
associate-*l*82.3%
associate-/l*82.3%
sub-neg82.3%
distribute-rgt-neg-out82.3%
distribute-rgt-in82.3%
*-lft-identity82.3%
distribute-rgt-neg-out82.3%
distribute-lft-neg-in82.3%
unpow382.2%
unsub-neg82.2%
Simplified82.2%
Taylor expanded in y around 0 0.9%
*-un-lft-identity0.9%
add-sqr-sqrt0.9%
sqrt-unprod0.9%
frac-times0.8%
metadata-eval0.8%
metadata-eval0.8%
frac-times0.9%
sqrt-unprod0.0%
add-sqr-sqrt32.4%
div-inv32.4%
times-frac32.4%
metadata-eval32.4%
associate-/r/32.4%
/-rgt-identity32.4%
*-commutative32.4%
neg-mul-132.4%
distribute-lft-neg-in32.4%
Applied egg-rr32.4%
Final simplification63.5%
(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*93.6%
Simplified93.6%
Taylor expanded in y around 0 55.5%
Final simplification55.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 99.9%
associate-*l*93.6%
Simplified93.6%
associate-*r*99.9%
flip--93.6%
associate-*r/92.2%
metadata-eval92.2%
+-commutative92.2%
Applied egg-rr92.2%
*-commutative92.2%
associate-/l*93.3%
*-commutative93.3%
Simplified93.3%
Taylor expanded in y around inf 45.8%
Taylor expanded in y around 0 2.9%
Final simplification2.9%
herbie shell --seed 2023200
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))