
(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 (/ (/ 1.0 x) (+ (* (pow x -0.5) (+ 1.0 x)) (sqrt (+ 1.0 x)))))
double code(double x) {
return (1.0 / x) / ((pow(x, -0.5) * (1.0 + x)) + sqrt((1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / (((x ** (-0.5d0)) * (1.0d0 + x)) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return (1.0 / x) / ((Math.pow(x, -0.5) * (1.0 + x)) + Math.sqrt((1.0 + x)));
}
def code(x): return (1.0 / x) / ((math.pow(x, -0.5) * (1.0 + x)) + math.sqrt((1.0 + x)))
function code(x) return Float64(Float64(1.0 / x) / Float64(Float64((x ^ -0.5) * Float64(1.0 + x)) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = (1.0 / x) / (((x ^ -0.5) * (1.0 + x)) + sqrt((1.0 + x))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / N[(N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{{x}^{-0.5} \cdot \left(1 + x\right) + \sqrt{1 + x}}
\end{array}
Initial program 65.5%
add-log-exp48.6%
*-un-lft-identity48.6%
log-prod48.6%
metadata-eval48.6%
add-log-exp65.5%
inv-pow65.5%
sqrt-pow260.6%
+-commutative60.6%
metadata-eval60.6%
Applied egg-rr60.6%
+-lft-identity60.6%
Simplified60.6%
flip--60.6%
frac-times54.7%
metadata-eval54.7%
add-sqr-sqrt56.3%
pow-prod-up65.5%
metadata-eval65.5%
inv-pow65.5%
inv-pow65.5%
sqrt-pow265.5%
metadata-eval65.5%
metadata-eval65.5%
sqrt-pow265.5%
inv-pow65.5%
div-inv65.4%
Applied egg-rr67.0%
*-rgt-identity67.0%
*-rgt-identity67.0%
associate--l+89.6%
+-inverses89.6%
metadata-eval89.6%
associate-*l*98.8%
associate-/r*99.3%
Simplified99.3%
distribute-rgt-in99.4%
pow-plus99.4%
metadata-eval99.4%
pow1/299.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 5e-9) (/ (/ 1.0 x) (+ (* (sqrt (/ 1.0 x)) 1.5) (* (sqrt x) 2.0))) (* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-9) {
tmp = (1.0 / x) / ((sqrt((1.0 / x)) * 1.5) + (sqrt(x) * 2.0));
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((x / (1.0 + x))));
}
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)))) <= 5d-9) then
tmp = (1.0d0 / x) / ((sqrt((1.0d0 / x)) * 1.5d0) + (sqrt(x) * 2.0d0))
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((x / (1.0d0 + x))))
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)))) <= 5e-9) {
tmp = (1.0 / x) / ((Math.sqrt((1.0 / x)) * 1.5) + (Math.sqrt(x) * 2.0));
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 5e-9: tmp = (1.0 / x) / ((math.sqrt((1.0 / x)) * 1.5) + (math.sqrt(x) * 2.0)) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 5e-9) tmp = Float64(Float64(1.0 / x) / Float64(Float64(sqrt(Float64(1.0 / x)) * 1.5) + Float64(sqrt(x) * 2.0))); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(x / Float64(1.0 + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-9) tmp = (1.0 / x) / ((sqrt((1.0 / x)) * 1.5) + (sqrt(x) * 2.0)); else tmp = (x ^ -0.5) * (1.0 - sqrt((x / (1.0 + x)))); 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], 5e-9], N[(N[(1.0 / x), $MachinePrecision] / N[(N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 1.5), $MachinePrecision] + N[(N[Sqrt[x], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{\frac{1}{x}}{\sqrt{\frac{1}{x}} \cdot 1.5 + \sqrt{x} \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 5.0000000000000001e-9Initial program 37.9%
add-log-exp7.3%
*-un-lft-identity7.3%
log-prod7.3%
metadata-eval7.3%
add-log-exp37.9%
inv-pow37.9%
sqrt-pow229.2%
+-commutative29.2%
metadata-eval29.2%
Applied egg-rr29.2%
+-lft-identity29.2%
Simplified29.2%
flip--29.1%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt21.5%
pow-prod-up38.1%
metadata-eval38.1%
inv-pow38.1%
inv-pow38.1%
sqrt-pow238.1%
metadata-eval38.1%
metadata-eval38.1%
sqrt-pow238.1%
inv-pow38.1%
div-inv38.1%
Applied egg-rr40.8%
*-rgt-identity40.8%
*-rgt-identity40.8%
associate--l+81.8%
+-inverses81.8%
metadata-eval81.8%
associate-*l*98.5%
associate-/r*99.5%
Simplified99.5%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
associate-+r+99.0%
distribute-rgt-out99.0%
metadata-eval99.0%
Simplified99.0%
if 5.0000000000000001e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
frac-sub99.3%
div-inv99.3%
*-un-lft-identity99.3%
+-commutative99.3%
*-rgt-identity99.3%
metadata-eval99.3%
frac-times99.3%
un-div-inv99.3%
pow1/299.3%
pow-flip99.8%
metadata-eval99.8%
+-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
times-frac99.8%
div-sub99.7%
*-inverses99.7%
/-rgt-identity99.7%
Simplified99.7%
*-un-lft-identity99.7%
sqrt-undiv99.7%
+-commutative99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 3e-9) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x x)))) (* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 3e-9) {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((x / (1.0 + x))));
}
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)))) <= 3d-9) then
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * x)))
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((x / (1.0d0 + x))))
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)))) <= 3e-9) {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 3e-9: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x))) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 3e-9) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x)))); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(x / Float64(1.0 + x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 3e-9) tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * x))); else tmp = (x ^ -0.5) * (1.0 - sqrt((x / (1.0 + x)))); 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], 3e-9], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 3 \cdot 10^{-9}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.99999999999999998e-9Initial program 37.5%
frac-sub37.5%
div-inv37.5%
*-un-lft-identity37.5%
+-commutative37.5%
*-rgt-identity37.5%
metadata-eval37.5%
frac-times37.5%
un-div-inv37.5%
pow1/237.5%
pow-flip37.5%
metadata-eval37.5%
+-commutative37.5%
Applied egg-rr37.5%
associate-*r/37.5%
*-rgt-identity37.5%
times-frac37.5%
div-sub37.4%
*-inverses37.4%
/-rgt-identity37.4%
Simplified37.4%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
associate-*r/99.3%
metadata-eval99.3%
unpow299.3%
Simplified99.3%
if 2.99999999999999998e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.8%
frac-sub98.8%
div-inv98.9%
*-un-lft-identity98.9%
+-commutative98.9%
*-rgt-identity98.9%
metadata-eval98.9%
frac-times98.8%
un-div-inv98.8%
pow1/298.8%
pow-flip99.3%
metadata-eval99.3%
+-commutative99.3%
Applied egg-rr99.3%
associate-*r/99.3%
*-rgt-identity99.3%
times-frac99.3%
div-sub99.2%
*-inverses99.2%
/-rgt-identity99.2%
Simplified99.2%
*-un-lft-identity99.2%
sqrt-undiv99.3%
+-commutative99.3%
Applied egg-rr99.3%
*-lft-identity99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ -1.0 (sqrt (+ 1.0 x)))))
(if (<= (+ (/ 1.0 (sqrt x)) t_0) 5e-9)
(* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x 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) <= 5e-9) {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * 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) <= 5d-9) then
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * 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) <= 5e-9) {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * 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) <= 5e-9: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * 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) <= 5e-9) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * 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) <= 5e-9) tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * 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], 5e-9], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * 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 5 \cdot 10^{-9}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\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)))) < 5.0000000000000001e-9Initial program 37.9%
frac-sub38.0%
div-inv38.0%
*-un-lft-identity38.0%
+-commutative38.0%
*-rgt-identity38.0%
metadata-eval38.0%
frac-times38.0%
un-div-inv38.0%
pow1/238.0%
pow-flip38.0%
metadata-eval38.0%
+-commutative38.0%
Applied egg-rr38.0%
associate-*r/38.0%
*-rgt-identity38.0%
times-frac38.0%
div-sub37.9%
*-inverses37.9%
/-rgt-identity37.9%
Simplified37.9%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
metadata-eval98.9%
unpow298.9%
Simplified98.9%
if 5.0000000000000001e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
add-log-exp7.6%
*-un-lft-identity7.6%
log-prod7.6%
metadata-eval7.6%
add-log-exp99.3%
pow1/299.3%
pow-flip99.7%
metadata-eval99.7%
Applied egg-rr99.7%
+-lft-identity99.7%
Simplified99.7%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 160000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x 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) * ((0.5 / x) - (0.375 / (x * 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)) * ((0.5d0 / x) - (0.375d0 / (x * 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) * ((0.5 / x) - (0.375 / (x * 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) * ((0.5 / x) - (0.375 / (x * 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(Float64(0.5 / x) - Float64(0.375 / Float64(x * 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) * ((0.5 / x) - (0.375 / (x * 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[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * 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}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\end{array}
\end{array}
if x < 1.6e5Initial 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%
inv-pow99.3%
sqrt-pow299.7%
metadata-eval99.7%
pow1/299.7%
pow-flip99.7%
+-commutative99.7%
metadata-eval99.7%
Applied egg-rr99.7%
fma-udef99.7%
distribute-lft1-in99.7%
metadata-eval99.7%
mul0-lft99.7%
+-rgt-identity99.7%
Simplified99.7%
if 1.6e5 < x Initial program 37.9%
frac-sub38.0%
div-inv38.0%
*-un-lft-identity38.0%
+-commutative38.0%
*-rgt-identity38.0%
metadata-eval38.0%
frac-times38.0%
un-div-inv38.0%
pow1/238.0%
pow-flip38.0%
metadata-eval38.0%
+-commutative38.0%
Applied egg-rr38.0%
associate-*r/38.0%
*-rgt-identity38.0%
times-frac38.0%
div-sub37.9%
*-inverses37.9%
/-rgt-identity37.9%
Simplified37.9%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
associate-*r/98.9%
metadata-eval98.9%
unpow298.9%
Simplified98.9%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 1.1) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -0.5) (- (/ 0.5 x) (/ 0.375 (* x x))))))
double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * 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)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) * ((0.5d0 / x) - (0.375d0 / (x * 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) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.1: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) * ((0.5 / x) - (0.375 / (x * x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.1) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.1) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) * ((0.5 / x) - (0.375 / (x * x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.1], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right)\\
\end{array}
\end{array}
if x < 1.1000000000000001Initial program 99.5%
*-un-lft-identity99.5%
clear-num99.5%
associate-/r/99.5%
prod-diff99.5%
*-un-lft-identity99.5%
fma-neg99.5%
*-un-lft-identity99.5%
inv-pow99.5%
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.1%
if 1.1000000000000001 < x Initial program 38.6%
frac-sub38.7%
div-inv38.7%
*-un-lft-identity38.7%
+-commutative38.7%
*-rgt-identity38.7%
metadata-eval38.7%
frac-times38.7%
un-div-inv38.7%
pow1/238.7%
pow-flip38.7%
metadata-eval38.7%
+-commutative38.7%
Applied egg-rr38.7%
associate-*r/38.7%
*-rgt-identity38.7%
times-frac38.7%
div-sub38.6%
*-inverses38.6%
/-rgt-identity38.6%
Simplified38.6%
Taylor expanded in x around inf 98.3%
associate-*r/98.3%
metadata-eval98.3%
associate-*r/98.3%
metadata-eval98.3%
unpow298.3%
Simplified98.3%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (/ (pow x -0.5) x))))
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, -0.5) / x);
}
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 ** (-0.5d0)) / x)
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, -0.5) / x);
}
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, -0.5) / x) 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 * Float64((x ^ -0.5) / x)); 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 ^ -0.5) / x); 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[(N[Power[x, -0.5], $MachinePrecision] / x), $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 \frac{{x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 99.5%
*-un-lft-identity99.5%
clear-num99.5%
associate-/r/99.5%
prod-diff99.5%
*-un-lft-identity99.5%
fma-neg99.5%
*-un-lft-identity99.5%
inv-pow99.5%
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.1%
if 1 < x Initial program 38.6%
frac-sub38.7%
div-inv38.7%
*-un-lft-identity38.7%
+-commutative38.7%
*-rgt-identity38.7%
metadata-eval38.7%
frac-times38.7%
un-div-inv38.7%
pow1/238.7%
pow-flip38.7%
metadata-eval38.7%
+-commutative38.7%
Applied egg-rr38.7%
associate-*r/38.7%
*-rgt-identity38.7%
times-frac38.7%
div-sub38.6%
*-inverses38.6%
/-rgt-identity38.6%
Simplified38.6%
Taylor expanded in x around inf 37.2%
associate-*r/37.2%
metadata-eval37.2%
Simplified37.2%
expm1-log1p-u37.2%
expm1-udef36.0%
*-commutative36.0%
add-log-exp36.0%
associate--r-36.0%
metadata-eval36.0%
metadata-eval36.0%
exp-sum36.0%
add-exp-log36.0%
*-un-lft-identity36.0%
add-log-exp36.0%
Applied egg-rr36.0%
expm1-def96.1%
expm1-log1p96.1%
*-commutative96.1%
metadata-eval96.1%
associate-*r/96.1%
associate-*l*96.0%
associate-*l/96.2%
*-lft-identity96.2%
Simplified96.2%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* 0.5 (/ (pow x -0.5) x))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * (pow(x, -0.5) / x);
}
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 = 0.5d0 * ((x ** (-0.5d0)) / x)
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 = 0.5 * (Math.pow(x, -0.5) / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 0.5 * (math.pow(x, -0.5) / x) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(0.5 * Float64((x ^ -0.5) / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = 0.5 * ((x ^ -0.5) / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.5%
*-un-lft-identity99.5%
clear-num99.5%
associate-/r/99.5%
prod-diff99.5%
*-un-lft-identity99.5%
fma-neg99.5%
*-un-lft-identity99.5%
inv-pow99.5%
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.3%
if 0.680000000000000049 < x Initial program 38.6%
frac-sub38.7%
div-inv38.7%
*-un-lft-identity38.7%
+-commutative38.7%
*-rgt-identity38.7%
metadata-eval38.7%
frac-times38.7%
un-div-inv38.7%
pow1/238.7%
pow-flip38.7%
metadata-eval38.7%
+-commutative38.7%
Applied egg-rr38.7%
associate-*r/38.7%
*-rgt-identity38.7%
times-frac38.7%
div-sub38.6%
*-inverses38.6%
/-rgt-identity38.6%
Simplified38.6%
Taylor expanded in x around inf 37.2%
associate-*r/37.2%
metadata-eval37.2%
Simplified37.2%
expm1-log1p-u37.2%
expm1-udef36.0%
*-commutative36.0%
add-log-exp36.0%
associate--r-36.0%
metadata-eval36.0%
metadata-eval36.0%
exp-sum36.0%
add-exp-log36.0%
*-un-lft-identity36.0%
add-log-exp36.0%
Applied egg-rr36.0%
expm1-def96.1%
expm1-log1p96.1%
*-commutative96.1%
metadata-eval96.1%
associate-*r/96.1%
associate-*l*96.0%
associate-*l/96.2%
*-lft-identity96.2%
Simplified96.2%
Final simplification97.1%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (pow x -0.5) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = pow(x, -0.5);
} else {
tmp = -pow((x * x), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.35d+154) then
tmp = x ** (-0.5d0)
else
tmp = -((x * x) ** (-0.25d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = Math.pow(x, -0.5);
} else {
tmp = -Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.35e+154: tmp = math.pow(x, -0.5) else: tmp = -math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = x ^ -0.5; else tmp = Float64(-(Float64(x * x) ^ -0.25)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.35e+154) tmp = x ^ -0.5; else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.35e+154], N[Power[x, -0.5], $MachinePrecision], (-N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 66.0%
frac-sub66.0%
div-inv66.1%
*-un-lft-identity66.1%
+-commutative66.1%
*-rgt-identity66.1%
metadata-eval66.1%
frac-times66.0%
un-div-inv66.0%
pow1/266.0%
pow-flip66.3%
metadata-eval66.3%
+-commutative66.3%
Applied egg-rr66.3%
associate-*r/66.3%
*-rgt-identity66.3%
times-frac66.3%
div-sub66.3%
*-inverses66.3%
/-rgt-identity66.3%
Simplified66.3%
Taylor expanded in x around 0 61.2%
if 1.35000000000000003e154 < x Initial program 64.1%
add-log-exp4.4%
*-un-lft-identity4.4%
log-prod4.4%
metadata-eval4.4%
add-log-exp64.1%
inv-pow64.1%
sqrt-pow246.3%
+-commutative46.3%
metadata-eval46.3%
Applied egg-rr46.3%
+-lft-identity46.3%
Simplified46.3%
Taylor expanded in x around inf 4.1%
mul-1-neg4.1%
Simplified4.1%
inv-pow4.1%
sqrt-pow14.1%
metadata-eval4.1%
sqr-pow4.1%
pow-prod-down64.1%
metadata-eval64.1%
Applied egg-rr64.1%
Final simplification62.0%
(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 Float64(-(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 65.5%
add-log-exp48.6%
*-un-lft-identity48.6%
log-prod48.6%
metadata-eval48.6%
add-log-exp65.5%
inv-pow65.5%
sqrt-pow260.6%
+-commutative60.6%
metadata-eval60.6%
Applied egg-rr60.6%
+-lft-identity60.6%
Simplified60.6%
Taylor expanded in x around inf 2.2%
mul-1-neg2.2%
Simplified2.2%
inv-pow2.2%
sqrt-pow12.2%
metadata-eval2.2%
expm1-log1p-u2.2%
expm1-udef19.1%
Applied egg-rr19.1%
expm1-def2.2%
expm1-log1p2.2%
Simplified2.2%
Final simplification2.2%
(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 65.5%
frac-sub65.5%
div-inv65.5%
*-un-lft-identity65.5%
+-commutative65.5%
*-rgt-identity65.5%
metadata-eval65.5%
frac-times65.5%
un-div-inv65.5%
pow1/265.5%
pow-flip65.7%
metadata-eval65.7%
+-commutative65.7%
Applied egg-rr65.7%
associate-*r/65.7%
*-rgt-identity65.7%
times-frac65.7%
div-sub65.7%
*-inverses65.7%
/-rgt-identity65.7%
Simplified65.7%
Taylor expanded in x around 0 45.7%
Final simplification45.7%
(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 2023187
(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)))))