
(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 8 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 (/ 1.0 (sqrt (+ 1.0 x)))))
(if (<= (- (/ 1.0 (sqrt x)) t_0) 2e-23)
(* 0.5 (pow x -1.5))
(- (pow x -0.5) t_0))))
double code(double x) {
double t_0 = 1.0 / sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) - t_0) <= 2e-23) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = pow(x, -0.5) - t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 / sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) - t_0) <= 2d-23) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = (x ** (-0.5d0)) - t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 / Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) - t_0) <= 2e-23) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = Math.pow(x, -0.5) - t_0;
}
return tmp;
}
def code(x): t_0 = 1.0 / math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) - t_0) <= 2e-23: tmp = 0.5 * math.pow(x, -1.5) else: tmp = math.pow(x, -0.5) - t_0 return tmp
function code(x) t_0 = Float64(1.0 / sqrt(Float64(1.0 + x))) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) - t_0) <= 2e-23) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64((x ^ -0.5) - t_0); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 / sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) - t_0) <= 2e-23) tmp = 0.5 * (x ^ -1.5); else tmp = (x ^ -0.5) - t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], 2e-23], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt{1 + x}}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} - t_0 \leq 2 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 35.8%
flip--35.8%
frac-times19.4%
metadata-eval19.4%
add-sqr-sqrt13.4%
frac-times24.7%
metadata-eval24.7%
add-sqr-sqrt35.8%
+-commutative35.8%
pow1/235.8%
pow-flip35.8%
metadata-eval35.8%
inv-pow35.8%
sqrt-pow235.8%
+-commutative35.8%
metadata-eval35.8%
Applied egg-rr35.8%
frac-sub36.4%
*-un-lft-identity36.4%
Applied egg-rr36.4%
*-rgt-identity36.4%
associate--l+84.9%
+-inverses84.9%
metadata-eval84.9%
associate-/r*86.2%
Simplified86.2%
Taylor expanded in x around inf 59.0%
unpow-159.0%
exp-to-pow57.1%
*-commutative57.1%
exp-prod58.7%
*-commutative58.7%
associate-*r*58.7%
metadata-eval58.7%
*-commutative58.7%
exp-to-pow60.6%
metadata-eval60.6%
pow-sqr60.6%
rem-sqrt-square100.0%
rem-square-sqrt99.4%
fabs-sqr99.4%
rem-square-sqrt100.0%
Simplified100.0%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
expm1-log1p-u92.1%
expm1-udef91.8%
pow1/291.8%
pow-flip91.8%
metadata-eval91.8%
Applied egg-rr91.8%
expm1-def92.1%
expm1-log1p99.6%
Simplified99.6%
Final simplification99.8%
(FPCore (x) :precision binary64 (* (/ 1.0 x) (/ 1.0 (* (+ 1.0 x) (+ (pow (+ 1.0 x) -0.5) (pow x -0.5))))))
double code(double x) {
return (1.0 / x) * (1.0 / ((1.0 + x) * (pow((1.0 + x), -0.5) + pow(x, -0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) * (1.0d0 / ((1.0d0 + x) * (((1.0d0 + x) ** (-0.5d0)) + (x ** (-0.5d0)))))
end function
public static double code(double x) {
return (1.0 / x) * (1.0 / ((1.0 + x) * (Math.pow((1.0 + x), -0.5) + Math.pow(x, -0.5))));
}
def code(x): return (1.0 / x) * (1.0 / ((1.0 + x) * (math.pow((1.0 + x), -0.5) + math.pow(x, -0.5))))
function code(x) return Float64(Float64(1.0 / x) * Float64(1.0 / Float64(Float64(1.0 + x) * Float64((Float64(1.0 + x) ^ -0.5) + (x ^ -0.5))))) end
function tmp = code(x) tmp = (1.0 / x) * (1.0 / ((1.0 + x) * (((1.0 + x) ^ -0.5) + (x ^ -0.5)))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision] + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} \cdot \frac{1}{\left(1 + x\right) \cdot \left({\left(1 + x\right)}^{-0.5} + {x}^{-0.5}\right)}
\end{array}
Initial program 68.8%
flip--68.7%
frac-times60.7%
metadata-eval60.7%
add-sqr-sqrt57.7%
frac-times63.2%
metadata-eval63.2%
add-sqr-sqrt68.5%
+-commutative68.5%
pow1/268.5%
pow-flip68.5%
metadata-eval68.5%
inv-pow68.5%
sqrt-pow268.5%
+-commutative68.5%
metadata-eval68.5%
Applied egg-rr68.5%
frac-sub69.0%
*-un-lft-identity69.0%
Applied egg-rr69.0%
*-rgt-identity69.0%
associate--l+92.2%
+-inverses92.2%
metadata-eval92.2%
associate-/r*92.9%
Simplified92.9%
associate-/l/99.3%
div-inv99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 118000000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 118000000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 118000000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 118000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 118000000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 118000000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 118000000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 118000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 118000000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1.18e8Initial program 99.3%
*-un-lft-identity99.3%
clear-num99.3%
associate-/r/99.3%
prod-diff99.3%
*-un-lft-identity99.3%
fma-neg99.3%
*-un-lft-identity99.3%
pow1/299.3%
pow-flip99.6%
metadata-eval99.6%
pow1/299.6%
pow-flip99.6%
+-commutative99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-+l-99.6%
expm1-log1p99.6%
expm1-def99.4%
associate--l-99.4%
fma-udef99.4%
distribute-lft1-in99.4%
metadata-eval99.4%
mul0-lft99.4%
metadata-eval99.4%
expm1-def99.6%
expm1-log1p99.6%
Simplified99.6%
if 1.18e8 < x Initial program 35.8%
flip--35.8%
frac-times19.4%
metadata-eval19.4%
add-sqr-sqrt13.4%
frac-times24.7%
metadata-eval24.7%
add-sqr-sqrt35.8%
+-commutative35.8%
pow1/235.8%
pow-flip35.8%
metadata-eval35.8%
inv-pow35.8%
sqrt-pow235.8%
+-commutative35.8%
metadata-eval35.8%
Applied egg-rr35.8%
frac-sub36.4%
*-un-lft-identity36.4%
Applied egg-rr36.4%
*-rgt-identity36.4%
associate--l+84.9%
+-inverses84.9%
metadata-eval84.9%
associate-/r*86.2%
Simplified86.2%
Taylor expanded in x around inf 59.0%
unpow-159.0%
exp-to-pow57.1%
*-commutative57.1%
exp-prod58.7%
*-commutative58.7%
associate-*r*58.7%
metadata-eval58.7%
*-commutative58.7%
exp-to-pow60.6%
metadata-eval60.6%
pow-sqr60.6%
rem-sqrt-square100.0%
rem-square-sqrt99.4%
fabs-sqr99.4%
rem-square-sqrt100.0%
Simplified100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.68) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.68d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.68: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.68) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.68) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.68], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.68:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1.67999999999999994Initial program 99.7%
Taylor expanded in x around 0 99.4%
*-commutative99.4%
Simplified99.4%
expm1-log1p-u92.3%
expm1-udef92.3%
pow1/292.3%
pow-flip92.3%
metadata-eval92.3%
Applied egg-rr92.0%
expm1-def92.3%
expm1-log1p100.0%
Simplified99.7%
if 1.67999999999999994 < x Initial program 36.9%
flip--36.9%
frac-times20.9%
metadata-eval20.9%
add-sqr-sqrt15.0%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.9%
+-commutative36.9%
pow1/236.9%
pow-flip36.9%
metadata-eval36.9%
inv-pow36.9%
sqrt-pow236.9%
+-commutative36.9%
metadata-eval36.9%
Applied egg-rr36.9%
frac-sub37.9%
*-un-lft-identity37.9%
Applied egg-rr37.9%
*-rgt-identity37.9%
associate--l+85.2%
+-inverses85.2%
metadata-eval85.2%
associate-/r*86.5%
Simplified86.5%
Taylor expanded in x around inf 58.5%
unpow-158.5%
exp-to-pow56.7%
*-commutative56.7%
exp-prod58.2%
*-commutative58.2%
associate-*r*58.2%
metadata-eval58.2%
*-commutative58.2%
exp-to-pow60.1%
metadata-eval60.1%
pow-sqr60.1%
rem-sqrt-square98.5%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.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 = 0.5d0 * (x ** (-1.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 = 0.5 * Math.pow(x, -1.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 = 0.5 * math.pow(x, -1.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(0.5 * (x ^ -1.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 = 0.5 * (x ^ -1.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[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1Initial program 99.7%
*-un-lft-identity99.7%
clear-num99.7%
associate-/r/99.7%
prod-diff99.7%
*-un-lft-identity99.7%
fma-neg99.7%
*-un-lft-identity99.7%
pow1/299.7%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 99.7%
if 1 < x Initial program 36.9%
flip--36.9%
frac-times20.9%
metadata-eval20.9%
add-sqr-sqrt15.0%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.9%
+-commutative36.9%
pow1/236.9%
pow-flip36.9%
metadata-eval36.9%
inv-pow36.9%
sqrt-pow236.9%
+-commutative36.9%
metadata-eval36.9%
Applied egg-rr36.9%
frac-sub37.9%
*-un-lft-identity37.9%
Applied egg-rr37.9%
*-rgt-identity37.9%
associate--l+85.2%
+-inverses85.2%
metadata-eval85.2%
associate-/r*86.5%
Simplified86.5%
Taylor expanded in x around inf 58.5%
unpow-158.5%
exp-to-pow56.7%
*-commutative56.7%
exp-prod58.2%
*-commutative58.2%
associate-*r*58.2%
metadata-eval58.2%
*-commutative58.2%
exp-to-pow60.1%
metadata-eval60.1%
pow-sqr60.1%
rem-sqrt-square98.5%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 0.67) (+ (pow x -0.5) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.67) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.67d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.67) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.67: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.67) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.67) tmp = (x ^ -0.5) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.67], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.67:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.67000000000000004Initial program 99.7%
*-un-lft-identity99.7%
clear-num99.7%
associate-/r/99.7%
prod-diff99.7%
*-un-lft-identity99.7%
fma-neg99.7%
*-un-lft-identity99.7%
pow1/299.7%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
if 0.67000000000000004 < x Initial program 36.9%
flip--36.9%
frac-times20.9%
metadata-eval20.9%
add-sqr-sqrt15.0%
frac-times26.1%
metadata-eval26.1%
add-sqr-sqrt36.9%
+-commutative36.9%
pow1/236.9%
pow-flip36.9%
metadata-eval36.9%
inv-pow36.9%
sqrt-pow236.9%
+-commutative36.9%
metadata-eval36.9%
Applied egg-rr36.9%
frac-sub37.9%
*-un-lft-identity37.9%
Applied egg-rr37.9%
*-rgt-identity37.9%
associate--l+85.2%
+-inverses85.2%
metadata-eval85.2%
associate-/r*86.5%
Simplified86.5%
Taylor expanded in x around inf 58.5%
unpow-158.5%
exp-to-pow56.7%
*-commutative56.7%
exp-prod58.2%
*-commutative58.2%
associate-*r*58.2%
metadata-eval58.2%
*-commutative58.2%
exp-to-pow60.1%
metadata-eval60.1%
pow-sqr60.1%
rem-sqrt-square98.5%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification98.8%
(FPCore (x) :precision binary64 (* 0.5 (pow x -1.5)))
double code(double x) {
return 0.5 * pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** (-1.5d0))
end function
public static double code(double x) {
return 0.5 * Math.pow(x, -1.5);
}
def code(x): return 0.5 * math.pow(x, -1.5)
function code(x) return Float64(0.5 * (x ^ -1.5)) end
function tmp = code(x) tmp = 0.5 * (x ^ -1.5); end
code[x_] := N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-1.5}
\end{array}
Initial program 68.8%
flip--68.7%
frac-times60.7%
metadata-eval60.7%
add-sqr-sqrt57.7%
frac-times63.2%
metadata-eval63.2%
add-sqr-sqrt68.5%
+-commutative68.5%
pow1/268.5%
pow-flip68.5%
metadata-eval68.5%
inv-pow68.5%
sqrt-pow268.5%
+-commutative68.5%
metadata-eval68.5%
Applied egg-rr68.5%
frac-sub69.0%
*-un-lft-identity69.0%
Applied egg-rr69.0%
*-rgt-identity69.0%
associate--l+92.2%
+-inverses92.2%
metadata-eval92.2%
associate-/r*92.9%
Simplified92.9%
Taylor expanded in x around inf 31.4%
unpow-131.4%
exp-to-pow30.5%
*-commutative30.5%
exp-prod31.3%
*-commutative31.3%
associate-*r*31.3%
metadata-eval31.3%
*-commutative31.3%
exp-to-pow32.2%
metadata-eval32.2%
pow-sqr32.2%
rem-sqrt-square51.2%
rem-square-sqrt51.0%
fabs-sqr51.0%
rem-square-sqrt51.2%
Simplified51.2%
Final simplification51.2%
(FPCore (x) :precision binary64 (pow x -1.5))
double code(double x) {
return pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** (-1.5d0)
end function
public static double code(double x) {
return Math.pow(x, -1.5);
}
def code(x): return math.pow(x, -1.5)
function code(x) return x ^ -1.5 end
function tmp = code(x) tmp = x ^ -1.5; end
code[x_] := N[Power[x, -1.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5}
\end{array}
Initial program 68.8%
sub-neg68.8%
flip-+68.7%
frac-times60.7%
metadata-eval60.7%
add-sqr-sqrt57.7%
distribute-neg-frac57.7%
metadata-eval57.7%
+-commutative57.7%
distribute-neg-frac57.7%
metadata-eval57.7%
+-commutative57.7%
pow1/257.7%
pow-flip57.7%
metadata-eval57.7%
Applied egg-rr57.7%
associate-*r/60.2%
associate-*l/60.2%
metadata-eval60.2%
sub-neg60.2%
distribute-neg-frac60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around inf 21.7%
expm1-log1p-u21.7%
expm1-udef20.0%
pow1/220.0%
pow-flip20.0%
pow-pow20.1%
metadata-eval20.1%
metadata-eval20.1%
Applied egg-rr20.1%
expm1-def24.4%
expm1-log1p24.4%
Simplified24.4%
Final simplification24.4%
(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 2023305
(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)))))