
(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+49) (not (<= y 1.05e+71))) (* y (* x (- y))) (* x (* y (- 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -5e+49) || !(y <= 1.05e+71)) {
tmp = y * (x * -y);
} 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 <= (-5d+49)) .or. (.not. (y <= 1.05d+71))) then
tmp = y * (x * -y)
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 <= -5e+49) || !(y <= 1.05e+71)) {
tmp = y * (x * -y);
} else {
tmp = x * (y * (1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+49) or not (y <= 1.05e+71): tmp = y * (x * -y) else: tmp = x * (y * (1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+49) || !(y <= 1.05e+71)) tmp = Float64(y * Float64(x * Float64(-y))); 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 <= -5e+49) || ~((y <= 1.05e+71))) tmp = y * (x * -y); else tmp = x * (y * (1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+49], N[Not[LessEqual[y, 1.05e+71]], $MachinePrecision]], N[(y * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+49} \lor \neg \left(y \leq 1.05 \cdot 10^{+71}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\end{array}
\end{array}
if y < -5.0000000000000004e49 or 1.04999999999999995e71 < y Initial program 99.8%
associate-*l*85.6%
Simplified85.6%
associate-*r*99.8%
flip--85.7%
associate-*r/77.8%
metadata-eval77.8%
pow277.8%
+-commutative77.8%
Applied egg-rr77.8%
associate-/l*85.7%
Simplified85.7%
div-inv85.7%
clear-num85.7%
metadata-eval85.7%
unpow285.7%
+-commutative85.7%
flip--99.8%
associate-*r*85.6%
*-commutative85.6%
associate-*r*99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 99.8%
neg-mul-199.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -5.0000000000000004e49 < y < 1.04999999999999995e71Initial program 99.9%
associate-*l*100.0%
Simplified100.0%
Final simplification99.9%
(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%
associate-*l*88.8%
Simplified88.8%
associate-*r*99.8%
flip--88.7%
associate-*r/81.9%
metadata-eval81.9%
pow281.9%
+-commutative81.9%
Applied egg-rr81.9%
associate-/l*88.7%
Simplified88.7%
div-inv88.7%
clear-num88.7%
metadata-eval88.7%
unpow288.7%
+-commutative88.7%
flip--99.8%
associate-*r*88.8%
*-commutative88.8%
associate-*r*99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 97.9%
neg-mul-197.9%
distribute-rgt-neg-in97.9%
Simplified97.9%
if -1 < y < 1Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in y around 0 97.5%
Final simplification97.7%
(FPCore (x y) :precision binary64 (* y (* x (- 1.0 y))))
double code(double x, double y) {
return y * (x * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (x * (1.0d0 - y))
end function
public static double code(double x, double y) {
return y * (x * (1.0 - y));
}
def code(x, y): return y * (x * (1.0 - y))
function code(x, y) return Float64(y * Float64(x * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = y * (x * (1.0 - y)); end
code[x_, y_] := N[(y * N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot \left(1 - y\right)\right)
\end{array}
Initial program 99.9%
associate-*l*94.8%
Simplified94.8%
associate-*r*99.9%
flip--94.7%
associate-*r/91.6%
metadata-eval91.6%
pow291.6%
+-commutative91.6%
Applied egg-rr91.6%
associate-/l*94.7%
Simplified94.7%
div-inv94.7%
clear-num94.7%
metadata-eval94.7%
unpow294.7%
+-commutative94.7%
flip--99.9%
associate-*r*94.8%
*-commutative94.8%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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%
associate-*l*96.1%
Simplified96.1%
Taylor expanded in y around 0 75.2%
if 1 < y Initial program 99.9%
associate-*l*90.2%
Simplified90.2%
associate-*r*99.9%
flip--90.2%
associate-*r/84.1%
metadata-eval84.1%
pow284.1%
+-commutative84.1%
Applied egg-rr84.1%
associate-*l*77.5%
associate-/l*80.4%
sub-neg80.4%
distribute-lft-in80.4%
*-rgt-identity80.4%
distribute-rgt-neg-in80.4%
unpow280.4%
cube-mult80.4%
unsub-neg80.4%
Simplified80.4%
Taylor expanded in y around 0 0.7%
frac-2neg0.7%
div-inv0.7%
neg-mul-10.7%
div-inv0.7%
add-sqr-sqrt0.0%
sqrt-unprod55.3%
frac-times55.3%
metadata-eval55.3%
metadata-eval55.3%
frac-times55.3%
sqrt-unprod35.6%
add-sqr-sqrt35.6%
remove-double-div35.6%
Applied egg-rr35.6%
Final simplification66.2%
(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%
associate-*l*94.8%
Simplified94.8%
Taylor expanded in y around 0 58.3%
Final simplification58.3%
herbie shell --seed 2023318
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))