
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return x / (1.0 + Math.sqrt((x + 1.0)));
}
def code(x): return x / (1.0 + math.sqrt((x + 1.0)))
function code(x) return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = x / (1.0 + sqrt((x + 1.0))); end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return x / (1.0 + Math.sqrt((x + 1.0)));
}
def code(x): return x / (1.0 + math.sqrt((x + 1.0)))
function code(x) return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = x / (1.0 + sqrt((x + 1.0))); end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return x / (1.0 + Math.sqrt((x + 1.0)));
}
def code(x): return x / (1.0 + math.sqrt((x + 1.0)))
function code(x) return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = x / (1.0 + sqrt((x + 1.0))); end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}
Initial program 99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (/ x (+ 1.0 t_0)) 5e-18)
(* x (fma x (fma x 0.0625 -0.125) 0.5))
(+ t_0 -1.0))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if ((x / (1.0 + t_0)) <= 5e-18) {
tmp = x * fma(x, fma(x, 0.0625, -0.125), 0.5);
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(x / Float64(1.0 + t_0)) <= 5e-18) tmp = Float64(x * fma(x, fma(x, 0.0625, -0.125), 0.5)); else tmp = Float64(t_0 + -1.0); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 5e-18], N[(x * N[(x * N[(x * 0.0625 + -0.125), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 5 \cdot 10^{-18}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.0625, -0.125\right), 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.00000000000000036e-18Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6499.6
Applied rewrites99.6%
if 5.00000000000000036e-18 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
lift-/.f64N/A
frac-2negN/A
neg-sub0N/A
metadata-evalN/A
associate--r+N/A
metadata-evalN/A
+-commutativeN/A
lift-+.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
distribute-neg-frac2N/A
lift-+.f64N/A
flip--N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
lift-neg.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (/ x (+ 1.0 t_0)) 5e-18)
(fma (* x x) -0.125 (* x 0.5))
(+ t_0 -1.0))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if ((x / (1.0 + t_0)) <= 5e-18) {
tmp = fma((x * x), -0.125, (x * 0.5));
} else {
tmp = t_0 + -1.0;
}
return tmp;
}
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(x / Float64(1.0 + t_0)) <= 5e-18) tmp = fma(Float64(x * x), -0.125, Float64(x * 0.5)); else tmp = Float64(t_0 + -1.0); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 5e-18], N[(N[(x * x), $MachinePrecision] * -0.125 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 5 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.125, x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.00000000000000036e-18Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.6
Applied rewrites99.6%
Applied rewrites99.6%
if 5.00000000000000036e-18 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
lift-/.f64N/A
frac-2negN/A
neg-sub0N/A
metadata-evalN/A
associate--r+N/A
metadata-evalN/A
+-commutativeN/A
lift-+.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
distribute-neg-frac2N/A
lift-+.f64N/A
flip--N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
lift-neg.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.004) (fma (* x x) -0.125 (* x 0.5)) (+ (sqrt x) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.004) {
tmp = fma((x * x), -0.125, (x * 0.5));
} else {
tmp = sqrt(x) + -1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.004) tmp = fma(Float64(x * x), -0.125, Float64(x * 0.5)); else tmp = Float64(sqrt(x) + -1.0); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.004], N[(N[(x * x), $MachinePrecision] * -0.125 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.004:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.125, x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} + -1\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.0040000000000000001Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Applied rewrites99.3%
if 0.0040000000000000001 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-sqrt.f6498.3
Applied rewrites98.3%
(FPCore (x) :precision binary64 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.004) (* x (fma x -0.125 0.5)) (+ (sqrt x) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.004) {
tmp = x * fma(x, -0.125, 0.5);
} else {
tmp = sqrt(x) + -1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.004) tmp = Float64(x * fma(x, -0.125, 0.5)); else tmp = Float64(sqrt(x) + -1.0); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.004], N[(x * N[(x * -0.125 + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.004:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} + -1\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.0040000000000000001Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
if 0.0040000000000000001 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-sqrt.f6498.3
Applied rewrites98.3%
(FPCore (x) :precision binary64 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.004) (* x (fma x -0.125 0.5)) (sqrt x)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.004) {
tmp = x * fma(x, -0.125, 0.5);
} else {
tmp = sqrt(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.004) tmp = Float64(x * fma(x, -0.125, 0.5)); else tmp = sqrt(x); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.004], N[(x * N[(x * -0.125 + 0.5), $MachinePrecision]), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.004:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.0040000000000000001Initial program 100.0%
Taylor expanded in x around 0
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
if 0.0040000000000000001 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
Taylor expanded in x around inf
lower-sqrt.f6496.0
Applied rewrites96.0%
(FPCore (x) :precision binary64 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.004) (* x 0.5) (sqrt x)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.004) {
tmp = x * 0.5;
} else {
tmp = sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 0.004d0) then
tmp = x * 0.5d0
else
tmp = sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 0.004) {
tmp = x * 0.5;
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (x / (1.0 + math.sqrt((x + 1.0)))) <= 0.004: tmp = x * 0.5 else: tmp = math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.004) tmp = Float64(x * 0.5); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.004) tmp = x * 0.5; else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.004], N[(x * 0.5), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.004:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.0040000000000000001Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6498.8
Applied rewrites98.8%
if 0.0040000000000000001 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.2%
Taylor expanded in x around inf
lower-sqrt.f6496.0
Applied rewrites96.0%
Final simplification97.8%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return x * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.5d0
end function
public static double code(double x) {
return x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
lower-*.f6466.4
Applied rewrites66.4%
Final simplification66.4%
(FPCore (x) :precision binary64 (+ 1.0 -1.0))
double code(double x) {
return 1.0 + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 + (-1.0d0)
end function
public static double code(double x) {
return 1.0 + -1.0;
}
def code(x): return 1.0 + -1.0
function code(x) return Float64(1.0 + -1.0) end
function tmp = code(x) tmp = 1.0 + -1.0; end
code[x_] := N[(1.0 + -1.0), $MachinePrecision]
\begin{array}{l}
\\
1 + -1
\end{array}
Initial program 99.7%
lift-/.f64N/A
frac-2negN/A
neg-sub0N/A
metadata-evalN/A
associate--r+N/A
metadata-evalN/A
+-commutativeN/A
lift-+.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
distribute-neg-frac2N/A
lift-+.f64N/A
flip--N/A
lower-neg.f64N/A
lower--.f6440.0
Applied rewrites40.0%
lift-neg.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f6440.0
Applied rewrites40.0%
Taylor expanded in x around 0
Applied rewrites4.4%
Final simplification4.4%
herbie shell --seed 2024226
(FPCore (x)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
:precision binary64
(/ x (+ 1.0 (sqrt (+ x 1.0)))))