Yesterday in my post about 55,
I repeated Wikipedia's claim that 55 is the largest number that is both
triangular and in the Fibonacci sequence. Chris Emerson commented to ask
for a proof. After a moment's thought, I realized I had no idea how to prove it.

My first impulse was to make two sets of the numbers in the sequences, and
intersect them, but building a very large set took too long. So instead
I wrote a function that took advantage of the ever-increasing nature of
the sequences to look for equal elements in two monotonic sequences:

And a function to cut off an infinite sequence once a certain ceiling had
been reached:

defupto(s,n):"""Stop a monotonic sequence once it gets to n."""foriins:ifi>n:returnyieldi

Now I could ask, what values less than quadrillion are in both the
triangular numbers and the Fibonacci sequence?:

>>>list(find_same(upto(fib(),1e15),upto(tri(),1e15)))[1,3,21,55]

This doesn't prove the claim for all numbers, but it shows that 55 is the
largest number under a quadrillion that is in both sequences.

Another way to do this is to take advantage of the asymmetry in growth rate.
The Fibonacci sequence up a quadrillion is only 72 elements. Make that a
set, then examine the triangular numbers up to quadrillion and keep the
ones that are in the Fibonacci set. And I'm certain there are other
techniques too.

I can't explain why, but composable generators please me. This was fun. :)