
(FPCore (x y) :precision binary64 (* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))
double code(double x, double y) {
return (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (3.0d0 * sqrt(x)) * ((y + (1.0d0 / (x * 9.0d0))) - 1.0d0)
end function
public static double code(double x, double y) {
return (3.0 * Math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
def code(x, y): return (3.0 * math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0)
function code(x, y) return Float64(Float64(3.0 * sqrt(x)) * Float64(Float64(y + Float64(1.0 / Float64(x * 9.0))) - 1.0)) end
function tmp = code(x, y) tmp = (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0); end
code[x_, y_] := N[(N[(3.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(y + N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \sqrt{x}\right) \cdot \left(\left(y + \frac{1}{x \cdot 9}\right) - 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))
double code(double x, double y) {
return (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (3.0d0 * sqrt(x)) * ((y + (1.0d0 / (x * 9.0d0))) - 1.0d0)
end function
public static double code(double x, double y) {
return (3.0 * Math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0);
}
def code(x, y): return (3.0 * math.sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0)
function code(x, y) return Float64(Float64(3.0 * sqrt(x)) * Float64(Float64(y + Float64(1.0 / Float64(x * 9.0))) - 1.0)) end
function tmp = code(x, y) tmp = (3.0 * sqrt(x)) * ((y + (1.0 / (x * 9.0))) - 1.0); end
code[x_, y_] := N[(N[(3.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[(N[(y + N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \sqrt{x}\right) \cdot \left(\left(y + \frac{1}{x \cdot 9}\right) - 1\right)
\end{array}
(FPCore (x y) :precision binary64 (fma (sqrt x) (fma y 3.0 -3.0) (/ 0.3333333333333333 (sqrt x))))
double code(double x, double y) {
return fma(sqrt(x), fma(y, 3.0, -3.0), (0.3333333333333333 / sqrt(x)));
}
function code(x, y) return fma(sqrt(x), fma(y, 3.0, -3.0), Float64(0.3333333333333333 / sqrt(x))) end
code[x_, y_] := N[(N[Sqrt[x], $MachinePrecision] * N[(y * 3.0 + -3.0), $MachinePrecision] + N[(0.3333333333333333 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{x}, \mathsf{fma}\left(y, 3, -3\right), \frac{0.3333333333333333}{\sqrt{x}}\right)
\end{array}
Initial program 99.5%
Taylor expanded in x around 0
lower-/.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-sqrt.f6463.7
Applied rewrites63.7%
Taylor expanded in y around 0
Applied rewrites99.6%
Applied rewrites99.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fma y 3.0 -3.0) (sqrt x)))
(t_1 (* (* (sqrt x) 3.0) (- (+ (/ 1.0 (* 9.0 x)) y) 1.0))))
(if (<= t_1 -0.05)
t_0
(if (<= t_1 5e+150) (/ 0.3333333333333333 (sqrt x)) t_0))))
double code(double x, double y) {
double t_0 = fma(y, 3.0, -3.0) * sqrt(x);
double t_1 = (sqrt(x) * 3.0) * (((1.0 / (9.0 * x)) + y) - 1.0);
double tmp;
if (t_1 <= -0.05) {
tmp = t_0;
} else if (t_1 <= 5e+150) {
tmp = 0.3333333333333333 / sqrt(x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(fma(y, 3.0, -3.0) * sqrt(x)) t_1 = Float64(Float64(sqrt(x) * 3.0) * Float64(Float64(Float64(1.0 / Float64(9.0 * x)) + y) - 1.0)) tmp = 0.0 if (t_1 <= -0.05) tmp = t_0; elseif (t_1 <= 5e+150) tmp = Float64(0.3333333333333333 / sqrt(x)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 3.0 + -3.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[x], $MachinePrecision] * 3.0), $MachinePrecision] * N[(N[(N[(1.0 / N[(9.0 * x), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.05], t$95$0, If[LessEqual[t$95$1, 5e+150], N[(0.3333333333333333 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, 3, -3\right) \cdot \sqrt{x}\\
t_1 := \left(\sqrt{x} \cdot 3\right) \cdot \left(\left(\frac{1}{9 \cdot x} + y\right) - 1\right)\\
\mathbf{if}\;t\_1 \leq -0.05:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+150}:\\
\;\;\;\;\frac{0.3333333333333333}{\sqrt{x}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 3 binary64) (sqrt.f64 x)) (-.f64 (+.f64 y (/.f64 #s(literal 1 binary64) (*.f64 x #s(literal 9 binary64)))) #s(literal 1 binary64))) < -0.050000000000000003 or 5.00000000000000009e150 < (*.f64 (*.f64 #s(literal 3 binary64) (sqrt.f64 x)) (-.f64 (+.f64 y (/.f64 #s(literal 1 binary64) (*.f64 x #s(literal 9 binary64)))) #s(literal 1 binary64))) Initial program 99.6%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-sqrt.f6497.9
Applied rewrites97.9%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 3 binary64) (sqrt.f64 x)) (-.f64 (+.f64 y (/.f64 #s(literal 1 binary64) (*.f64 x #s(literal 9 binary64)))) #s(literal 1 binary64))) < 5.00000000000000009e150Initial program 99.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
frac-2negN/A
div-invN/A
neg-mul-1N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
un-div-invN/A
lower-/.f64N/A
metadata-evalN/A
metadata-eval99.2
Applied rewrites99.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6479.2
Applied rewrites79.2%
Applied rewrites79.2%
Final simplification90.4%
(FPCore (x y) :precision binary64 (* (* (sqrt x) 3.0) (- (+ (/ 1.0 (* 9.0 x)) y) 1.0)))
double code(double x, double y) {
return (sqrt(x) * 3.0) * (((1.0 / (9.0 * x)) + y) - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sqrt(x) * 3.0d0) * (((1.0d0 / (9.0d0 * x)) + y) - 1.0d0)
end function
public static double code(double x, double y) {
return (Math.sqrt(x) * 3.0) * (((1.0 / (9.0 * x)) + y) - 1.0);
}
def code(x, y): return (math.sqrt(x) * 3.0) * (((1.0 / (9.0 * x)) + y) - 1.0)
function code(x, y) return Float64(Float64(sqrt(x) * 3.0) * Float64(Float64(Float64(1.0 / Float64(9.0 * x)) + y) - 1.0)) end
function tmp = code(x, y) tmp = (sqrt(x) * 3.0) * (((1.0 / (9.0 * x)) + y) - 1.0); end
code[x_, y_] := N[(N[(N[Sqrt[x], $MachinePrecision] * 3.0), $MachinePrecision] * N[(N[(N[(1.0 / N[(9.0 * x), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sqrt{x} \cdot 3\right) \cdot \left(\left(\frac{1}{9 \cdot x} + y\right) - 1\right)
\end{array}
Initial program 99.5%
Final simplification99.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (fma y 3.0 -3.0) (sqrt x))))
(if (<= y -9.5e+15)
t_0
(if (<= y 1.25e-17) (* (+ (/ 0.3333333333333333 x) -3.0) (sqrt x)) t_0))))
double code(double x, double y) {
double t_0 = fma(y, 3.0, -3.0) * sqrt(x);
double tmp;
if (y <= -9.5e+15) {
tmp = t_0;
} else if (y <= 1.25e-17) {
tmp = ((0.3333333333333333 / x) + -3.0) * sqrt(x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(fma(y, 3.0, -3.0) * sqrt(x)) tmp = 0.0 if (y <= -9.5e+15) tmp = t_0; elseif (y <= 1.25e-17) tmp = Float64(Float64(Float64(0.3333333333333333 / x) + -3.0) * sqrt(x)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * 3.0 + -3.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.5e+15], t$95$0, If[LessEqual[y, 1.25e-17], N[(N[(N[(0.3333333333333333 / x), $MachinePrecision] + -3.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, 3, -3\right) \cdot \sqrt{x}\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-17}:\\
\;\;\;\;\left(\frac{0.3333333333333333}{x} + -3\right) \cdot \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.5e15 or 1.25e-17 < y Initial program 99.5%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-sqrt.f6484.7
Applied rewrites84.7%
if -9.5e15 < y < 1.25e-17Initial program 99.4%
Taylor expanded in y around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-+.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
lower-/.f64N/A
lower-sqrt.f6499.1
Applied rewrites99.1%
(FPCore (x y) :precision binary64 (* (fma (- 1.0 y) -3.0 (/ 0.3333333333333333 x)) (sqrt x)))
double code(double x, double y) {
return fma((1.0 - y), -3.0, (0.3333333333333333 / x)) * sqrt(x);
}
function code(x, y) return Float64(fma(Float64(1.0 - y), -3.0, Float64(0.3333333333333333 / x)) * sqrt(x)) end
code[x_, y_] := N[(N[(N[(1.0 - y), $MachinePrecision] * -3.0 + N[(0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1 - y, -3, \frac{0.3333333333333333}{x}\right) \cdot \sqrt{x}
\end{array}
Initial program 99.5%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
associate-+r-N/A
+-commutativeN/A
distribute-rgt-inN/A
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x y) :precision binary64 (* (fma y 3.0 -3.0) (sqrt x)))
double code(double x, double y) {
return fma(y, 3.0, -3.0) * sqrt(x);
}
function code(x, y) return Float64(fma(y, 3.0, -3.0) * sqrt(x)) end
code[x_, y_] := N[(N[(y * 3.0 + -3.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 3, -3\right) \cdot \sqrt{x}
\end{array}
Initial program 99.5%
Taylor expanded in x around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-sqrt.f6466.9
Applied rewrites66.9%
(FPCore (x y) :precision binary64 (* (* (sqrt x) 3.0) y))
double code(double x, double y) {
return (sqrt(x) * 3.0) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (sqrt(x) * 3.0d0) * y
end function
public static double code(double x, double y) {
return (Math.sqrt(x) * 3.0) * y;
}
def code(x, y): return (math.sqrt(x) * 3.0) * y
function code(x, y) return Float64(Float64(sqrt(x) * 3.0) * y) end
function tmp = code(x, y) tmp = (sqrt(x) * 3.0) * y; end
code[x_, y_] := N[(N[(N[Sqrt[x], $MachinePrecision] * 3.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\sqrt{x} \cdot 3\right) \cdot y
\end{array}
Initial program 99.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6443.6
Applied rewrites43.6%
Applied rewrites43.6%
(FPCore (x y) :precision binary64 (* (* y 3.0) (sqrt x)))
double code(double x, double y) {
return (y * 3.0) * sqrt(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * 3.0d0) * sqrt(x)
end function
public static double code(double x, double y) {
return (y * 3.0) * Math.sqrt(x);
}
def code(x, y): return (y * 3.0) * math.sqrt(x)
function code(x, y) return Float64(Float64(y * 3.0) * sqrt(x)) end
function tmp = code(x, y) tmp = (y * 3.0) * sqrt(x); end
code[x_, y_] := N[(N[(y * 3.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot 3\right) \cdot \sqrt{x}
\end{array}
Initial program 99.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6443.6
Applied rewrites43.6%
Applied rewrites43.6%
(FPCore (x y) :precision binary64 (* 3.0 (+ (* y (sqrt x)) (* (- (/ 1.0 (* x 9.0)) 1.0) (sqrt x)))))
double code(double x, double y) {
return 3.0 * ((y * sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * sqrt(x)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * ((y * sqrt(x)) + (((1.0d0 / (x * 9.0d0)) - 1.0d0) * sqrt(x)))
end function
public static double code(double x, double y) {
return 3.0 * ((y * Math.sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * Math.sqrt(x)));
}
def code(x, y): return 3.0 * ((y * math.sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * math.sqrt(x)))
function code(x, y) return Float64(3.0 * Float64(Float64(y * sqrt(x)) + Float64(Float64(Float64(1.0 / Float64(x * 9.0)) - 1.0) * sqrt(x)))) end
function tmp = code(x, y) tmp = 3.0 * ((y * sqrt(x)) + (((1.0 / (x * 9.0)) - 1.0) * sqrt(x))); end
code[x_, y_] := N[(3.0 * N[(N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 / N[(x * 9.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(y \cdot \sqrt{x} + \left(\frac{1}{x \cdot 9} - 1\right) \cdot \sqrt{x}\right)
\end{array}
herbie shell --seed 2024249
(FPCore (x y)
:name "Numeric.SpecFunctions:incompleteGamma from math-functions-0.1.5.2, B"
:precision binary64
:alt
(! :herbie-platform default (* 3 (+ (* y (sqrt x)) (* (- (/ 1 (* x 9)) 1) (sqrt x)))))
(* (* 3.0 (sqrt x)) (- (+ y (/ 1.0 (* x 9.0))) 1.0)))