It's official, I am a grown up!
http://code.google.com/apis/inapppayments/articles/index.html
Friday, July 22, 2011
Monday, July 18, 2011
Continued fraction expansions of irrational square roots
I had no idea (until this Thursday, July 16) that I had never seen a proof of the fact that the continued fraction expansion of √D is periodic whenever D is not a perfect square. But have no fear, I found out about something called a reduced quadratic irrational and now have a proof. Here we go.
Definition: An irrational root α of a quadratic equation with integer coefficients is called reduced if α>1 and its conjugate ˜α satisfies −1<˜α<0. ◻
Solutions (since assumed real) of such quadratics can be written as α=√D+PQ
Definition: We say a reduced quadratic irrational α is associated to D if we can write α=P+√DQ
Lemma 1: Transforming a reduced irrational root α associated to D into its integer part and fractional part via α=⌊α⌋+1α′,
Proof: Letting α=√D+PQ
Thus α′ is both reduced and associated to D. ◻
Lemma 2: There are finitely many reduced quadratic irrationals associated to a fixed D.
Proof: As above write an arbitrary reduced irrational as α=√D+PQ. Since α>1 and ˜α>−1, we know α+˜α=2PQ>0 hence with the assumption Q>0 we have P>0. Since ˜α<0 we also have P<√D. Also, since α>1 by assumption we have Q<P+√D<2√D thus there are finitely many choices for both P and Q, forcing finitely many reduced quadratic irrationals associated to a fixed D (this amount is strictly bounded above by 2D). ◻
Claim: The continued fraction expansion of √D is periodic whenever D is not a perfect square.
Proof: We'll use Lemma 1 to establish a series of reduced quadratic irrationals associated to D and then use Lemma 2 to assert this series must repeat (hence be periodic) due to the finite number of such irrationals.
Write a0=⌊√D⌋ and √D=a0+1α0. From here, we will prove
Since 1α0 is the fractional part of the irrational √D, we have 0<1α0<1⇒α0>1.
Following the recurrence defined, since each αi is a reduced quadratic irrational, each ai≥1. Also, by Lemma 1, each αi+1 is reduced and associated to D since α0 is. By Lemma 2, we only have finitely many choices for these, hence there must be some smallest k for which αk=α0. Since αi+1 is determined completely by αi we will then have αk+j=αj for all j>0, hence the αi are periodic. Similarly, as the ai for i>0 are determined completely by αi−1, the ai must be periodic as well, forcing the continued fraction expansion √D=a0+1a1+1a2+⋱
Update: I posted this on
About Bossy Lobster
Definition: An irrational root α of a quadratic equation with integer coefficients is called reduced if α>1 and its conjugate ˜α satisfies −1<˜α<0. ◻
Solutions (since assumed real) of such quadratics can be written as α=√D+PQ
where D,P,Q∈Z and D,Q>0. It is also possible (though not required) to ensure that Q divides D−P2. This is actually a necessary assumption for some of the stuff I do, is mentioned here and generally frustrated the heck out of me, so that. As an example for some enlightenment, notice α=2+√74
is reduced but 4 does not divide 7−22. However, if we write this as 8+√11216, we have our desired condition.
Definition: We say a reduced quadratic irrational α is associated to D if we can write α=P+√DQ
and Q divides D−P2. ◻
Lemma 1: Transforming a reduced irrational root α associated to D into its integer part and fractional part via α=⌊α⌋+1α′,
the resulting quadratic irrational α′ is reduced and associated to D as well. (This is what one does during continued fraction expansion, and as I did with √2 during my last post.)
Proof: Letting α=√D+PQ
and X=⌊α⌋, we have 1α′=√D−(QX−P)Q.
- Since √D is irrational, we must have 1α′>0 and since 1α′ is the fractional part we know 0<1α′<1⇒α′>1.
- Transforming α′=Q√D−(QX−P)⋅√D+(QX−P)√D+(QX−P)=√D+(QX−P)1Q(D−(QX−P)2),we have P′=QX−P and Q′=1Q(D−(QX−P)2) and need to show Q′∈Z. But D−(QX−P)2≡D−P2modQ and since α is associated to D, Q must divide this quantity, hence Q′ is an integer.
- Since X=⌊√D+PQ⌋ is an integer and α is irrational, we know X<√D+PQ hence P′=QX−P<√D forcing ˜α′<0.
- Since α>1 we know X≥1⇔0≤X−1. Thus ˜α=P−√DQ<0≤X−1⇒Q<√D+(QX−P)⇒Q(√D−(QX−P))<D−(QX−P)2⇒−˜α′=√D−(QX−P)1Q(D−(QX−P)2)<1hence ˜α′>−1 and α′ is reduced.
- Since Q′=1Q(D−(P′)2), we know D−(P′)2≡QQ′≡0modQ′hence α′ is associated to D.
Thus α′ is both reduced and associated to D. ◻
Lemma 2: There are finitely many reduced quadratic irrationals associated to a fixed D.
Proof: As above write an arbitrary reduced irrational as α=√D+PQ. Since α>1 and ˜α>−1, we know α+˜α=2PQ>0 hence with the assumption Q>0 we have P>0. Since ˜α<0 we also have P<√D. Also, since α>1 by assumption we have Q<P+√D<2√D thus there are finitely many choices for both P and Q, forcing finitely many reduced quadratic irrationals associated to a fixed D (this amount is strictly bounded above by 2D). ◻
Claim: The continued fraction expansion of √D is periodic whenever D is not a perfect square.
Proof: We'll use Lemma 1 to establish a series of reduced quadratic irrationals associated to D and then use Lemma 2 to assert this series must repeat (hence be periodic) due to the finite number of such irrationals.
Write a0=⌊√D⌋ and √D=a0+1α0. From here, we will prove
- α0 is a reduced quadratic irrational associated to D.
- By defining ai+1=⌊αi⌋ and αi=ai+1+1αi+1, αi+1 is also a reduced quadratic irrational associated to D (assuming all α up until i are as well).
Since 1α0 is the fractional part of the irrational √D, we have 0<1α0<1⇒α0>1.
By simple algebra, we have α0=a0+√DD−a20,~α0=a0−√DD−a20.
Since a0 is the floor, we know a0−√D<0⇒~α0<0. Since D∈Z⇒√D>1 and √D>a0, we have 1<√D+a0⇒√D−a0<D−a20⇒a0−√D>−(D−a20)⇒~α0>−1.
Thus α0 is a reduced quadratic irrational. Since P0=a0 and Q0=D−a20=D−P20, Q0 clearly divides D−P20 so α0 is associated to D as well.
Following the recurrence defined, since each αi is a reduced quadratic irrational, each ai≥1. Also, by Lemma 1, each αi+1 is reduced and associated to D since α0 is. By Lemma 2, we only have finitely many choices for these, hence there must be some smallest k for which αk=α0. Since αi+1 is determined completely by αi we will then have αk+j=αj for all j>0, hence the αi are periodic. Similarly, as the ai for i>0 are determined completely by αi−1, the ai must be periodic as well, forcing the continued fraction expansion √D=a0+1a1+1a2+⋱
to be periodic.◻
Update: I posted this on

About Bossy Lobster
Labels:
Algebra,
Continued Fractions,
Math,
Quadratic Irrational,
Square Root
Sunday, July 10, 2011
Continued Fractions for the Greater Good part 1
OK, maybe not for the greater good, but still fun. This first post will be relatively short and sweet, intended to give an introduction for the posts that will follow.
Before the introduction, some motivation courtesy of Wikipedia:
The other motivation (the one I actually learned first in real life) for continued fractions comes from √2 being represented by an infinite continued fraction. (Instead of saying a probability of 0.01876, people would rather say a 1 in 53 chance.) So we try to write √2=1.41421356… as 1+12.414. But, instead, notice that √2=1+(√2−1)=1+1√2+1.
Define the nth convergent to be hnkn, so above we have h0=a0,k0=1 and h1=a0a1+1,k0=a1.
Claim: hn and kn satisfy hn=anhn−1+hn−2kn=ankn−1+kn−2
Proof: The fraction hnkn is converted into hn+1kn+1 simply by changing an to an+1an+1 in the final denominator. Since hnkn=anhn−1+hn−2ankn−1+kn−2
Thus hn+1 and kn+1 satisfy the same recurrence.
It remains to check the initial conditions work, but note h0=a0h−1+h−2=a0⋅1+0=a0k0=a0k−1+k−2=a0⋅0+1=1
Check out my next post, where I actually accomplish something with fractions (or at least prepare to accomplish something).About Bossy Lobster
Before the introduction, some motivation courtesy of Wikipedia:
“...decimal representation has some problems. One problem is that many rational numbers lack finite representations in this system. For example, the number 13 is represented by the infinite sequence (0,3,3,3,3,…). Another problem is that the constant 10 is an essentially arbitrary choice, and one which biases the resulting representation toward numbers that have some relation to the integer 10. For example, 1371600 has a finite decimal representation, while 13 does not, not because 1371600 is simpler than 13, but because 1600 happens to divide a power of 10 (106=1600×625). Continued fraction notation is a representation of the real numbers that avoids both these problems. Let us consider how we might describe a number like 41593, which is around 4.4624. This is approximately 4. Actually it is a little bit more than 4, about 4+12. But the 2 in the denominator is not correct; the correct denominator is a little bit more than 2 about 2+16, so 41593 is approximately 4+12+16.With this in mind, one can define an infinite continued fraction to be a0+1a1+1a2+⋱.But the 6 in the denominator is not correct; the correct denominator is a little bit more than 6, actually 6+17. So 41593 is actually 4+12+16+17.This is exact...”
With the denominators a0,a1,a2,…, we can define a recurrence for the finite approximations (convergents) of this value. For example, the zeroth is a0 and the first is a0+1a1=a0a1+1a1.
The other motivation (the one I actually learned first in real life) for continued fractions comes from √2 being represented by an infinite continued fraction. (Instead of saying a probability of 0.01876, people would rather say a 1 in 53 chance.) So we try to write √2=1.41421356… as 1+12.414. But, instead, notice that √2=1+(√2−1)=1+1√2+1.
Plugging this into itself, we have √2=1+11+1+1√2+1=1+11+1+11+1+1√2+1
and notice it can be represented by (1;2,2,2,…).
Define the nth convergent to be hnkn, so above we have h0=a0,k0=1 and h1=a0a1+1,k0=a1.
Claim: hn and kn satisfy hn=anhn−1+hn−2kn=ankn−1+kn−2
along with h−1=1,h−2=0 and k−1=0,k−2=1.
Proof: The fraction hnkn is converted into hn+1kn+1 simply by changing an to an+1an+1 in the final denominator. Since hnkn=anhn−1+hn−2ankn−1+kn−2
we similarly have hn+1kn+1=(an+1an+1)hn−1+hn−2(an+1an+1)kn−1+kn−2=an+1(anhn−1+hn−2)+hn−1an+1(ankn−1+kn−2)+kn−1=an+1hn+hn−1an+1kn+kn−1
Thus hn+1 and kn+1 satisfy the same recurrence.
It remains to check the initial conditions work, but note h0=a0h−1+h−2=a0⋅1+0=a0k0=a0k−1+k−2=a0⋅0+1=1
and h1=a1h0+h−1=a0a1+1k1=a1k0+k−1=a1⋅1+0=a1
as we checked above. ◻
Check out my next post, where I actually accomplish something with fractions (or at least prepare to accomplish something).
Sunday, July 3, 2011
Verifying 1and1 Site Ownership with Google Apps
Hello freens. I purchased bossylobster.com from 1&1 recently with the intent of hosting it on Google App Engine. I soon found out how delightful this process is. I made a 0.1 version for my site at bossylobster.appspot.com and decided to launch by clicking "Add Domain" in the "Application Settings".
After clicking this I was greeted with a note: "You must sign up for Google Apps to register this domain or prove that you already own it." Great, so now I had to sign up for Google Apps. (As a side note, at the time this seemed an unnecessary, annoying wrinkle to add my App, but I now realize the integration with GMail, Calendar, Docs, etc. is fantastic.)
So here is my ish: prove that you already own it.
Yesterday morning, I spent several hours trying to verify ownership of bossylobster.com (which I had purchased a week prior). While I realize the DNS propagation process takes some time, I didn't want to try one method, wait 24 hours and then realize at that point it hadn't worked.
So, Google Apps gives four options on how to verify:
Well, since I hadn't set my website up, the last three options were off limits to me (or so I thought). I had a bare minimum package from 1&1, so hosting was pretty much off limits. Apparently I picked one of the inept domain hosts because they don't support creation of a CNAME TXT record!! A quick Google search reveals "Yes, we do understand what an SPF record is. Unfortunately we do not support in on our hosting plans. We apologize for any inconvenience."
So here I am back to square one, just trying to prove I own something, an inherently basic task made incredibly frustrating. Hopefully I can help people avoid some frustration with the following instructions.
1. Open terminal and change into the directory with code for bossylobster (your site).
2. Create a Django project in that directory via the command
sudo django-admin.py startproject bossylobster_django.
(If you don't have Django or you are using Windows, read these install instructions, but DON'T SET UP A DATABASE, not necessary here. For a more detailed tutorial see this page. Also note, startproject is the function name in the django-admin module and bossylobster_django can be replaced with your project name.)
4. Change the file bossylobster_django/urls.py to:
6a. Determine your internal IP address for use in step 7
6b. Determine your router's (external) IP address for use in step 8
7. Set up a port forwarding rule in your router for port 80 (websites) with the IP address you found in 6a
8. (After logging in to 1&1) change IP for bossylobster.com to point to your router (from 6b)
9. From the bossylobster_django directory (or whatever you called it), run the server via
sudo python manage.py runserver 192.168.XX.YY:80
where 192.168.XX.YY is the IP you found in 6b.
10. Check to see if your change has propagated to DNS servers worldwide (wait until it has)
11. Upon propagation, login to Google Apps and verify via the meta tag
About Bossy Lobster
After clicking this I was greeted with a note: "You must sign up for Google Apps to register this domain or prove that you already own it." Great, so now I had to sign up for Google Apps. (As a side note, at the time this seemed an unnecessary, annoying wrinkle to add my App, but I now realize the integration with GMail, Calendar, Docs, etc. is fantastic.)
So here is my ish: prove that you already own it.
Yesterday morning, I spent several hours trying to verify ownership of bossylobster.com (which I had purchased a week prior). While I realize the DNS propagation process takes some time, I didn't want to try one method, wait 24 hours and then realize at that point it hadn't worked.
So, Google Apps gives four options on how to verify:
- Create a TXT record
- Upload an HTML file to a specific path on your site
- Add a <meta> tag to your home page
- Verify using your Google Analytics tracking code
Well, since I hadn't set my website up, the last three options were off limits to me (or so I thought). I had a bare minimum package from 1&1, so hosting was pretty much off limits. Apparently I picked one of the inept domain hosts because they don't support creation of a CNAME TXT record!! A quick Google search reveals "Yes, we do understand what an SPF record is. Unfortunately we do not support in on our hosting plans. We apologize for any inconvenience."
So here I am back to square one, just trying to prove I own something, an inherently basic task made incredibly frustrating. Hopefully I can help people avoid some frustration with the following instructions.
1. Open terminal and change into the directory with code for bossylobster (your site).
2. Create a Django project in that directory via the command
sudo django-admin.py startproject bossylobster_django.
(If you don't have Django or you are using Windows, read these install instructions, but DON'T SET UP A DATABASE, not necessary here. For a more detailed tutorial see this page. Also note, startproject is the function name in the django-admin module and bossylobster_django can be replaced with your project name.)
4. Change the file bossylobster_django/urls.py to:
from django.conf.urls.defaults import patterns from django.conf.urls.defaults import url urlpatterns = patterns('', url(r'^$', 'bossylobster_django.views.index', name='home'), )5. Change the file bossylobster_django/views.py to:
from django.http import HttpResponse def index(request): content = '\n'.join(['<html>', ' <head>', ' <meta name="google-site-verification" content="XXXX" />', ' </head>', ' <body>', ' Hello world!', ' </body>', ' </html>']) return HttpResponse(content)where XXXX should be replaced by the content value provided by Google.
6a. Determine your internal IP address for use in step 7
6b. Determine your router's (external) IP address for use in step 8
7. Set up a port forwarding rule in your router for port 80 (websites) with the IP address you found in 6a
8. (After logging in to 1&1) change IP for bossylobster.com to point to your router (from 6b)
9. From the bossylobster_django directory (or whatever you called it), run the server via
sudo python manage.py runserver 192.168.XX.YY:80
where 192.168.XX.YY is the IP you found in 6b.
10. Check to see if your change has propagated to DNS servers worldwide (wait until it has)
11. Upon propagation, login to Google Apps and verify via the meta tag
About Bossy Lobster
Friday, July 1, 2011
Getting Divvy-like functionality on Linux
I love my Divvy, as I'm sure many do, but it's not available for Linux. (I completely understand why it isn't, though the fact that they make Divvy a free demo with full functionality brings into question how much they are trying to monetize it.) Anyhow, not wanting to give away my left hand for a personal computer, I run Ubuntu on my home machine (but OS X at work, kind of funny).
In reality, all I really need from Divvy is the ability to do three things without the mouse that I normally couldn't do.
1. Maximize a window
2a. Make the window take the entire left half of the screen
2b. Make the window take the entire right half of the screen
That's all, I'm not asking for much.
=====================================================================
=====================================================================
=====================================================================
As a brief side not for those who don't know, with Divvy, I start with a window
In reality, all I really need from Divvy is the ability to do three things without the mouse that I normally couldn't do.
1. Maximize a window
2a. Make the window take the entire left half of the screen
2b. Make the window take the entire right half of the screen
That's all, I'm not asking for much.
=====================================================================
=====================================================================
=====================================================================
As a brief side not for those who don't know, with Divvy, I start with a window
and then call up Divvy with (a command I set globally) Ctrl-Z
and then once Divvy is up, I just hit the letter L (another command I made) and voila
my window is on the full left half of the screen.
=====================================================================
=====================================================================
=====================================================================
So, every other weekend for the last five months, I have tried to find a Divvy-like solution for Linux. I picked up and discarded Bluetile and PyWO along the way, the former because it is way too heavy a solution and the latter because it required the keypad, which my laptop keyboard does not have (of course I could've enabled NumLock to simulate the keypad, but that is too big a PITA).
Finally, last night I came to a solution that I want to share (in case anyone has gone through the pain I have). That solution is Compiz and here is how I did it:
1. Install Compiz from the command line via sudo apt-get install compizconfig-settings-manager
2. Install the extra plugins via sudo apt-get install compiz-fusion-plugins-extra
3. Open Compiz (ccsm from the command line) or
4. Go into the Window Management subsection
5. Enter Grid and set the "Put Left" and "Put Right" bindings to Alt-F8 and Alt-F9, while disabling everything else (my choice, doesn't have to be yours, if you have a Keypad on your keyboard and NumLock is not going to interfere with the letter 'm', then go for it)
(Also, another side note, if you are having trouble figuring out how to change the binding, just click the first box, the ones that say Disabled or whatever the current binding is and then "Grab Key Combination"
7. For maximize go to General Options
8. In the Key Bindings tab, make sure "Toggle Window Maximized" is set to it's default value of Alt-F10
(A little bit more about what you can do with Compiz:
Linux nerds watch Las Vegas, told you so Brent!)
About Bossy Lobster
So, every other weekend for the last five months, I have tried to find a Divvy-like solution for Linux. I picked up and discarded Bluetile and PyWO along the way, the former because it is way too heavy a solution and the latter because it required the keypad, which my laptop keyboard does not have (of course I could've enabled NumLock to simulate the keypad, but that is too big a PITA).
Finally, last night I came to a solution that I want to share (in case anyone has gone through the pain I have). That solution is Compiz and here is how I did it:
1. Install Compiz from the command line via sudo apt-get install compizconfig-settings-manager
2. Install the extra plugins via sudo apt-get install compiz-fusion-plugins-extra
3. Open Compiz (ccsm from the command line) or
4. Go into the Window Management subsection
5. Enter Grid and set the "Put Left" and "Put Right" bindings to Alt-F8 and Alt-F9, while disabling everything else (my choice, doesn't have to be yours, if you have a Keypad on your keyboard and NumLock is not going to interfere with the letter 'm', then go for it)
(Also, another side note, if you are having trouble figuring out how to change the binding, just click the first box, the ones that say Disabled or whatever the current binding is and then "Grab Key Combination"
to change the binding to your hearts content.)
7. For maximize go to General Options
8. In the Key Bindings tab, make sure "Toggle Window Maximized" is set to it's default value of Alt-F10
So with that, I my conditions satisfied: 1. via Alt-F10, 2a. via Alt-F8 and 2b. via Alt-F9. My search is over (for now...unless I make DivvyBuntu...)
Linux nerds watch Las Vegas, told you so Brent!)
Labels:
Compiz,
Divvy,
Linux,
Mac OS X,
Window Manager
Subscribe to:
Posts (Atom)