
(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 (let* ((t_0 (- 0.0 (* y (* y x))))) (if (<= y -2e+94) t_0 (if (<= y 1e+56) (* x (* y (- 1.0 y))) t_0))))
double code(double x, double y) {
double t_0 = 0.0 - (y * (y * x));
double tmp;
if (y <= -2e+94) {
tmp = t_0;
} else if (y <= 1e+56) {
tmp = x * (y * (1.0 - y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 0.0d0 - (y * (y * x))
if (y <= (-2d+94)) then
tmp = t_0
else if (y <= 1d+56) then
tmp = x * (y * (1.0d0 - y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.0 - (y * (y * x));
double tmp;
if (y <= -2e+94) {
tmp = t_0;
} else if (y <= 1e+56) {
tmp = x * (y * (1.0 - y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.0 - (y * (y * x)) tmp = 0 if y <= -2e+94: tmp = t_0 elif y <= 1e+56: tmp = x * (y * (1.0 - y)) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(0.0 - Float64(y * Float64(y * x))) tmp = 0.0 if (y <= -2e+94) tmp = t_0; elseif (y <= 1e+56) tmp = Float64(x * Float64(y * Float64(1.0 - y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 0.0 - (y * (y * x)); tmp = 0.0; if (y <= -2e+94) tmp = t_0; elseif (y <= 1e+56) tmp = x * (y * (1.0 - y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.0 - N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e+94], t$95$0, If[LessEqual[y, 1e+56], N[(x * N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0 - y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -2 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 10^{+56}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2e94 or 1.00000000000000009e56 < y Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6486.6%
Simplified86.6%
Applied egg-rr86.6%
*-commutativeN/A
clear-numN/A
frac-timesN/A
times-fracN/A
neg-mul-1N/A
remove-double-negN/A
frac-2negN/A
associate-*r/N/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
/-lowering-/.f64N/A
distribute-frac-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-commutativeN/A
associate-/l*N/A
Applied egg-rr86.6%
Taylor expanded in y around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6486.6%
Simplified86.6%
associate-/r*N/A
associate-/r/N/A
associate-*l/N/A
*-commutativeN/A
clear-numN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
div-invN/A
metadata-evalN/A
div-invN/A
metadata-evalN/A
swap-sqrN/A
metadata-evalN/A
*-rgt-identityN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
frac-2negN/A
neg-mul-1N/A
div-invN/A
distribute-frac-negN/A
neg-lowering-neg.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
Applied egg-rr99.9%
if -2e94 < y < 1.00000000000000009e56Initial program 99.8%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 0.0 (* y (* y x))))) (if (<= y -1.0) t_0 (if (<= y 1.0) (* y x) t_0))))
double code(double x, double y) {
double t_0 = 0.0 - (y * (y * x));
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 0.0d0 - (y * (y * x))
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.0 - (y * (y * x));
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.0 - (y * (y * x)) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.0: tmp = y * x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(0.0 - Float64(y * Float64(y * x))) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 0.0 - (y * (y * x)); tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.0 - N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.0], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0 - y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.8%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6490.2%
Simplified90.2%
Applied egg-rr90.1%
*-commutativeN/A
clear-numN/A
frac-timesN/A
times-fracN/A
neg-mul-1N/A
remove-double-negN/A
frac-2negN/A
associate-*r/N/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
/-lowering-/.f64N/A
distribute-frac-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-commutativeN/A
associate-/l*N/A
Applied egg-rr90.1%
Taylor expanded in y around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6489.2%
Simplified89.2%
associate-/r*N/A
associate-/r/N/A
associate-*l/N/A
*-commutativeN/A
clear-numN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
div-invN/A
metadata-evalN/A
div-invN/A
metadata-evalN/A
swap-sqrN/A
metadata-evalN/A
*-rgt-identityN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
frac-2negN/A
neg-mul-1N/A
div-invN/A
distribute-frac-negN/A
neg-lowering-neg.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
Applied egg-rr98.9%
if -1 < y < 1Initial program 100.0%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
*-lowering-*.f6496.3%
Simplified96.3%
Final simplification97.6%
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* y x) (- 0.0 (* y x))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = y * x;
} else {
tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = y * x else: tmp = 0.0 - (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(y * x); else tmp = Float64(0.0 - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = y * x; else tmp = 0.0 - (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], N[(y * x), $MachinePrecision], N[(0.0 - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0 - y \cdot x\\
\end{array}
\end{array}
if y < 1Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6497.5%
Simplified97.5%
Taylor expanded in y around 0
*-lowering-*.f6473.7%
Simplified73.7%
if 1 < y Initial program 99.8%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6487.6%
Simplified87.6%
Applied egg-rr87.5%
*-commutativeN/A
clear-numN/A
frac-timesN/A
times-fracN/A
neg-mul-1N/A
remove-double-negN/A
frac-2negN/A
associate-*r/N/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
/-lowering-/.f64N/A
distribute-frac-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-commutativeN/A
associate-/l*N/A
Applied egg-rr87.6%
Taylor expanded in y around 0
/-lowering-/.f640.8%
Simplified0.8%
inv-powN/A
sqr-powN/A
pow-prod-downN/A
*-rgt-identityN/A
metadata-evalN/A
swap-sqrN/A
metadata-evalN/A
div-invN/A
metadata-evalN/A
div-invN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
clear-numN/A
clear-numN/A
associate-/r/N/A
frac-2negN/A
metadata-evalN/A
remove-double-divN/A
distribute-lft-neg-inN/A
neg-lowering-neg.f64N/A
*-lowering-*.f6424.6%
Applied egg-rr24.6%
Final simplification62.0%
(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*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6495.2%
Simplified95.2%
Applied egg-rr95.1%
*-commutativeN/A
clear-numN/A
un-div-invN/A
associate-/r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
flip--N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6499.7%
Applied egg-rr99.7%
associate-/r/N/A
clear-numN/A
clear-numN/A
associate-*l/N/A
*-commutativeN/A
*-rgt-identityN/A
/-lowering-/.f64N/A
/-lowering-/.f6499.7%
Applied egg-rr99.7%
Taylor expanded in y around 0
Simplified99.9%
(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*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6495.2%
Simplified95.2%
Taylor expanded in y around 0
*-lowering-*.f6456.3%
Simplified56.3%
Final simplification56.3%
herbie shell --seed 2024158
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))