
(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 6 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 -5e+93) (not (<= y 3e+138))) (* y (* x (- y))) (* x (- y (* y y)))))
double code(double x, double y) {
double tmp;
if ((y <= -5e+93) || !(y <= 3e+138)) {
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 <= (-5d+93)) .or. (.not. (y <= 3d+138))) 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 <= -5e+93) || !(y <= 3e+138)) {
tmp = y * (x * -y);
} else {
tmp = x * (y - (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+93) or not (y <= 3e+138): tmp = y * (x * -y) else: tmp = x * (y - (y * y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+93) || !(y <= 3e+138)) 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 <= -5e+93) || ~((y <= 3e+138))) tmp = y * (x * -y); else tmp = x * (y - (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+93], N[Not[LessEqual[y, 3e+138]], $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 -5 \cdot 10^{+93} \lor \neg \left(y \leq 3 \cdot 10^{+138}\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 < -5.0000000000000001e93 or 3.0000000000000001e138 < y Initial program 99.9%
distribute-lft-out--83.7%
*-rgt-identity83.7%
associate-*l*65.5%
distribute-lft-out--81.7%
Simplified81.7%
Taylor expanded in y around inf 81.7%
unpow281.7%
associate-*r*81.7%
mul-1-neg81.7%
distribute-rgt-neg-out81.7%
associate-*l*99.9%
*-commutative99.9%
Simplified99.9%
if -5.0000000000000001e93 < y < 3.0000000000000001e138Initial program 99.9%
distribute-lft-out--97.5%
*-rgt-identity97.5%
associate-*l*97.5%
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.4%
*-rgt-identity86.4%
associate-*l*74.5%
distribute-lft-out--87.9%
Simplified87.9%
Taylor expanded in y around inf 87.5%
unpow287.5%
mul-1-neg87.5%
distribute-rgt-neg-out87.5%
Simplified87.5%
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.4%
Final simplification92.8%
(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.4%
*-rgt-identity86.4%
associate-*l*74.5%
distribute-lft-out--87.9%
Simplified87.9%
Taylor expanded in y around inf 87.5%
unpow287.5%
associate-*r*87.5%
mul-1-neg87.5%
distribute-rgt-neg-out87.5%
associate-*l*99.4%
*-commutative99.4%
Simplified99.4%
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.4%
Final simplification99.4%
(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 (if (<= y 1.0) (* x y) (* x (- y))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = 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) then
tmp = 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) {
tmp = x * y;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x * y else: tmp = x * -y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(x * y); else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = x * y; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], N[(x * y), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 1Initial program 99.9%
distribute-lft-out--99.9%
*-rgt-identity99.9%
associate-*l*95.9%
distribute-lft-out--95.9%
Simplified95.9%
Taylor expanded in y around 0 73.9%
if 1 < y Initial program 99.8%
distribute-lft-out--74.1%
*-rgt-identity74.1%
associate-*l*61.3%
distribute-lft-out--87.0%
Simplified87.0%
*-un-lft-identity87.0%
distribute-rgt-out--87.0%
associate-*l*99.8%
flip--87.0%
associate-*r/79.4%
metadata-eval79.4%
+-commutative79.4%
Applied egg-rr79.4%
associate-*l*70.3%
associate-/l*72.8%
sub-neg72.8%
distribute-rgt-neg-out72.8%
distribute-rgt-in72.8%
*-lft-identity72.8%
distribute-rgt-neg-out72.8%
distribute-lft-neg-in72.8%
unpow372.9%
unsub-neg72.9%
Simplified72.9%
Taylor expanded in y around 0 0.8%
frac-2neg0.8%
div-inv0.8%
neg-mul-10.8%
div-inv0.8%
add-sqr-sqrt0.0%
sqrt-unprod50.6%
frac-times51.8%
metadata-eval51.8%
metadata-eval51.8%
frac-times50.6%
sqrt-unprod30.1%
add-sqr-sqrt30.1%
remove-double-div30.1%
Applied egg-rr30.1%
Final simplification61.3%
(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--92.5%
*-rgt-identity92.5%
associate-*l*85.9%
distribute-lft-out--93.3%
Simplified93.3%
Taylor expanded in y around 0 52.8%
Final simplification52.8%
herbie shell --seed 2023196
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))