
(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 5 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 -2.8e+25) (not (<= y 1e+118))) (* y (* x (- y))) (* x (- y (* y y)))))
double code(double x, double y) {
double tmp;
if ((y <= -2.8e+25) || !(y <= 1e+118)) {
tmp = y * (x * -y);
} 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 <= (-2.8d+25)) .or. (.not. (y <= 1d+118))) then
tmp = y * (x * -y)
else
tmp = x * (y - (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.8e+25) || !(y <= 1e+118)) {
tmp = y * (x * -y);
} else {
tmp = x * (y - (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.8e+25) or not (y <= 1e+118): tmp = y * (x * -y) else: tmp = x * (y - (y * y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.8e+25) || !(y <= 1e+118)) tmp = Float64(y * Float64(x * Float64(-y))); else tmp = Float64(x * Float64(y - Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.8e+25) || ~((y <= 1e+118))) tmp = y * (x * -y); else tmp = x * (y - (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.8e+25], N[Not[LessEqual[y, 1e+118]], $MachinePrecision]], N[(y * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * N[(y - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+25} \lor \neg \left(y \leq 10^{+118}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - y \cdot y\right)\\
\end{array}
\end{array}
if y < -2.8000000000000002e25 or 9.99999999999999967e117 < y Initial program 99.8%
distribute-lft-out--82.6%
*-rgt-identity82.6%
associate-*l*65.7%
distribute-lft-out--82.9%
Simplified82.9%
Taylor expanded in y around inf 82.9%
unpow282.9%
associate-*r*82.9%
mul-1-neg82.9%
distribute-rgt-neg-out82.9%
associate-*l*99.8%
*-commutative99.8%
Simplified99.8%
if -2.8000000000000002e25 < y < 9.99999999999999967e117Initial program 99.9%
distribute-lft-out--99.3%
*-rgt-identity99.3%
associate-*l*99.3%
distribute-lft-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))) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * (y * -y);
} 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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * (y * -y)
else
tmp = x * y
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 = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = x * (y * -y) else: tmp = x * y 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(x * y); 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 = x * y; 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[(x * y), $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}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
distribute-lft-out--86.3%
*-rgt-identity86.3%
associate-*l*73.8%
distribute-lft-out--87.3%
Simplified87.3%
Taylor expanded in y around inf 85.1%
unpow285.1%
mul-1-neg85.1%
distribute-rgt-neg-out85.1%
Simplified85.1%
if -1 < y < 1Initial program 100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-*l*100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 99.0%
Final simplification92.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (* x (- y))) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x * -y);
} 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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x * -y)
else
tmp = x * y
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 * (x * -y);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (x * -y) else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x * Float64(-y))); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (x * -y); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
distribute-lft-out--86.3%
*-rgt-identity86.3%
associate-*l*73.8%
distribute-lft-out--87.3%
Simplified87.3%
Taylor expanded in y around inf 85.1%
unpow285.1%
associate-*r*85.1%
mul-1-neg85.1%
distribute-rgt-neg-out85.1%
associate-*l*97.6%
*-commutative97.6%
Simplified97.6%
if -1 < y < 1Initial program 100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-*l*100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 99.0%
Final simplification98.3%
(FPCore (x y) :precision binary64 (* (- 1.0 y) (* x y)))
double code(double x, double y) {
return (1.0 - y) * (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - y) * (x * y)
end function
public static double code(double x, double y) {
return (1.0 - y) * (x * y);
}
def code(x, y): return (1.0 - y) * (x * y)
function code(x, y) return Float64(Float64(1.0 - y) * Float64(x * y)) end
function tmp = code(x, y) tmp = (1.0 - y) * (x * y); end
code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - y\right) \cdot \left(x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (* x y))
double code(double x, double y) {
return x * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * y
end function
public static double code(double x, double y) {
return x * y;
}
def code(x, y): return x * y
function code(x, y) return Float64(x * y) end
function tmp = code(x, y) tmp = x * y; end
code[x_, y_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.9%
distribute-lft-out--93.3%
*-rgt-identity93.3%
associate-*l*87.1%
distribute-lft-out--93.8%
Simplified93.8%
Taylor expanded in y around 0 57.2%
Final simplification57.2%
herbie shell --seed 2023224
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))