I am trying to determine pi to n decimals using Python but I can't figure why it isn't working. I initially tried with Machin's formula of pi = 16atan(1/5)-4atan(1/239) and Taylor expansion. def atan(x, n): k = 0 u = x # 1st value of u for k=0 t = u # 1st value of s for k=0 s = t # summ for k=0 while k&lt;n:     k += 1     u *= -(x*x)     t = u/(2*k+1)     s += t return s  Then I just ask for pi but it is limited to a small number of decimals pi_calc = 16arctang(1/5,10000000) - 4arctang(1/239,10000000) 3.141592653589794  I found another way with a spigot algo, but I thought my way could work a bit more... I suspect it is because we are limited by the precision of numbers in python but I'm not sure. Ideas? Thanks
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
Combining multiple textures with a white background I'd like to sort of "overlay" these shaders, but the only options are mix and add. Allow me to explain.  I made two images, both white background, one with red scribbles and one with blue scribbles, both 1920x1080. Image textures plugged into diffuse was my node setup. I want both scribbles to be added to the plane while the background stays the same color.  If I mix them I get the following:  The red and blue scribbles are now 50% dimmer than they would be on their own, and the white color hasn't changed in intensity.  If I add them I get the following:  The red and blue scribbles are still 50% dimmer than they normally would be (since the white background is being added over each). But the white background is now 2x brighter than normal.  Can I get a result where the white background is normal brightness and both the blue and red scribbles are at normal brightness? AirPort Time Capsule wifi is suddenly very slow: Boom network load alias fo rm command ( cp comand issue ) Can't install wine on Ubuntu 14.04 I cannot install Wine on Ubuntu 14.04.  When I try to install it on the Ubuntu Software Center I always get a message that says I have unmet dependencies. I tried installing Wine through the terminal and I get this:  Reading package lists... Done Building dependency tree        Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:  The following packages have unmet dependencies:  wine : Depends: wine1.6 but it is not going to be installed E: Unable to correct problems, you have held broken packages. I am trying to disable the touchscreen on my Asus S200E laptop.  In Ubuntu 16.04, I was able to do so with this:  Section "InputClass"     Identifier "evdev touchscreen catchall"     MatchIsTouchscreen "on"     MatchDevicePath "/dev/input/event*"     Driver "libinput" EndSection   How can this be done on Ubuntu 18.04? The definite and zero article with the word "civilization" Understanding MCMC and the Metropolis-Hastings algorithm Over the past few days I have been trying to understand how Markov Chain Monte Carlo (MCMC) works. In particular I have been trying to understand and implement the Metropolis-Hastings algorithm. So far I think I have an overall understanding of the algorithm but there are a couple of things that are not clear to me yet. I want to use MCMC to fit some models to data. Because of this I will describe my understanding of Metropolis-Hastings algorithm for fitting a straight line $f(x)=ax$ to some observed data $D$:  1) Make an initial guess for $a$. Set this $a$ as our current $a$ ($a_0$). Also add $a$ at the end of the Markov Chain ($C$).  2) Repeat the steps bellow a number of times.  3) Evaluate current likelihood (${\cal L_0}$) given $a_0$ and $D$.  4) Propose a new $a$ ($a_1$) by sampling from a normal distribution with $\mu=a_0$ and $\sigma=stepsize$. For now, $stepsize$ is constant.  5) Evaluate new likelihood (${\cal L_1}$) given $a_1$ and $D$.  6) If ${\cal L_1}$ is bigger than ${\cal L_0}$, accept $a_1$ as the new $a_0$, append it at the end of $C$ and go to step 2.  7) If ${\cal L_1}$ is smaller than ${\cal L_0}$ generate a number ($U$) in range [0,1] from a uniform distribution  8) If $U$ is smaller than the difference between the two likelihoods (${\cal L_1}$ - ${\cal L_0}$), accept $a_1$ as the new $a_0$, append it at the end of $C$ and go to step 2.  9) If $U$ is bigger than the difference between the two likelihoods (${\cal L_1}$ - ${\cal L_0}$), append the $a_0$ at the end of $C$, keep using the same $a_0$, go to step 2.  10) End of Repeat.  11) Remove some elements from the start of $C$ (burn-in phase).  12) Now take the average of the values in $C$. This average is the estimated $a$.  Now I have some questions regarding the above steps:   How do I construct the likelihood function for $f(x)=ax$ but also for any arbitrary function? Is this a correct implementation of Metropolis-Hastings algorithm? How the selection of the random number generation method at Step 7 can change the results? How is this algorithm going to change if I have multiple model parameters? For example, if I had the model $f(x)=ax+b$.   Notes/Credits: The main structure of the algorithm described above is based on the code from an MPIA Python Workshop. Language hints for quoted code In  I tried to add  for syntax formatting to code blocks quoted from the question. However, it seems they won't be honoured if I write them as a comment in my own part of the post, and if I include the hint in the qutotation as well then I have some ugly empty space before the code block. There should be a way to write these things properly. Chance of selecting the last k pages in correct order from a set of n pages I have a set of documents numbered 1 to n. If I arrange the documents randomly, what is the chance of selecting the last k pages in the correct order if I select them at random from the documents?   Because order is important, I use the following formula:  $\displaystyle\frac{n!}{(n-k)!}$  From this I calculate how many ways there are to select k pages from n pages in the correct order. I need to have the last k pages. Which I can do in only one way. So is the chance   1/$\displaystyle\frac{n!}{(n-k)!}$?   It seems unlikely. It seems to me spontaneously that the chance should be smaller. Let $A$ and $B$ be two $n \times n$ symmetric and positive definite matrices.   If $A \prec B$, then is it true that $B^{-1} \prec A^{-1}$?  Here, $A \prec B$ means that $B-A$ is positive definite. I'm having trouble with the OpenLayers Plugin of Qgis and the map composer:  If I create an OSM-background layer and if I want to export this, the OSM-Layer looks perfectly all right in the normal qgis program window. But in the map composer and after export the layer has shifted relatively to my other shape layers (EPSG:32633 - WGS 84 / UTM zone 33N).  The second thing is that the output resolution of the exported osm-layer is very, very poor.   A really bad way of getting around this whole trouble would be to increase the screen resolution and make a screenshot of the map composition window of qgis. But I don't think this would be very professional. It also would cause a lot of pain :)   I'm using Qgis 1.8.0-Lisboa under Linux. The openlayers plugin is version 0.92. Similar to , what's the best way to stay up to date with the latest stable releases of Thunderbird? Why is the Principle of Superposition true in EM? Does it hold more generally? In the theory of electromagnetism (EM), why is the principle of superposition true? Can we read it off from Maxwell's equations directly?  Does it have any limit of applicability or is it a fundamental property of nature? For every prime of the form $2^{4n}+1$, 7 is a primitive root. Driver locked memory on a non-virtual machine It seems that a List object cannot be stored in a List variable in C#, and can't even be explicitly cast that way.  List&lt;string&gt; sl = new List&lt;string&gt;(); List&lt;object&gt; ol; ol = sl;   results in Cannot implicitly convert type System.Collections.Generic.List&lt;string&gt; to System.Collections.Generic.List&lt;object&gt;  And then...  List&lt;string&gt; sl = new List&lt;string&gt;(); List&lt;object&gt; ol; ol = (List&lt;object&gt;)sl;   results in Cannot convert type System.Collections.Generic.List&lt;string&gt; to System.Collections.Generic.List&lt;object&gt;  Of course, you can do it by pulling everything out of the string list and putting it back in one at a time, but it is a rather convoluted solution. The statement is:     In a commutative ring with 1, every proper ideal is contained in a maximal ideal.   and we prove it using Zorn's lemma, that is, $I$ is an ideal, $P=\{I\subset  A\mid A\text{ is an ideal}\} $, then by set inclusion, every totally ordered subset has a bound, then $P$ has a maximal element $M$.  My question is why $M$ must contain $I$? I have a Canon 550D which I've been using for around a year now. I really love it and have learned a great deal with this and the 18 - 135mm kit lens. But now with experience I feel the need to get some better glass. I won't be buying a new body any time soon because I figure investing in some good glass is more important.   As I have looked around, I see quite a few good used L lenses I can get in ebay for good bargain prices. But I know that the EF lenses don't have the same focal length in the cropped sensors. Is it a wise decision to buy these EF lenses or buy the cropped sensor alternatives?  I have the following lenses in mind that I am looking to buy down the line from the canon range over the next several months.  16-35mm f/2.8L, 24-70mm f/2.8L, 70-200 f/4L.  Are these apt choices for cropped sensors? I know most pros with FFs use these but I am a bit skeptic that they will serve the same purpose for me. If so what are the alternatives for this that have almost as good image quality? Statement: $[a, b] \cap \mathbb{Q}$ in $\mathbb{Q}$ is not compact. Thus the interior of all compact subsets of $\mathbb{Q}$ is $\emptyset$.   I am trying to understand the first sentence. I read that a closed subspace of a compact space is compact, so for example, consider the unit interval $[0, 1]$ which is a compact space. Take a closed subspace $[0, 1] \cap \mathbb{Q}$ of $[0, 1]$. This set is closed since it just consists of all the rational numbers in between $0$ and $1$, including $0$ and $1$. So it is a closed subspace of a compact space. But why isn't this compact? Uniform continuity of $f(x)=x^{2/3}\log x$ on $[0, \infty)$ Let $f$ be a real valued function on $[0,\infty)$ defined by  $$f(x)= \begin{cases} x^{{2}/{3}}\log x &amp; \text{ if } x&gt;0 \\  0 &amp; \text{ if } x= 0 \end{cases}$$  Then which of the following is true?  A. $f$ is discontinuous at $x=0$.  B. $f$ is continuous on $[0,\infty)$, but not uniformly continuous on $[0,\infty)$.  C. $f$ is uniformly continuous on $[0,\infty)$.  D. $f$ is not uniformly continuous on $[0,\infty)$, but uniformly continuous on $[1,\infty)$.  I could see that $f(x)=x^{\frac{2}{3}}\log x$ is continous at $x=0$   But for uniform continuity I thought boundedness of derivative would help   But I found $f'(x)=\frac{2}{3}x^{-\frac{1}{3}}\log x + x^{-\frac{1}{3}}$   This $f'(x)$ is not bounded so i can not say any thing about uniform contunuity.  Please help me to clear this.   Thank you :)  P.S : This was already asked before ( some other person but it was not having enough details so it got closed. I tried to edit that question but someone said I should not edit OP to add more details. I was afraid that may be against the rules of MSE. So, I thought i should ask this separately with my own ideas.