
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 + (y * y))
end function
public static double code(double x, double y) {
return x * (1.0 + (y * y));
}
def code(x, y): return x * (1.0 + (y * y))
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function tmp = code(x, y) tmp = x * (1.0 + (y * y)); end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + y \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (+ 1.0 (* y y))))
double code(double x, double y) {
return x * (1.0 + (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 + (y * y))
end function
public static double code(double x, double y) {
return x * (1.0 + (y * y));
}
def code(x, y): return x * (1.0 + (y * y))
function code(x, y) return Float64(x * Float64(1.0 + Float64(y * y))) end
function tmp = code(x, y) tmp = x * (1.0 + (y * y)); end
code[x_, y_] := N[(x * N[(1.0 + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + y \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma (* y x) y x))
double code(double x, double y) {
return fma((y * x), y, x);
}
function code(x, y) return fma(Float64(y * x), y, x) end
code[x_, y_] := N[(N[(y * x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot x, y, x\right)
\end{array}
Initial program 91.2%
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e-7) x (* y (* y x))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-7) {
tmp = x;
} else {
tmp = y * (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 * y) <= 5d-7) then
tmp = x
else
tmp = y * (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-7) {
tmp = x;
} else {
tmp = y * (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e-7: tmp = x else: tmp = y * (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e-7) tmp = x; else tmp = Float64(y * Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e-7) tmp = x; else tmp = y * (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e-7], x, N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999977e-7Initial program 100.0%
Taylor expanded in y around 0
Simplified99.1%
if 4.99999999999999977e-7 < (*.f64 y y) Initial program 83.8%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6483.5
Simplified83.5%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.5
Applied egg-rr99.5%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e-7) x (* y x)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-7) {
tmp = x;
} else {
tmp = 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 * y) <= 5d-7) then
tmp = x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-7) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e-7: tmp = x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e-7) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e-7) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e-7], x, N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999977e-7Initial program 100.0%
Taylor expanded in y around 0
Simplified99.1%
if 4.99999999999999977e-7 < (*.f64 y y) Initial program 83.8%
*-commutativeN/A
flip-+N/A
associate-*l/N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
associate-*l/N/A
flip-+N/A
+-commutativeN/A
distribute-rgt1-inN/A
/-lowering-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.7
Applied egg-rr99.7%
inv-powN/A
remove-double-divN/A
inv-powN/A
sqr-powN/A
unpow-prod-downN/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
metadata-evalN/A
pow-lowering-pow.f64N/A
Applied egg-rr48.3%
Taylor expanded in y around inf
associate-*r/N/A
*-rgt-identityN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6420.7
Simplified20.7%
Taylor expanded in y around 0
*-lowering-*.f6412.6
Simplified12.6%
Final simplification51.8%
(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 91.2%
Taylor expanded in y around 0
Simplified47.4%
(FPCore (x y) :precision binary64 (+ x (* (* x y) y)))
double code(double x, double y) {
return x + ((x * y) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x * y) * y)
end function
public static double code(double x, double y) {
return x + ((x * y) * y);
}
def code(x, y): return x + ((x * y) * y)
function code(x, y) return Float64(x + Float64(Float64(x * y) * y)) end
function tmp = code(x, y) tmp = x + ((x * y) * y); end
code[x_, y_] := N[(x + N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x \cdot y\right) \cdot y
\end{array}
herbie shell --seed 2024204
(FPCore (x y)
:name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"
:precision binary64
:alt
(! :herbie-platform default (+ x (* (* x y) y)))
(* x (+ 1.0 (* y y))))