
(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+134) (not (<= y 2e+144))) (- 0.0 (* y (* x y))) (* x (* y (- 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -5e+134) || !(y <= 2e+144)) {
tmp = 0.0 - (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+134)) .or. (.not. (y <= 2d+144))) then
tmp = 0.0d0 - (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+134) || !(y <= 2e+144)) {
tmp = 0.0 - (y * (x * y));
} else {
tmp = x * (y * (1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+134) or not (y <= 2e+144): tmp = 0.0 - (y * (x * y)) else: tmp = x * (y * (1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+134) || !(y <= 2e+144)) tmp = Float64(0.0 - Float64(y * Float64(x * 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+134) || ~((y <= 2e+144))) tmp = 0.0 - (y * (x * y)); else tmp = x * (y * (1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+134], N[Not[LessEqual[y, 2e+144]], $MachinePrecision]], N[(0.0 - N[(y * N[(x * y), $MachinePrecision]), $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^{+134} \lor \neg \left(y \leq 2 \cdot 10^{+144}\right):\\
\;\;\;\;0 - y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\
\end{array}
\end{array}
if y < -4.99999999999999981e134 or 2.00000000000000005e144 < y Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6479.3%
Simplified79.3%
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
sub-negN/A
--lowering--.f64N/A
*-lowering-*.f6479.3%
Applied egg-rr79.3%
Applied egg-rr82.2%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6479.3%
Simplified79.3%
associate-*r*N/A
remove-double-divN/A
un-div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
remove-double-divN/A
metadata-evalN/A
distribute-neg-fracN/A
associate-/l/N/A
inv-powN/A
pow-powN/A
neg-mul-1N/A
associate-*r/N/A
associate-*l/N/A
pow-prod-downN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
unpow1N/A
frac-2negN/A
metadata-evalN/A
Applied egg-rr99.9%
if -4.99999999999999981e134 < y < 2.00000000000000005e144Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6499.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (- 0.0 (* y (* x y))) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (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 = 0.0 - (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(0.0 - Float64(y * Float64(x * 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 = 0.0 - (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[(0.0 - N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;0 - y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\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--.f6487.9%
Simplified87.9%
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
sub-negN/A
--lowering--.f64N/A
*-lowering-*.f6487.9%
Applied egg-rr87.9%
Applied egg-rr89.5%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6486.6%
Simplified86.6%
associate-*r*N/A
remove-double-divN/A
un-div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
remove-double-divN/A
metadata-evalN/A
distribute-neg-fracN/A
associate-/l/N/A
inv-powN/A
pow-powN/A
neg-mul-1N/A
associate-*r/N/A
associate-*l/N/A
pow-prod-downN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
unpow1N/A
frac-2negN/A
metadata-evalN/A
Applied egg-rr98.5%
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-*.f6498.1%
Simplified98.1%
Final simplification98.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* x (- 0.0 (* y y))) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = x * (0.0 - (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 * (0.0d0 - (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 * (0.0 - (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 * (0.0 - (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(0.0 - Float64(y * 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 * (0.0 - (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[(0.0 - N[(y * y), $MachinePrecision]), $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(0 - y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\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--.f6487.9%
Simplified87.9%
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
sub-negN/A
--lowering--.f64N/A
*-lowering-*.f6487.9%
Applied egg-rr87.9%
Applied egg-rr89.5%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6486.6%
Simplified86.6%
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-*.f6498.1%
Simplified98.1%
Final simplification92.5%
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* x y) (- 0.0 (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x * y;
} else {
tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x * y else: tmp = 0.0 - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(x * y); else tmp = Float64(0.0 - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = x * y; else tmp = 0.0 - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], N[(x * y), $MachinePrecision], N[(0.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;0 - x \cdot y\\
\end{array}
\end{array}
if y < 1Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6496.4%
Simplified96.4%
Taylor expanded in y around 0
*-lowering-*.f6479.7%
Simplified79.7%
if 1 < y Initial program 99.9%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6488.6%
Simplified88.6%
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
sub-negN/A
--lowering--.f64N/A
*-lowering-*.f6488.6%
Applied egg-rr88.6%
Applied egg-rr88.6%
Taylor expanded in y around 0
Simplified0.7%
frac-2negN/A
neg-mul-1N/A
div-invN/A
distribute-frac-negN/A
neg-lowering-neg.f64N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
frac-2negN/A
unpow1N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow-powN/A
inv-powN/A
frac-2negN/A
metadata-evalN/A
remove-double-divN/A
pow2N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
div-invN/A
clear-numN/A
Applied egg-rr27.6%
Final simplification64.7%
(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}
Initial program 99.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%
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
--lowering--.f6494.1%
Simplified94.1%
Taylor expanded in y around 0
*-lowering-*.f6456.9%
Simplified56.9%
herbie shell --seed 2024125
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))