wu :: forums
« wu :: forums - Mysterious Function »

Welcome, Guest. Please Login or Register.
May 19th, 2024, 7:08am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Grimbal, ThudnBlunder, Icarus, SMQ, william wu, towr, Eigenray)
   Mysterious Function
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Mysterious Function  (Read 1336 times)
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Mysterious Function  
« on: Feb 27th, 2004, 7:45am »
Quote Quote Modify Modify

What does the following function do?
 
Code:
M(a, b)
{
  eps = 0.00001;
  p = max(a, b);
  q = min(a, b);
 
  while (q > eps) {
     r = (q*q)/(p*p);
     s = r/(r+4);
     p = (2*s + 1)*p;
     q = s*q;
  }
 
  return p;
}

 
Note: you need to prove your answer - simulation is not enough!
« Last Edit: Feb 28th, 2004, 2:48am by Barukh » IP Logged
Eigenray
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 1948
Re: Mysterious Function  
« Reply #1 on: Feb 27th, 2004, 9:49am »
Quote Quote Modify Modify

M(1,1) looks suspiciously familiar, so compute a table of M(a,b)2.  Then it's clear that M(a,b)2 = a2 + b2.
::Initially, {p,q} = {a,b}, and in the limit as eps goes to 0, the loop terminates at {p,q} = {0, sqrt(a2+b2)}, so it's reasonable to suggest that at all points, p2+q2 = a2+b2 = C.  Let's prove this.  After one iteration, p,q take on the new values:
p' := p(3q2+4p2)/(q2+4p2) > p,
q' := q3/(q2+4p2) < q,
and doing the algebra, p'2 + q'2 = p2 + q2, so this quantity never changes, and is always C.
Therefore, when the loop terminates and q < eps, we must have p > sqrt(C-eps).
To see that the loop does terminate, we may write
q' = f(q) = q3/(4C - 3q2), and since q is strictly decreasing and bounded below by 0, it must converge to some limit less than q0 = min(a,b).  But the only fixed points of f(q) are q=0 and q = sqrt(C) >= max(a,b).  Therefore q converges to 0, and p converges to sqrt(C)
.
IP Logged
John_Gaughan
Uberpuzzler
*****



Behold, the power of cheese!

5187759 5187759   john23874   SnowmanJTG
WWW Email

Gender: male
Posts: 767
Re: Mysterious Function  
« Reply #2 on: Feb 27th, 2004, 8:40pm »
Quote Quote Modify Modify

What is "eps"?
IP Logged

x = (0x2B | ~0x2B)
x == the_question
Barukh
Uberpuzzler
*****






   


Gender: male
Posts: 2276
Re: Mysterious Function  
« Reply #3 on: Feb 28th, 2004, 2:50am »
Quote Quote Modify Modify

on Feb 27th, 2004, 8:40pm, John_Gaughan wrote:
What is "eps"?

It's a very small number. I modified the code to reflect this.
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board