
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(* (pow x -1.5) 0.5)
(/ (pow (fma x x x) -0.5) (+ (sqrt x) t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = pow(fma(x, x, x), -0.5) / (sqrt(x) + t_0);
}
return tmp;
}
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64((fma(x, x, x) ^ -0.5) / Float64(sqrt(x) + t_0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Power[N[(x * x + x), $MachinePrecision], -0.5], $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(\mathsf{fma}\left(x, x, x\right)\right)}^{-0.5}}{\sqrt{x} + t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 37.4%
add-cube-cbrt37.4%
pow337.4%
pow1/236.6%
pow-flip26.0%
metadata-eval26.0%
inv-pow26.0%
sqrt-pow237.4%
+-commutative37.4%
metadata-eval37.4%
Applied egg-rr37.4%
Taylor expanded in x around inf 67.0%
rem-cube-cbrt67.7%
*-commutative67.7%
pow-flip68.3%
metadata-eval68.3%
Applied egg-rr68.3%
expm1-log1p-u68.3%
expm1-udef37.4%
sqrt-pow137.4%
metadata-eval37.4%
Applied egg-rr37.4%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.0%
frac-sub98.0%
clear-num98.0%
sqrt-unprod98.0%
+-commutative98.0%
*-un-lft-identity98.0%
*-rgt-identity98.0%
+-commutative98.0%
Applied egg-rr98.0%
associate-/r/98.0%
associate-*l/98.1%
*-lft-identity98.1%
distribute-rgt-in98.1%
*-lft-identity98.1%
Simplified98.1%
flip--98.9%
add-sqr-sqrt98.4%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
associate--l+99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
div-inv99.5%
inv-pow99.5%
sqrt-pow299.9%
+-commutative99.9%
fma-def99.9%
metadata-eval99.9%
Applied egg-rr99.9%
associate-*l/99.9%
*-lft-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(* (pow x -1.5) 0.5)
(/ (/ 1.0 (+ (sqrt x) t_0)) (sqrt (+ x (* x x)))))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = (1.0 / (sqrt(x) + t_0)) / sqrt((x + (x * x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
tmp = (x ** (-1.5d0)) * 0.5d0
else
tmp = (1.0d0 / (sqrt(x) + t_0)) / sqrt((x + (x * x)))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = Math.pow(x, -1.5) * 0.5;
} else {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / Math.sqrt((x + (x * x)));
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 0.0: tmp = math.pow(x, -1.5) * 0.5 else: tmp = (1.0 / (math.sqrt(x) + t_0)) / math.sqrt((x + (x * x))) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / sqrt(Float64(x + Float64(x * x)))); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) tmp = (x ^ -1.5) * 0.5; else tmp = (1.0 / (sqrt(x) + t_0)) / sqrt((x + (x * x))); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\sqrt{x + x \cdot x}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 37.4%
add-cube-cbrt37.4%
pow337.4%
pow1/236.6%
pow-flip26.0%
metadata-eval26.0%
inv-pow26.0%
sqrt-pow237.4%
+-commutative37.4%
metadata-eval37.4%
Applied egg-rr37.4%
Taylor expanded in x around inf 67.0%
rem-cube-cbrt67.7%
*-commutative67.7%
pow-flip68.3%
metadata-eval68.3%
Applied egg-rr68.3%
expm1-log1p-u68.3%
expm1-udef37.4%
sqrt-pow137.4%
metadata-eval37.4%
Applied egg-rr37.4%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.0%
frac-sub98.0%
clear-num98.0%
sqrt-unprod98.0%
+-commutative98.0%
*-un-lft-identity98.0%
*-rgt-identity98.0%
+-commutative98.0%
Applied egg-rr98.0%
associate-/r/98.0%
associate-*l/98.1%
*-lft-identity98.1%
distribute-rgt-in98.1%
*-lft-identity98.1%
Simplified98.1%
flip--98.9%
add-sqr-sqrt98.4%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
associate--l+99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 1e-8)
(/ (/ 1.0 (+ (sqrt x) t_0)) (- (+ x 0.5) (/ 0.125 x)))
(- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-8) {
tmp = (1.0 / (sqrt(x) + t_0)) / ((x + 0.5) - (0.125 / x));
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 1d-8) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / ((x + 0.5d0) - (0.125d0 / x))
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 1e-8) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / ((x + 0.5) - (0.125 / x));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 1e-8: tmp = (1.0 / (math.sqrt(x) + t_0)) / ((x + 0.5) - (0.125 / x)) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 1e-8) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(Float64(x + 0.5) - Float64(0.125 / x))); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-8) tmp = (1.0 / (sqrt(x) + t_0)) / ((x + 0.5) - (0.125 / x)); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 1e-8], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 0.5), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 10^{-8}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\left(x + 0.5\right) - \frac{0.125}{x}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1e-8Initial program 37.9%
frac-sub38.0%
clear-num38.0%
sqrt-unprod38.0%
+-commutative38.0%
*-un-lft-identity38.0%
*-rgt-identity38.0%
+-commutative38.0%
Applied egg-rr38.0%
associate-/r/38.0%
associate-*l/38.0%
*-lft-identity38.0%
distribute-rgt-in38.0%
*-lft-identity38.0%
Simplified38.0%
flip--38.8%
add-sqr-sqrt38.3%
add-sqr-sqrt39.5%
Applied egg-rr39.5%
associate--l+81.2%
+-inverses81.2%
metadata-eval81.2%
+-commutative81.2%
Simplified81.2%
Taylor expanded in x around inf 99.7%
+-commutative99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
if 1e-8 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
inv-pow99.4%
sqrt-pow299.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-rgt-identity99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 1e-8)
(/ (/ 1.0 (+ (sqrt x) t_0)) (+ x 0.5))
(- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-8) {
tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 1d-8) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + 0.5d0)
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 1e-8) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 1e-8: tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + 0.5) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 1e-8) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + 0.5)); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-8) tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 1e-8], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 10^{-8}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1e-8Initial program 37.9%
frac-sub38.0%
clear-num38.0%
sqrt-unprod38.0%
+-commutative38.0%
*-un-lft-identity38.0%
*-rgt-identity38.0%
+-commutative38.0%
Applied egg-rr38.0%
associate-/r/38.0%
associate-*l/38.0%
*-lft-identity38.0%
distribute-rgt-in38.0%
*-lft-identity38.0%
Simplified38.0%
flip--38.8%
add-sqr-sqrt38.3%
add-sqr-sqrt39.5%
Applied egg-rr39.5%
associate--l+81.2%
+-inverses81.2%
metadata-eval81.2%
+-commutative81.2%
Simplified81.2%
Taylor expanded in x around inf 99.5%
+-commutative7.8%
Simplified99.5%
if 1e-8 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
inv-pow99.4%
sqrt-pow299.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-rgt-identity99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 1e-14) (* (pow x -1.5) 0.5) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-14) {
tmp = pow(x, -1.5) * 0.5;
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 1d-14) then
tmp = (x ** (-1.5d0)) * 0.5d0
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 1e-14) {
tmp = Math.pow(x, -1.5) * 0.5;
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 1e-14: tmp = math.pow(x, -1.5) * 0.5 else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 1e-14) tmp = Float64((x ^ -1.5) * 0.5); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-14) tmp = (x ^ -1.5) * 0.5; else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-14], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 10^{-14}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 9.99999999999999999e-15Initial program 37.6%
add-cube-cbrt37.6%
pow337.6%
pow1/236.8%
pow-flip26.5%
metadata-eval26.5%
inv-pow26.5%
sqrt-pow237.6%
+-commutative37.6%
metadata-eval37.6%
Applied egg-rr37.6%
Taylor expanded in x around inf 67.2%
rem-cube-cbrt67.9%
*-commutative67.9%
pow-flip68.4%
metadata-eval68.4%
Applied egg-rr68.4%
expm1-log1p-u68.4%
expm1-udef36.8%
sqrt-pow136.8%
metadata-eval36.8%
Applied egg-rr36.8%
expm1-def99.3%
expm1-log1p99.3%
Simplified99.3%
if 9.99999999999999999e-15 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.2%
*-un-lft-identity99.2%
clear-num99.2%
associate-/r/99.2%
prod-diff99.2%
*-un-lft-identity99.2%
fma-neg99.2%
*-un-lft-identity99.2%
inv-pow99.2%
sqrt-pow299.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.6%
+-commutative99.6%
metadata-eval99.6%
Applied egg-rr99.6%
fma-udef99.6%
distribute-lft1-in99.6%
metadata-eval99.6%
mul0-lft99.6%
+-rgt-identity99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
inv-pow99.6%
sqrt-pow2100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 99.4%
if 1 < x Initial program 38.7%
add-cube-cbrt38.7%
pow338.7%
pow1/237.9%
pow-flip27.8%
metadata-eval27.8%
inv-pow27.8%
sqrt-pow238.7%
+-commutative38.7%
metadata-eval38.7%
Applied egg-rr38.7%
Taylor expanded in x around inf 66.5%
rem-cube-cbrt67.1%
*-commutative67.1%
pow-flip67.7%
metadata-eval67.7%
Applied egg-rr67.7%
expm1-log1p-u67.7%
expm1-udef36.8%
sqrt-pow136.8%
metadata-eval36.8%
Applied egg-rr36.8%
expm1-def97.9%
expm1-log1p97.9%
Simplified97.9%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.5;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (x ** (-1.5d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -1.5) * 0.5); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
inv-pow99.6%
sqrt-pow2100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 0.680000000000000049 < x Initial program 38.7%
add-cube-cbrt38.7%
pow338.7%
pow1/237.9%
pow-flip27.8%
metadata-eval27.8%
inv-pow27.8%
sqrt-pow238.7%
+-commutative38.7%
metadata-eval38.7%
Applied egg-rr38.7%
Taylor expanded in x around inf 66.5%
rem-cube-cbrt67.1%
*-commutative67.1%
pow-flip67.7%
metadata-eval67.7%
Applied egg-rr67.7%
expm1-log1p-u67.7%
expm1-udef36.8%
sqrt-pow136.8%
metadata-eval36.8%
Applied egg-rr36.8%
expm1-def97.9%
expm1-log1p97.9%
Simplified97.9%
Final simplification98.4%
(FPCore (x) :precision binary64 (* (pow x -1.5) 0.5))
double code(double x) {
return pow(x, -1.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-1.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -1.5) * 0.5;
}
def code(x): return math.pow(x, -1.5) * 0.5
function code(x) return Float64((x ^ -1.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -1.5) * 0.5; end
code[x_] := N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5} \cdot 0.5
\end{array}
Initial program 70.3%
add-cube-cbrt69.5%
pow369.5%
pow1/269.2%
pow-flip64.4%
metadata-eval64.4%
inv-pow64.4%
sqrt-pow269.6%
+-commutative69.6%
metadata-eval69.6%
Applied egg-rr69.6%
Taylor expanded in x around inf 34.6%
rem-cube-cbrt34.9%
*-commutative34.9%
pow-flip35.2%
metadata-eval35.2%
Applied egg-rr35.2%
expm1-log1p-u35.2%
expm1-udef20.3%
sqrt-pow120.6%
metadata-eval20.6%
Applied egg-rr20.6%
expm1-def49.9%
expm1-log1p49.9%
Simplified49.9%
Final simplification49.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ x 0.5)))
double code(double x) {
return 1.0 / (x + 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + 0.5d0)
end function
public static double code(double x) {
return 1.0 / (x + 0.5);
}
def code(x): return 1.0 / (x + 0.5)
function code(x) return Float64(1.0 / Float64(x + 0.5)) end
function tmp = code(x) tmp = 1.0 / (x + 0.5); end
code[x_] := N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 0.5}
\end{array}
Initial program 70.3%
frac-sub70.3%
clear-num70.3%
sqrt-unprod70.3%
+-commutative70.3%
*-un-lft-identity70.3%
*-rgt-identity70.3%
+-commutative70.3%
Applied egg-rr70.3%
associate-/r/70.3%
associate-*l/70.3%
*-lft-identity70.3%
distribute-rgt-in70.3%
*-lft-identity70.3%
Simplified70.3%
Taylor expanded in x around 0 68.3%
Taylor expanded in x around inf 7.3%
+-commutative7.3%
Simplified7.3%
Final simplification7.3%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 70.3%
frac-sub70.3%
clear-num70.3%
sqrt-unprod70.3%
+-commutative70.3%
*-un-lft-identity70.3%
*-rgt-identity70.3%
+-commutative70.3%
Applied egg-rr70.3%
associate-/r/70.3%
associate-*l/70.3%
*-lft-identity70.3%
distribute-rgt-in70.3%
*-lft-identity70.3%
Simplified70.3%
Taylor expanded in x around 0 68.3%
Taylor expanded in x around inf 7.3%
Final simplification7.3%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 70.3%
Taylor expanded in x around 0 52.4%
Taylor expanded in x around inf 1.9%
Final simplification1.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2023171
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))