13
3
The Dottie number is the fixed point of the cosine function, or the solution to the equation cos(x)=x.1
Your task will be to make code that approximates this constant. Your code should represent a function that takes an integer as input and outputs a real number. The limit of your function as the input grows should be the Dottie number.
You may output as a fraction, a decimal, or an algebraic representation of a number. Your output should be capable of being arbitrarily precise, floats and doubles are not sufficient for this challenge. If your language is not capable of arbitrary precision numbers, then you must either implement them or choose a new language.
This is a code-golf question so answers will be scored in bytes, with fewer bytes being better.
Tips
One way of calculating the constant is to take any number and repeatedly apply the cosine to it. As the number of applications tends towards infinity the result tends towards the fixed point of cosine.
Here is a fairly accurate approximation of the number.
0.739085133215161
1: Here we will take cosine in radians
So, if we are using Python, we must implement our own type or import
Decimal
? – Mr. Xcoder – 2017-08-04T15:28:56.867How accurate must our submissions be? – Mr. Xcoder – 2017-08-04T15:30:34.223
Goes to Jelly tutorial to steal
ÆẠȷ¡
realizes it's invalid. Tries Brachylog; oh no Brachylog doesn't even do floats. – Erik the Outgolfer – 2017-08-04T15:30:38.463@Mr.Xcoder They must only be asymptotically accurate. – Post Rock Garf Hunter – 2017-08-04T15:31:00.190
I feel like the "arbitrarily precise" requirement is a bit too stringent. Why not consider an answer valid once
x=cos(x)
? – kamoroso94 – 2017-08-04T16:58:35.790@kamoroso94 Because then answers can output the value without calculation. The arbitrarily precise requirement requires that answers actually be calculated as opposed to simply stored in the source. – Post Rock Garf Hunter – 2017-08-04T17:26:52.040
Ah I see, that is quite an unfortunate loophole. Thanks for explaining. – kamoroso94 – 2017-08-04T19:06:09.687
Possible duplicate of Approximate the plastic number (instead of x^3-1=x we have cos(x)=x)
– Sanchises – 2017-08-04T21:17:43.383@Sanchises I don't believe this is a duplicate. In some languages, those with equation solvers, the two tasks are very similar. However the majority of languages don't have these. The most common algorithm for solving here simply doesn't work on the other question. – Post Rock Garf Hunter – 2017-08-04T21:44:56.857
For a computer "arbitrary precise" is it too much, because each number use memory, and memory is limited. Perhaps better "arbitrary precise until one upper bound", for example digits until 10^4 or until memory of PC allow that calculation – RosLuP – 2017-08-05T08:45:27.010
1I would like to see this in Haskell, APL, and some Lisp flavor. – Mark C – 2017-10-25T08:50:55.407