
(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 (- (/ (/ 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 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ x (* y y))) (t_1 (- t_0 3.0))) (if (or (<= t_1 -20000000.0) (not (<= t_1 -2.0))) t_0 -3.0)))
double code(double x, double y) {
double t_0 = x / (y * y);
double t_1 = t_0 - 3.0;
double tmp;
if ((t_1 <= -20000000.0) || !(t_1 <= -2.0)) {
tmp = t_0;
} else {
tmp = -3.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) :: t_1
real(8) :: tmp
t_0 = x / (y * y)
t_1 = t_0 - 3.0d0
if ((t_1 <= (-20000000.0d0)) .or. (.not. (t_1 <= (-2.0d0)))) then
tmp = t_0
else
tmp = -3.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y * y);
double t_1 = t_0 - 3.0;
double tmp;
if ((t_1 <= -20000000.0) || !(t_1 <= -2.0)) {
tmp = t_0;
} else {
tmp = -3.0;
}
return tmp;
}
def code(x, y): t_0 = x / (y * y) t_1 = t_0 - 3.0 tmp = 0 if (t_1 <= -20000000.0) or not (t_1 <= -2.0): tmp = t_0 else: tmp = -3.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y * y)) t_1 = Float64(t_0 - 3.0) tmp = 0.0 if ((t_1 <= -20000000.0) || !(t_1 <= -2.0)) tmp = t_0; else tmp = -3.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y * y); t_1 = t_0 - 3.0; tmp = 0.0; if ((t_1 <= -20000000.0) || ~((t_1 <= -2.0))) tmp = t_0; else tmp = -3.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - 3.0), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -20000000.0], N[Not[LessEqual[t$95$1, -2.0]], $MachinePrecision]], t$95$0, -3.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y \cdot y}\\
t_1 := t\_0 - 3\\
\mathbf{if}\;t\_1 \leq -20000000 \lor \neg \left(t\_1 \leq -2\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;-3\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (*.f64 y y)) #s(literal 3 binary64)) < -2e7 or -2 < (-.f64 (/.f64 x (*.f64 y y)) #s(literal 3 binary64)) Initial program 92.5%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
pow-prod-downN/A
pow-prod-upN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
+-commutativeN/A
lower-+.f6411.3
lift-/.f64N/A
lift-*.f64N/A
Applied rewrites11.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-pow.f64N/A
metadata-evalN/A
pow-plusN/A
unpow3N/A
associate-*r*N/A
frac-timesN/A
associate-/r*N/A
lift-/.f64N/A
associate-/r*N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l/N/A
unpow1N/A
metadata-evalN/A
pow-powN/A
pow2N/A
pow1/2N/A
rem-sqrt-square-revN/A
lower-/.f64N/A
Applied rewrites21.3%
lift-pow.f64N/A
unpow2N/A
lower-*.f6421.3
Applied rewrites21.3%
Taylor expanded in x around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6491.4
Applied rewrites91.4%
if -2e7 < (-.f64 (/.f64 x (*.f64 y y)) #s(literal 3 binary64)) < -2Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.9%
Final simplification94.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(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}
Initial program 95.8%
(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 95.8%
Taylor expanded in x around 0
Applied rewrites45.4%
(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 2024339
(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))