
(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 10 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) 1e-6)
(*
(+
(/ 0.5 x)
(-
(/ 0.3125 (pow x 3.0))
(+ (/ 0.375 (* x x)) (/ 0.2734375 (pow x 4.0)))))
(pow x -0.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) <= 1e-6) {
tmp = ((0.5 / x) + ((0.3125 / pow(x, 3.0)) - ((0.375 / (x * x)) + (0.2734375 / pow(x, 4.0))))) * pow(x, -0.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) <= 1d-6) then
tmp = ((0.5d0 / x) + ((0.3125d0 / (x ** 3.0d0)) - ((0.375d0 / (x * x)) + (0.2734375d0 / (x ** 4.0d0))))) * (x ** (-0.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) <= 1e-6) {
tmp = ((0.5 / x) + ((0.3125 / Math.pow(x, 3.0)) - ((0.375 / (x * x)) + (0.2734375 / Math.pow(x, 4.0))))) * Math.pow(x, -0.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) <= 1e-6: tmp = ((0.5 / x) + ((0.3125 / math.pow(x, 3.0)) - ((0.375 / (x * x)) + (0.2734375 / math.pow(x, 4.0))))) * math.pow(x, -0.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) <= 1e-6) tmp = Float64(Float64(Float64(0.5 / x) + Float64(Float64(0.3125 / (x ^ 3.0)) - Float64(Float64(0.375 / Float64(x * x)) + Float64(0.2734375 / (x ^ 4.0))))) * (x ^ -0.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) <= 1e-6) tmp = ((0.5 / x) + ((0.3125 / (x ^ 3.0)) - ((0.375 / (x * x)) + (0.2734375 / (x ^ 4.0))))) * (x ^ -0.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], 1e-6], N[(N[(N[(0.5 / x), $MachinePrecision] + N[(N[(0.3125 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - N[(N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.2734375 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -0.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 10^{-6}:\\
\;\;\;\;\left(\frac{0.5}{x} + \left(\frac{0.3125}{{x}^{3}} - \left(\frac{0.375}{x \cdot x} + \frac{0.2734375}{{x}^{4}}\right)\right)\right) \cdot {x}^{-0.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)))) < 9.99999999999999955e-7Initial program 30.9%
frac-sub30.9%
div-inv30.9%
*-un-lft-identity30.9%
+-commutative30.9%
*-rgt-identity30.9%
metadata-eval30.9%
frac-times30.9%
un-div-inv30.9%
pow1/230.9%
pow-flip30.9%
metadata-eval30.9%
+-commutative30.9%
Applied egg-rr30.9%
associate-*r/30.9%
*-rgt-identity30.9%
times-frac30.9%
div-sub30.9%
*-inverses30.9%
/-rgt-identity30.9%
Simplified30.9%
Taylor expanded in x around inf 99.5%
associate--l+99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
associate-*r/99.5%
metadata-eval99.5%
unpow299.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
if 9.99999999999999955e-7 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
add-log-exp5.1%
*-un-lft-identity5.1%
log-prod5.1%
metadata-eval5.1%
add-log-exp99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ -1.0 (sqrt (+ 1.0 x)))))
(if (<= (+ (/ 1.0 (sqrt x)) t_0) 1e-10)
(/ (pow x -0.5) (/ x (+ 0.5 (/ -0.375 x))))
(+ (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) <= 1e-10) {
tmp = pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
} 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) <= 1d-10) then
tmp = (x ** (-0.5d0)) / (x / (0.5d0 + ((-0.375d0) / x)))
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) <= 1e-10) {
tmp = Math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
} 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) <= 1e-10: tmp = math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x))) 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) <= 1e-10) tmp = Float64((x ^ -0.5) / Float64(x / Float64(0.5 + Float64(-0.375 / x)))); 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) <= 1e-10) tmp = (x ^ -0.5) / (x / (0.5 + (-0.375 / x))); 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], 1e-10], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x / N[(0.5 + N[(-0.375 / x), $MachinePrecision]), $MachinePrecision]), $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 10^{-10}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\frac{x}{0.5 + \frac{-0.375}{x}}}\\
\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.00000000000000004e-10Initial program 30.4%
frac-sub30.4%
div-inv30.4%
*-un-lft-identity30.4%
+-commutative30.4%
*-rgt-identity30.4%
metadata-eval30.4%
frac-times30.4%
un-div-inv30.4%
pow1/230.4%
pow-flip30.4%
metadata-eval30.4%
+-commutative30.4%
Applied egg-rr30.4%
associate-*r/30.4%
*-rgt-identity30.4%
times-frac30.4%
div-sub30.5%
*-inverses30.5%
/-rgt-identity30.5%
Simplified30.5%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
associate-*r/99.4%
metadata-eval99.4%
unpow299.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef29.2%
*-commutative29.2%
associate-/r*29.2%
sub-div29.2%
Applied egg-rr29.2%
expm1-def99.4%
expm1-log1p99.4%
associate-*r/99.5%
associate-/l*99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
if 1.00000000000000004e-10 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
add-log-exp5.5%
*-un-lft-identity5.5%
log-prod5.5%
metadata-eval5.5%
add-log-exp99.4%
pow1/299.4%
pow-flip99.9%
metadata-eval99.9%
Applied egg-rr99.9%
+-lft-identity99.9%
Simplified99.9%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 160000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (pow x -0.5) (/ x (+ 0.5 (/ -0.375 x))))))
double code(double x) {
double tmp;
if (x <= 160000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 160000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = (x ** (-0.5d0)) / (x / (0.5d0 + ((-0.375d0) / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 160000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = Math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 160000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 160000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64((x ^ -0.5) / Float64(x / Float64(0.5 + Float64(-0.375 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 160000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = (x ^ -0.5) / (x / (0.5 + (-0.375 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 160000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x / N[(0.5 + N[(-0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 160000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\frac{x}{0.5 + \frac{-0.375}{x}}}\\
\end{array}
\end{array}
if x < 1.6e5Initial 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.9%
metadata-eval99.9%
pow1/299.9%
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%
if 1.6e5 < x Initial program 30.4%
frac-sub30.4%
div-inv30.4%
*-un-lft-identity30.4%
+-commutative30.4%
*-rgt-identity30.4%
metadata-eval30.4%
frac-times30.4%
un-div-inv30.4%
pow1/230.4%
pow-flip30.4%
metadata-eval30.4%
+-commutative30.4%
Applied egg-rr30.4%
associate-*r/30.4%
*-rgt-identity30.4%
times-frac30.4%
div-sub30.5%
*-inverses30.5%
/-rgt-identity30.5%
Simplified30.5%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
associate-*r/99.4%
metadata-eval99.4%
unpow299.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef29.2%
*-commutative29.2%
associate-/r*29.2%
sub-div29.2%
Applied egg-rr29.2%
expm1-def99.4%
expm1-log1p99.4%
associate-*r/99.5%
associate-/l*99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 1.1) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (/ (pow x -0.5) (/ x (+ 0.5 (/ -0.375 x))))))
double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.1d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (x ** (-0.5d0)) / (x / (0.5d0 + ((-0.375d0) / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = Math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.1: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = math.pow(x, -0.5) / (x / (0.5 + (-0.375 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.1) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64((x ^ -0.5) / Float64(x / Float64(0.5 + Float64(-0.375 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.1) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = (x ^ -0.5) / (x / (0.5 + (-0.375 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.1], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x / N[(0.5 + N[(-0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\frac{x}{0.5 + \frac{-0.375}{x}}}\\
\end{array}
\end{array}
if x < 1.1000000000000001Initial 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.5%
if 1.1000000000000001 < x Initial program 30.9%
frac-sub30.9%
div-inv30.9%
*-un-lft-identity30.9%
+-commutative30.9%
*-rgt-identity30.9%
metadata-eval30.9%
frac-times30.9%
un-div-inv30.9%
pow1/230.9%
pow-flip30.9%
metadata-eval30.9%
+-commutative30.9%
Applied egg-rr30.9%
associate-*r/30.9%
*-rgt-identity30.9%
times-frac30.9%
div-sub30.9%
*-inverses30.9%
/-rgt-identity30.9%
Simplified30.9%
Taylor expanded in x around inf 99.0%
associate-*r/99.0%
metadata-eval99.0%
associate-*r/99.0%
metadata-eval99.0%
unpow299.0%
Simplified99.0%
expm1-log1p-u99.0%
expm1-udef29.4%
*-commutative29.4%
associate-/r*29.4%
sub-div29.4%
Applied egg-rr29.4%
expm1-def99.0%
expm1-log1p99.0%
associate-*r/99.1%
associate-/l*99.1%
sub-neg99.1%
distribute-neg-frac99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = (0.5 / x) * pow(x, -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)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (0.5d0 / x) * (x ** (-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) + (-1.0 - (x * -0.5));
} else {
tmp = (0.5 / x) * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = (0.5 / x) * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64(Float64(0.5 / x) * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = (0.5 / x) * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {x}^{-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.5%
if 1 < x Initial program 30.9%
frac-sub30.9%
div-inv30.9%
*-un-lft-identity30.9%
+-commutative30.9%
*-rgt-identity30.9%
metadata-eval30.9%
frac-times30.9%
un-div-inv30.9%
pow1/230.9%
pow-flip30.9%
metadata-eval30.9%
+-commutative30.9%
Applied egg-rr30.9%
associate-*r/30.9%
*-rgt-identity30.9%
times-frac30.9%
div-sub30.9%
*-inverses30.9%
/-rgt-identity30.9%
Simplified30.9%
Taylor expanded in x around inf 97.9%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.66d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (0.5d0 / x) * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) + -1.0; else tmp = (0.5 / x) * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.6%
Taylor expanded in x around 0 98.8%
add-log-exp5.1%
*-un-lft-identity5.1%
log-prod5.1%
metadata-eval5.1%
add-log-exp99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr99.2%
+-lft-identity100.0%
Simplified99.2%
if 0.660000000000000031 < x Initial program 30.9%
frac-sub30.9%
div-inv30.9%
*-un-lft-identity30.9%
+-commutative30.9%
*-rgt-identity30.9%
metadata-eval30.9%
frac-times30.9%
un-div-inv30.9%
pow1/230.9%
pow-flip30.9%
metadata-eval30.9%
+-commutative30.9%
Applied egg-rr30.9%
associate-*r/30.9%
*-rgt-identity30.9%
times-frac30.9%
div-sub30.9%
*-inverses30.9%
/-rgt-identity30.9%
Simplified30.9%
Taylor expanded in x around inf 97.9%
Final simplification98.7%
(FPCore (x) :precision binary64 (+ (pow x -0.5) -1.0))
double code(double x) {
return pow(x, -0.5) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) + (-1.0d0)
end function
public static double code(double x) {
return Math.pow(x, -0.5) + -1.0;
}
def code(x): return math.pow(x, -0.5) + -1.0
function code(x) return Float64((x ^ -0.5) + -1.0) end
function tmp = code(x) tmp = (x ^ -0.5) + -1.0; end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} + -1
\end{array}
Initial program 71.7%
Taylor expanded in x around 0 59.7%
add-log-exp5.0%
*-un-lft-identity5.0%
log-prod5.0%
metadata-eval5.0%
add-log-exp71.7%
pow1/271.7%
pow-flip70.0%
metadata-eval70.0%
Applied egg-rr59.9%
+-lft-identity70.0%
Simplified59.9%
Final simplification59.9%
(FPCore (x) :precision binary64 (sqrt (/ 1.0 x)))
double code(double x) {
return sqrt((1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((1.0d0 / x))
end function
public static double code(double x) {
return Math.sqrt((1.0 / x));
}
def code(x): return math.sqrt((1.0 / x))
function code(x) return sqrt(Float64(1.0 / x)) end
function tmp = code(x) tmp = sqrt((1.0 / x)); end
code[x_] := N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{x}}
\end{array}
Initial program 71.7%
add-log-exp5.0%
*-un-lft-identity5.0%
log-prod5.0%
metadata-eval5.0%
add-log-exp71.7%
pow1/271.7%
pow-flip70.0%
metadata-eval70.0%
Applied egg-rr70.0%
+-lft-identity70.0%
Simplified70.0%
Taylor expanded in x around inf 58.7%
Final simplification58.7%
(FPCore (x) :precision binary64 (pow x -0.5))
double code(double x) {
return pow(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 Math.pow(x, -0.5);
}
def code(x): return math.pow(x, -0.5)
function code(x) return x ^ -0.5 end
function tmp = code(x) tmp = x ^ -0.5; end
code[x_] := N[Power[x, -0.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5}
\end{array}
Initial program 71.7%
frac-sub71.6%
div-inv71.6%
*-un-lft-identity71.6%
+-commutative71.6%
*-rgt-identity71.6%
metadata-eval71.6%
frac-times71.7%
un-div-inv71.7%
pow1/271.7%
pow-flip71.9%
metadata-eval71.9%
+-commutative71.9%
Applied egg-rr71.9%
associate-*r/71.9%
*-rgt-identity71.9%
times-frac71.9%
div-sub71.9%
*-inverses71.9%
/-rgt-identity71.9%
Simplified71.9%
Taylor expanded in x around 0 58.8%
Final simplification58.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 71.7%
Taylor expanded in x around 0 60.3%
Taylor expanded in x around inf 4.2%
*-commutative4.2%
Simplified4.2%
Final simplification4.2%
(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 2023227
(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)))))