
(FPCore (x y) :precision binary64 (- (/ x (* y y)) 3.0))
double code(double x, double y) {
return (x / (y * y)) - 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (y * y)) - 3.0d0
end function
public static double code(double x, double y) {
return (x / (y * y)) - 3.0;
}
def code(x, y): return (x / (y * y)) - 3.0
function code(x, y) return Float64(Float64(x / Float64(y * y)) - 3.0) end
function tmp = code(x, y) tmp = (x / (y * y)) - 3.0; end
code[x_, y_] := N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] - 3.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y \cdot y} - 3
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (/ x (* y y)) 3.0))
double code(double x, double y) {
return (x / (y * y)) - 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (y * y)) - 3.0d0
end function
public static double code(double x, double y) {
return (x / (y * y)) - 3.0;
}
def code(x, y): return (x / (y * y)) - 3.0
function code(x, y) return Float64(Float64(x / Float64(y * y)) - 3.0) end
function tmp = code(x, y) tmp = (x / (y * y)) - 3.0; end
code[x_, y_] := N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] - 3.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y \cdot y} - 3
\end{array}
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e-308) (/ (/ x y) y) (- (/ x (* y y)) 3.0)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e-308) {
tmp = (x / y) / y;
} else {
tmp = (x / (y * y)) - 3.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 2d-308) then
tmp = (x / y) / y
else
tmp = (x / (y * y)) - 3.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 2e-308) {
tmp = (x / y) / y;
} else {
tmp = (x / (y * y)) - 3.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e-308: tmp = (x / y) / y else: tmp = (x / (y * y)) - 3.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e-308) tmp = Float64(Float64(x / y) / y); else tmp = Float64(Float64(x / Float64(y * y)) - 3.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 2e-308) tmp = (x / y) / y; else tmp = (x / (y * y)) - 3.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e-308], N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision], N[(N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] - 3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{-308}:\\
\;\;\;\;\frac{\frac{x}{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot y} - 3\\
\end{array}
\end{array}
if (*.f64 y y) < 1.9999999999999998e-308Initial program 69.3%
Taylor expanded in x around inf 69.3%
*-lft-identity69.3%
associate-*l/67.6%
unpow267.6%
associate-/r*67.7%
*-rgt-identity67.7%
associate-/l*67.7%
unpow-167.7%
unpow-167.7%
pow-sqr67.7%
metadata-eval67.7%
*-commutative67.7%
Simplified67.7%
metadata-eval67.7%
pow-sqr67.7%
inv-pow67.7%
inv-pow67.7%
un-div-inv67.7%
Applied egg-rr67.7%
associate-*r/99.8%
div-inv99.8%
Applied egg-rr99.8%
if 1.9999999999999998e-308 < (*.f64 y y) Initial program 99.9%
(FPCore (x y) :precision binary64 (if (<= y 0.002) (/ (/ x y) y) -3.0))
double code(double x, double y) {
double tmp;
if (y <= 0.002) {
tmp = (x / y) / y;
} else {
tmp = -3.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 0.002d0) then
tmp = (x / y) / y
else
tmp = -3.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.002) {
tmp = (x / y) / y;
} else {
tmp = -3.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.002: tmp = (x / y) / y else: tmp = -3.0 return tmp
function code(x, y) tmp = 0.0 if (y <= 0.002) tmp = Float64(Float64(x / y) / y); else tmp = -3.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.002) tmp = (x / y) / y; else tmp = -3.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.002], N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision], -3.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.002:\\
\;\;\;\;\frac{\frac{x}{y}}{y}\\
\mathbf{else}:\\
\;\;\;\;-3\\
\end{array}
\end{array}
if y < 2e-3Initial program 91.3%
Taylor expanded in x around inf 52.4%
*-lft-identity52.4%
associate-*l/51.8%
unpow251.8%
associate-/r*51.9%
*-rgt-identity51.9%
associate-/l*51.8%
unpow-151.8%
unpow-151.8%
pow-sqr51.9%
metadata-eval51.9%
*-commutative51.9%
Simplified51.9%
metadata-eval51.9%
pow-sqr51.8%
inv-pow51.8%
inv-pow51.8%
un-div-inv51.9%
Applied egg-rr51.9%
associate-*r/60.8%
div-inv60.9%
Applied egg-rr60.9%
if 2e-3 < y Initial program 100.0%
Taylor expanded in x around 0 95.8%
(FPCore (x y) :precision binary64 (- (/ (/ x y) y) 3.0))
double code(double x, double y) {
return ((x / y) / y) - 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x / y) / y) - 3.0d0
end function
public static double code(double x, double y) {
return ((x / y) / y) - 3.0;
}
def code(x, y): return ((x / y) / y) - 3.0
function code(x, y) return Float64(Float64(Float64(x / y) / y) - 3.0) end
function tmp = code(x, y) tmp = ((x / y) / y) - 3.0; end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] - 3.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x}{y}}{y} - 3
\end{array}
Initial program 93.7%
associate-/r*99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
clear-num99.9%
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 -3.0)
double code(double x, double y) {
return -3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -3.0d0
end function
public static double code(double x, double y) {
return -3.0;
}
def code(x, y): return -3.0
function code(x, y) return -3.0 end
function tmp = code(x, y) tmp = -3.0; end
code[x_, y_] := -3.0
\begin{array}{l}
\\
-3
\end{array}
Initial program 93.7%
Taylor expanded in x around 0 55.7%
(FPCore (x y) :precision binary64 (- (/ (/ x y) y) 3.0))
double code(double x, double y) {
return ((x / y) / y) - 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x / y) / y) - 3.0d0
end function
public static double code(double x, double y) {
return ((x / y) / y) - 3.0;
}
def code(x, y): return ((x / y) / y) - 3.0
function code(x, y) return Float64(Float64(Float64(x / y) / y) - 3.0) end
function tmp = code(x, y) tmp = ((x / y) / y) - 3.0; end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] - 3.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x}{y}}{y} - 3
\end{array}
herbie shell --seed 2024143
(FPCore (x y)
:name "Statistics.Sample:$skurtosis from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (- (/ (/ x y) y) 3))
(- (/ x (* y y)) 3.0))