
(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 -7.1e+155) (not (<= y 4e+126))) (* y (* x (- y))) (* x (* y (- 1.0 y)))))
double code(double x, double y) {
double tmp;
if ((y <= -7.1e+155) || !(y <= 4e+126)) {
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 <= (-7.1d+155)) .or. (.not. (y <= 4d+126))) 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 <= -7.1e+155) || !(y <= 4e+126)) {
tmp = y * (x * -y);
} else {
tmp = x * (y * (1.0 - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.1e+155) or not (y <= 4e+126): tmp = y * (x * -y) else: tmp = x * (y * (1.0 - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.1e+155) || !(y <= 4e+126)) 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 <= -7.1e+155) || ~((y <= 4e+126))) tmp = y * (x * -y); else tmp = x * (y * (1.0 - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.1e+155], N[Not[LessEqual[y, 4e+126]], $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 -7.1 \cdot 10^{+155} \lor \neg \left(y \leq 4 \cdot 10^{+126}\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 < -7.09999999999999992e155 or 3.9999999999999997e126 < y Initial program 100.0%
associate-*l*82.0%
Simplified82.0%
add082.0%
fma-define82.0%
metadata-eval82.0%
fma-neg82.0%
associate-*r*100.0%
*-commutative100.0%
add-sqr-sqrt44.0%
associate-*r*44.0%
fma-neg44.0%
metadata-eval44.0%
Applied egg-rr44.0%
add044.0%
flip-+27.8%
add-sqr-sqrt27.9%
metadata-eval27.9%
Applied egg-rr27.9%
--rgt-identity27.9%
--rgt-identity27.9%
Simplified27.9%
fma-undefine27.9%
add027.9%
pow127.9%
pow1/227.9%
pow-div44.0%
metadata-eval44.0%
pow1/244.0%
associate-*r*44.0%
add-sqr-sqrt100.0%
associate-*r*100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-out100.0%
Simplified100.0%
if -7.09999999999999992e155 < y < 3.9999999999999997e126Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
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*90.1%
Simplified90.1%
add090.1%
fma-define90.1%
metadata-eval90.1%
fma-neg90.1%
associate-*r*99.8%
*-commutative99.8%
add-sqr-sqrt45.4%
associate-*r*45.4%
fma-neg45.4%
metadata-eval45.4%
Applied egg-rr45.4%
add045.4%
flip-+33.4%
add-sqr-sqrt33.5%
metadata-eval33.5%
Applied egg-rr33.5%
--rgt-identity33.5%
--rgt-identity33.5%
Simplified33.5%
fma-undefine33.5%
add033.5%
pow133.5%
pow1/233.5%
pow-div45.4%
metadata-eval45.4%
pow1/245.4%
associate-*r*45.4%
add-sqr-sqrt99.8%
associate-*r*99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 94.3%
mul-1-neg94.3%
distribute-rgt-neg-out94.3%
Simplified94.3%
if -1 < y < 1Initial program 99.9%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in y around 0 97.1%
Final simplification95.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%
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%
associate-*l*95.2%
Simplified95.2%
Taylor expanded in y around 0 58.5%
Final simplification58.5%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
associate-*l*95.2%
Simplified95.2%
associate-*r*99.9%
flip--95.1%
associate-*r/93.6%
metadata-eval93.6%
pow293.6%
+-commutative93.6%
Applied egg-rr93.6%
associate-*l*91.8%
associate-/l*92.4%
associate-/r/88.0%
sub-neg88.0%
distribute-lft-in88.0%
distribute-rgt-neg-in88.0%
unpow288.0%
cube-mult88.0%
unsub-neg88.0%
*-rgt-identity88.0%
Simplified88.0%
Taylor expanded in y around inf 36.2%
Taylor expanded in y around 0 2.6%
Final simplification2.6%
herbie shell --seed 2024034
(FPCore (x y)
:name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
:precision binary64
(* (* x y) (- 1.0 y)))