Wednesday, July 31, 2013

Dave Computes The Feinberg Formulas for Hold'Em Poker Starting Hands

Part 1:  Ranking Starting Hands

How can we memorize which Hold'em starting hands to play?  Our first problem lies in ranking all 169 possible starting hands.  I did this in an earlier post, and showed that the ranking depends quite a bit on how many players are in the hand.  In the chart below, you can see the ranking of starting hands for a heads-up game, a 3-player game (in which all 3 showdown every hand), etc.  My interpretation is that the 3Way column (for example) is appropriate for any game in which we expect 3 players to see the flop, regardless of how many people were dealt in and how many stay for the showdown.


The Avg column ranks hands using a weighted average of the value of that hand in different sized games, with 50% of the weight given to a hand's value in a 2-way flop, 25% in a 3-way flop, 12.5% in a 4-way flop, etc.  I think of it as a correction to the 2Way column, where hands that weaken with more players (like 77) are pushed down the list, while hands that become stronger with multiple players (like KJs) move up.

Our challenge now is to find a formula that helps us memorize the ranking of the most commonly played hands (especially the top third).  I considered more formulas than I care to admit.  I'll present the best two of these below.  Both are very faithful to my hand ranking.  The "Simple Feinberg Formula" boasts a very simple rule, but can be difficult to use in practice.  The "Easy Feinberg Formula" requires a small effort to memorize, but is extremely easy to apply.


Part 2:  The Simple Feinberg Formula
In this formula, A = 14, K = 13, Q = 12, J = 11, T = 10, 9 = 9, and so on.  We simply triple the high card, add the kicker, add 3 if suited, and add the number of possible straights (using both cards), as illustrated by the following examples.

KJ:  3 × 13 (high) + 11 (kicker) + 2 (straights) = 52
A7s:  3 × 14 (high) + 7 (kicker) + 3 (suited) = 52
K9s:  3 × 13 (high) + 9 (kicker) + 3 (suited) + 1 (straights) = 52
QTs:  3 × 12 (high) + 10 (kicker) + 3 (suited) + 3 (straights) = 52

These hands have the same score because they're about equally strong in my ranking.  For a pocket pair, triple the value and add 34.

66:  3 × 6 + 34 = 52

Let's see the results.


So, if in a certain preflop situation you felt you ought to raise 14% of the time, you could raise any hand with a score of 52 or higher.  (See my earlier post for a discussion of how often to raise preflop.)

This formula exactly reproduces the top 50 hands in my ranking.  (In fact, the formula makes only 4 "mistakes" in ranking the top 60 hands, which can be corrected by adding 1 point to the scores of 55, 44, JT, and T9s.)  The formula is granular enough that you can adjust your play to your exact position.

Ok, so the scores are rather high, which makes it difficult to perform the necessary mental math quickly.  But I claim it's easier than it looks.  In most situations, a quick estimate is enough to decide whether to enter a hand.  You probably already recognize premium hands like 99, AQs, and AK and trash hands (nearly anything with a high card below a jack), so you can skip the math on these.

I find the fastest way to perform the calculation is to start with the high card, then add 1 if it's suited, then triple this result, then add the kicker, and finally add the number of straights.  You'll quickly discover that the same numbers come up all the time:

AXs = (14 + 1) × 3 =  45
AXo = KXs = 14 × 3 = 42
KXo = QXs = 13 × 3 = 39
QXo = JXs = 12 × 3 = 36

Once you know these, the math gets much easier.  Another key is to stop calculating as soon as the score passes the desired threshold (or clearly won't get there).  This way you won't have to determine the number of possible straights often.

If you'd prefer to work with smaller numbers, you can reduce the card values without affecting relative card rankings.  For example, you might use A=4, K=3, Q=2, J=1, T=0, etc., for the high card (but this requires using negative numbers for hands like 98s).

The Simple Feinberg Formula distributes the top 50% of starting hands into more than 20 hand groups.  That sounds great, and it is if you can take advantage of this in your play.  But you might not want to memorize a different strategy for each group.  The solution is to bundle multiple scores into larger groups.

A simple approach is to round all scores to the nearest multiple of 3 (for example).  50, 51, and 52 would all round to 51, and would therefore all be played the same way.  The good news is that this means there's no need to triple in the first place.  We could simply add the kicker and number of straights, divide by 3 and round to the nearest integer, then add the high card and 1 more if suited.  Now the numbers are smaller, but they're not really any easier to compute.  The bad news is that there are good reasons for treating scores of 50, 51, and 52 differently.

A better solution is to group scores into more meaningful ranges.  Suppose you consider 41 to be a reasonable threshold for raising heads-up, 47 for raising on the button, and 50 for raising from the cut-off.  Now you've got a few hand groups:  the 40-and-less group, the 41-46 group, the 47-49 group, and the 50 group.  Of course, this approach would require memorizing the numbers 41, 47, and 50, along with how to play such hands.  There must be an easier way...


Part 3:  The Easy Feinberg Formula
Although many people treat all small pocket pairs (66 - 22) the same, we see from our hand ranking that there are surprisingly large differences between the values of these hands.


The Simple Feinberg Formula above asked us to triple pair values, triple high values, and add 3 for suited hands.  That leads us to the following key observation.  If K8 (a top 30% hand) is about as strong as 44, then A8 (like K8, but with a higher top card) and K8s (like K8, but suited) should be about as strong as 55 (the next pair up).  In practice, this trick works impressively well.  For that reason, the Easy Feinberg Formula groups hands into "plays like 55," "plays like 66," etc.  (The strange kicker values in the Easy Feinberg Formula have been determined empirically, with the goal of faithfully producing the above hand rankings.)

Rule #1:  The value of pocket pair XX is X.
 Examples:  The value of 66 is 6.  The value of KK is 13.
Rule #2:  High card values are 3 for Ax, 2 for Kx, and 1 for Qx.  All other high cards are worth 0. 

Rule #3:  Kicker values are:
5 for xK
4 for xQ, xJ, xT
3 for x9
2 for x8, x7
1 for x6, x5, x4, x3
0 for x2
Examples:
AK = 3 (Ax) + 5 (xK) = 8
A2 = 3 (Ax) + 0 (x2) = 3
Q8 = 1 (Qx) + 2 (x8) = 3
T9 = 0 (Tx) + 3 (x9) = 3
Rule #4:  Add 1 if suited.
KQs = 2 (Kx) + 4 (xQ) + 1 (suited) = 7
J3s = 0 (Jx) + 1 (x3) + 1 (suited) = 2
If you can will yourself to memorize the kicker values, the payoff is a formula that's easy to apply and gives the following results, which again are quite faithful to the hand ranking shown earlier.


So, if in a certain preflop situation you felt you ought to raise 15% of the time, you could raise any hand with a score of 6 or higher.  An easy (but simplistic) rule might be to play 3+ from the blinds (and heads-up), 4+ from the button, 5+ from 1-off-the-button, and 6+ from 2-off-the-button.  Note that it's roughly the case that raising your score threshold by 2 will halve your play frequency.  So, if you believe someone would raise with a score of 4+, you might reraise them with a score of 6+.

Tuesday, July 9, 2013

Dave Computes Poker Play Frequencies

A super-important problem in poker is determining whether your poker hand is likely to be the best at the table, without knowing what your opponents hold.  In this post, I'll assume that you know absolutely nothing about your opponents' hands, but you know the exact value of your own hand.

For example, suppose you're one of 3 players in a Hold'em poker game.  You expect to have the best hand about 33% of the time.  Suppose you hold K7o preflop and you're first to act (on the button).  Using the spreadsheet I made available in an earlier post, you see that only 32% of all possible hands are more likely to win than your K7o.  I'll therefore refer to K7o as a 32% hand.  Since this is less than 33%, you might assume you have a better-than-even chance of holding the best hand.  Are you correct?  No.  Let's see why.

There is a 68% chance (100% - 32%) that your K7o will beat any single opponent.  That means there's a 0.68 * 0.68 = 46% chance that your hand is better than both of your opponents', and a 54% chance that it isn't.  How strong must your hand be to have a 50% chance of beating both?

Let p be the probability that a single opponent's hand will beat yours.  (In the case of K7o, p = 0.32.)  Then the probability of beating a single opponent is (1 - p).  The probability of beating both opponents is (1 - p)2.  Now set this equal to 0.5 and solve for p.

(1 - p)2 = 0.5
p = 1 - (0.5)1/2 = 29.29%

What does that mean for our poker play?  It means we can't raise a K7o for value in this situation, because there's a 54% chance we're just giving that money away to an opponent.  Actually, the situation is not so straightforward.  If I'm on the button, I'll be last to act on all remaining rounds, giving me an edge that probably brings my chances of winning the hand closer to 50%.  (There are a lot of other subtleties to consider here, too.  If both opponents will call me down no matter what, then I have enough pot equity with my better-than-33% hand to raise for value.  However, in a 3-way hand, my K7o goes down in value and is now beaten by 36% of possible hands.)

So, it is reasonable to raise a top-29.29% hand for value in a 3-player game.  Solving
(1 - p)3 = 0.5, we find that it's reasonable to raise a top-20.63% for value in a 4-player game.  Note that this reasoning holds for any poker game.  But you can only apply it when you know the exact value of your hand, as you might in Hold'em preflop play.

Suppose we're on the button in a 4-player Hold'em game, and the first player folds.  Now we're effectively in a 3-player game, so we can raise a 29.29% hand for value.  This explains much of why your position changes the number of hands you can play.  (By the way, my math has convinced me that you should nearly always open with a raise in a game of hold'em.  I rarely open by calling.  When someone does limp ahead of me, I'm more likely to limp in with hands I might have opened with a raise.)

In general, in an n-player game, we can find this threshold by solving (1 - p)n - 1 = 0.5 for p.

p = 1 - 0.51/(n - 1)

Here's what we find.

Number Of PlayersThreshold
250.00%
329.29%
420.63%
515.91%

Now, suppose you're in a 5-player game of Hold'em.  The player under the gun opens with a raise (which we'll assume is not particularly monstrous).  The next player folds.  You're on the button.  You believe that raiser must have a top-15.91% hand.  You have ATo--a 9.5% hand with one opponent.  Do you reraise?  If we ignore the fact that you have position on the raiser, you should fold.  Why?  Because your opponent holds a 15.91% hand or better--anything from A8o to AA.  More than half of those hands are stronger than your ATo.  To raise, your hand must be in the top 15.91% / 2 = 7.96%.  So, you could raise a KQs (7.84%) or AJo (7.54%), but should fold ATo.

Now suppose you're the original raiser and the player on the button reraises you with what you assume to be a top-7.96% hand.  Using the same logic (and still ignoring position), you should reraise them back (potentially capping or putting yourself all-in at this point) with a top-3.98% hand (7.96% / 2) like 77 or AKs, but should probably call otherwise.

Number Of PlayersRaiseReraiseCap
250.00% (J5s)25.00% (QTo)12.50% (A7s)
329.29% (J9s)14.64% (QJs)7.32% (AQo)
420.63% (A3s)10.31% (A8s)5.16% (AJs)
515.91% (A8o)7.96% (KQs)3.98% (77)
612.94% (A9o)6.47% (ATs)3.24% (88)
710.91% (KTs)5.46% (AKo)2.73% (99)
89.43% (66)4.71% (AJs)2.36% (TT)
98.30% (A9s)4.15% (77)2.07% (JJ)
107.41% (AQo)3.71% (AKs)1.85% (JJ)

These playing frequencies turn out to be fairly close to those suggested by successful poker players.

Let's use this table to work through one more example.  If you're the first to act among 6 players, then you can raise your top-12.94% hands (ignoring position again), which would be A9o or better in a tight game.  If you're reraised, you can expect your opponent to hold a top-6.47% hand (ATs or better), and you can therefore raise them back with a top 3.24% hand (88 or better).  Note again that we're not taking position into account or, more importantly, the playing styles of your opponents.

Incidentally, if you look at preflop Hold'em play in this way, you're not stealing the blinds--you're raising for value.

All of this begs the question:  How can I determine the strength of my hole cards without constantly turning to a spreadsheet?  I'll address this in my next post.

Sunday, September 30, 2012

Dave Computes Solitaire Strategy

Having invested countless hours in playing Klondike Solitaire, I have decided to share my current wisdom on Solitaire strategy.  Note that I'm talking here about the version where 3 cards are dealt from the stock at once, which necessarily complicates the strategy.  I should also say that my goal in solitaire is to attain the highest winning percentage.  Many people will prefer winning the most games per unit time, or scoring the most points per win.  Any of these goals will lead to different strategies.  Anyway, here are the rules that guide my play.


Rule #1:  Prefer to expose face-down cards.

At the beginning of the game, there are 24 cards in the stock, 7 face-up cards on the table, and 21 face-down cards underneath them.  To win the game, I must eventually gain access to all cards.  Clearly, I already have access to the 7 face-up cards.  Of the 24 stock cards, one cycle through the deck immediately grants me access to 8 of them, and the remaining 16 are just a play or two away.  On the other hand, most of the 21 face-down cards are buried under 2 or more cards, and the deepest is buried under 6 cards.  So, not only should I make plays that reveal face-down cards, but I should strive to reveal cards from the piles with the most face-down cards.  At the start of the game, revealing just one face-down card from the rightmost pile gets me one play closer to revealing each of the 5 cards below it.

Therefore, I will generally make all the plays I can with the table cards (first moving the cards from piles with the most face-down cards) before dealing further from the stock.


Rule #2:  Never empty a pile unless there is a king immediately available.

This rule is fairly straightforward.  There is absolutely no advantage to emptying out a pile unless you have a king handy.  Any move that would have left a pile empty has the potential to block a future play that may arise before a king comes up.


Rule #3:  Usually play the last playable card in the stock.

Let's number the cards in the stock from 1 to 24.  As I cycle through the stock, I first see card #3, then #6, #9, #12, #15, #18, #21, and #24.  Suppose I can play card #6 and #12.  Which should I play first?  Most people would play card #6 before they even discover card #12.  I'm convinced that's not a winning strategy.  Here's why.  If I play #6 and then #12, then on the next deal I'll have access to 6 new cards (#7, #10, #14, #17, #20, and #23).  If I instead play only #12, the next deal will give me access to #13, #16, #19, and #22, and if I now play #6 (which is still available to me), the deal after that will expose #7, #10, #14, #17, #20, and #23--a total of 10 new cards!

Therefore, I will always cycle through the entire stock once before choosing which card to play--usually the last playable card.  Yes, it takes longer to play this way.  No, it doesn't bother me.

Exception To Rule #3:
The exception to this rule is when playing a later card in the stock will prevent me from being able to play an earlier card.  For example, if both the 4-of-diamonds and the 4-of-hearts are accessible to me, but I can only play one red 4, then I should play the earlier four so as to expose more new cards on the next deal.  Here's another example where this comes up.  I have a 4-of-hearts exposed, and a 3-of-spades sitting on the table.  I can move the 3 onto the 4, in order to play a king from the stock, or I can put a 3-of-clubs from the stock onto the 4.  I can't make both plays, so I should play whichever appears earlier in the stock.  This kind of situation arises quite frequently, and if misplayed, can easily turn a winning game into a losing one.  Also, bear in mind that the two playable (but mutually exclusive) cards may be separated and/or followed by other playable cards which should be played first.  And sometimes playing a stock card may reveal a new playable card that should be ignored if it would prevent me from playing a card I saw earlier in the stock.


Rule #4:  Never play more than 3 cards from the stock on a single deal.

On a particular deal, once I've played a third card from the stock, all remaining accessible cards will continue to be accessible on the next deal.  By ignoring these remaining cards until the next deal, I may discover newly accessible cards that should be played first.


Rule #5:  Don't move any card to the foundations if it could still prove useful on the table.

For example, I shouldn't move the 3-of-spades onto the spades foundation if there's still a chance that I'll need it to support a red 2.  Of course, if both red aces have already come up, or if the ace-of-hearts has come up and the 2-of-diamonds is already supported by the 3-of-clubs, then it's safe to move the 3-of-spades to the foundation.  But I shouldn't be in a rush to move cards to the foundations.  I am certain that people who always move cards onto foundations are not playing optimally.  And yes, this means I always disable any auto-move feature on my Solitaire software.


Saturday, September 15, 2012

Dave Computes Interest Payments

We're usually taught two ways to calculate interest payments--simple and compound.  The truth is there's only one way to calculate interest and several models for paying back a loan.

The Basics

Whenever I borrow anything, the lender and I must agree on how much rent I need to pay, and how often I need to pay it.  Borrowing money is no different.  The money I borrow at the beginning of a loan is called the principal, and the rent I pay for borrowing it is called interest.  Unlike rents on other items, the interest I pay when I borrow money is not a fixed amount.  Rather it's (usually) a fixed interest rate--a percentage that tells me how much of the amount borrowed I need to pay in rent.  For example, I might borrow $500 and agree to pay 2% of the borrowed amount every month.  Then, after the first month, I would owe 2% × $500 = $10 in interest.  (Recall that 2% = 0.02.)

Note:  The 2% interest rate in my example is what I call the periodic interest rate--the percent charged every period when interest is collected/assessed.  By convention, we usually speak in terms of annual interest rates--the percent due each year.  Therefore, the first step of any interest calculation is usually to convert an annual interest rate into the more useful periodic interest rate.  In my example, the annual interest is 24%, the period is 1 month, and therefore the periodic interest rate I need for my calculations is 24% ÷ 12 = 2%.

The One Law Of Interest Payments

Every period, the borrower is charged an amount of interest equal to the periodic interest rate (r) multiplied by the borrowed amount (b).
Initially, the borrowed amount b is simply the principal (the amount of money initially borrowed).  Surprisingly, this is the only law you ever need to calculate interest payments.

Let's return to the example where I borrow $500 and I'm charged 2% interest each month.  We already determined (using The One Law Of Interest Payments) that I owe 2% × $500 = $10 in interest for the first month.  But suppose I pay only $7.  Since I owed $10 but paid only $7, I've effectively borrowed another $3.  Now I've borrowed a total of $503, so The One Law Of Interest Payments tells me that next month I'll owe 2% × $503 = $10.06 in interest.  The extra 6 cents is really interest on the interest I didn't pay.  Now, $7 is an unusual payment, so let's look at some more common payment plans.

Payment Plan #1:  Simple Interest

In this plan, I pay the full amount of interest every period, and at the end of the loan I also pay back the principal in full.  Again, suppose I've borrowed $500, and I'm charged 2% interest each month, which works out to be $10.  In this plan, I pay exactly $10.  The next month, since I've still borrowed $500, I again owe $10.  By paying the full interest every month, the amount I've borrowed doesn't change, which keeps the math simple.  At the end of the loan, I pay back the $500.  If the loan lasts for 1 year, then I've paid 12 × $10 = $120 in interest.  In general, I'll pay a total of t × r × p in interest, where t is the number of periods in the loan, r is the periodic interest rate, and p is the principal.

Payment Plan #2:  Compound Interest

In this plan, I'm charged interest each period (as always) but I don't pay any of it.  At the end of the loan, I pay back the principal in full, along with all the accumulated interest.  So, this time when I'm charged $10 interest on my $500 loan, I pay $0.  That means I've effectively borrowed an additional $10, so I've now borrowed a total of $510.  Next month, The One Law Of Interest Payments tells me I'll owe 2% × $510 = $10.20 in interest.  Again, I pay $0, so I've now borrowed $510 + $10.20 = $520.20, and next month I'll be charged 2% × $520.20 = $10.404, and again I'll pay $0, and so on.  But how much will I have to pay back at the end of the loan?

Originally, I borrowed $500.
After 1 period, I've borrowed $500 + 0.02 × $500 = $500 × 1.02.
After 2 periods, I've borrowed ($500 × 1.02) × 1.02 = $500 × (1.02)2.
After 3 periods, I've borrowed $500 × (1.02)3.

Each period, the amount I owe multiplies by 1.02 (and is therefore growing exponentially).  At the end of 1 year, I'll owe $500 × (1.02)12 = $634.12, where $134.12 of that is interest ($14.12 more than I paid using the simple interest payment plan.)

In general, after t periods, I'll owe a total of p(1 + r)t.

With compound interest, my debt can accumulate quite quickly.  If I borrow that $500 for 10 years, then the simple interest payment plan would cost me $1,200 in interest, while the compound interest payment plan would cost me $4882.58 in interest.  That's why people talk of "the power of compound interest."

Payment Plan #3:  Overpaying

Suppose I need $100,000 to buy a house.  A loan to buy a house is called a mortgage, but it's essentially like any other loan.  My bank would be crazy to lend me that money using a simple or compound interest payment plan.  Let's see why.

Suppose the bank offers to loan me the money for 30 years at 6% interest, and interest is assessed every month.  That makes the periodic interest rate r = 6% ÷ 12 = 0.5% (or 0.005). 

I would owe 0.5% × $100,000 = $500 in interest for the first month.  If I pay exactly $500 each month, I end up with a simple interest plan, in which I still owe $100,000 at the end of the loan.  If I pay less than $500 each month, I'll owe even more at the end of the loan (the principal plus accumulated interest).  In the most extreme case, I pay $0 each month, resulting in a compound interest plan in which I owe over $600,000 at the end of the loan.  The bank is never going to trust me to be able to make a single large payment of $100,000 or $600,000 at the end of the loan. 

To reduce the amount I'll owe at the end of the loan, my monthly payment will need to be more than $500.  That way, every month I'll pay off all of the interest and some of the principal.

Suppose I pay $550 each month.  Again, The One Law Of Interest Payments guides us.  After one month, I owe $500 in interest, but I pay $550, which covers all of the interest and also pays off $50 of the loan (the principal).  That means I've effectively borrowed $50 less, so I've now borrowed "only" $99,950.  Since I've borrowed less, I'll now be charged less interest next month:  0.5% × $99,950 = $499.75.  Again, I pay $550, which now pays off all of the interest plus $50.25 of the principal.  The interest calculations for the first 3 months of this loan are summarized in the following table.


Month
Borrowed
Interest
Principal Paid Off
1
$100,000
0.5% × $100,000
= $500
$550 - $500
= $50
2
$100,000 - $50
= $99,950
0.5% × $99,950
= $499.75
$550 - $499.75
= $50.25
3
$99,950 - $50.25
= $99,899.75
0.5% × $99,899.75
= $499.49875
$550 - $499.49875
= $50.50125

Notice that each month, I've borrowed less, so I owe less interest, so I pay off more of the principal, so I've borrowed even less, and so on.  OK, so how much will I owe at the end of 30 years?  To answer that, we'll derive the general formula for interest payments.

The General Formula

So far, we've seen three payment plans, and in each one, my regular payment x is a constant.  These plans are summarized in the following table.


Payment Plan
Regular Payment
Simple Interest
x = pr
Compound Interest
x = 0
Overpaying
x > pr

Clearly, the more I pay during the loan (larger x), the less I'll owe at the end of the loan.  In this section, we'll derive a general formula for how much I owe at the end of the loan, as a function of x (and p,  r, and t).

Initially, I borrow p.  After one period, The One Law Of Interest Payments tells me I'll owe a total of p(1 + r), which includes both the amount I borrowed (p) and one period of interest (pr).  I make a payment of x, which means now I've only borrowed p(1 + r) - x.  Notice that we multiplied the amount borrowed by (1 + r) and then subtracted x.  This same process will repeat every period, so after my next payment, I will multiply p(1 + r) - x itself by (1 + r) and then subtract x, resulting in the following pattern:

Originally, I borrowed p.
After 1 period, I've borrowed p(1 + r) - x.
After 2 periods, I've borrowed p(1 + r)2 - x(1 + r) - x.
After 3 periods, I've borrowed p(1 + r)3 - x(1 + r)2 - x(1 + r) - x.
After t periods, I've borrowed p(1 + r)t - x(1 + r)t-1 - x(1 + r)t-2 ... - x(1 + r) - x

Recognizing that (1 + r)t-1 + (1 + r)t-2 ... + (1 + r) + 1 is a geometric series whose sum is
[(1 + r)t- 1] ÷ r, our formula simplifies to

p(1 + r)t - x[(1 + r)t - 1] ÷ r

which tells me how much I owe after borrowing p at a periodic interest rate of r, and making payments of x for t periods.  This is The General Formula.

Using The General Formula


If this formula is really so general, we should be able to use it to calculate both simple and compound interest, and indeed we can.

In a compound interest payment plan, x = 0 (since I don't pay interest until the end of the loan).  Plugging x = 0 into the general formula, the ugly righthand term immediately disappears, and we are left with p(1 + r)t, which we recognize as the formula for compound interest.

In a simple interest payment plan, x = pr (since I pay off the interest each period).  When we plug x = pr into the general formula, most of the formula cancels out, and we're left with just p.  And this makes perfect sense, because no matter how long I borrow for, I've always paid off all interest, and I therefore only owe the principal p at the end of the loan.

In my mortgage example, p = $100,000, r = 0.005, t = 360 (the number of months in 30 years), and x = $550.  Plugging these values into the formula, I get

($100,000)(1.005)360 - ($550)[(1.005)360 - 1] ÷ 0.005 = $49,774.25

I still owe almost $50,000 at the end of the loan.  Apparently, I should have made higher monthly payments.  But how high?

Payment Plan #3 (Revised):  Overpaying (to pay off the principal exactly)

I want to determine the regular payment x that will completely pay off the full loan (principal and interest) in exactly 30 years.  In this plan, at the end of the loan, I will owe $0, meaning that the general formula had better give me $0.

p(1 + r)t - x[(1 + r)t - 1] ÷ r = 0


By solving this equation for x, we can determine the correct monthly payment:

x = pr(1 + r)t ÷ [(1 + r)t - 1]

This is the mortgage payment formula you'll find elsewhere (in some equivalent form).

In my mortgage example, p = $100,000, r = 0.005, and t = 360.  Plugging these values into the formula, I get

x = ($100,000)(0.005)(1.005)360 ÷ [(1.005)360 - 1] = $599.55

Therefore, if the bank offers me a 30-year loan of $100,000 with a fixed (annual) interest rate of 6%, my monthly mortgage payment will be $599.55.  After 360 payments of $599.55, I will have paid off the loan in full, having paid a total of $215,838 for the privilege of borrowing $100,000 for 30 years.  But, of course, now we know there's nothing arbitrary about that $215,838.  It's the logical consequence of applying The One Law Of Interest Payments.

Friday, September 14, 2012

Dave Computes A Very Tiny Interpreter

Several years ago I designed a simple 4-bit computer processor that my students could build from TTL chips and wire. I called the processor the CHUMP (Cheap Homebrew Understandable Minimal Processor), and I called the corresponding programming language Chumpanese (which we imagine is not constrained by 4-bit addresses).  You can read an early draft of the paper I wrote on it here.

Anyway, I was playing around with a well-known OISC (one instruction set computer) language tonight, in which the only instruction is:

subeq a, b, c

This instruction behaves as follows:

mem[a] = mem[a] - mem[b];
if (mem[a] == 0)
  pc = mem[c];
else
  pc++;

(subleq is the more popular version, which branches when mem[a]<=0.)

It occurred to me tonight that I could easily write an interpreter for this OISC in Chumpanese.  I used one address for the program counter.  pc would contain a, pc+1 would contain b, pc+2 would contain c, and pc+3 would be the beginning of the next instruction.  Here is the very tiny OISC interpreter I wrote in Chumpanese:

fetch: read pc load it add 1 storeto b       // b = mem[pc + 1]
       read pc read it load it               // mem[a] (a=mem[pc])
       read b read it sub it                 // mem[a] - mem[b]
       read pc read it storeto it            // store in mem[a]
       ifzero jump                           // if (mem[a] == 0)
       read pc load it add 3 goto end        // pc + 3 (next inst)
jump:  read pc load it add 2 storeto c       // c = pc + 2
       read c read it load it                // mem[c]
end:   storeto pc goto fetch                 // set pc and repeat

Yes, my students found Chumpanese awfully confusing, too, even though they knew exactly what voltages would change in response to each instruction.

Thursday, September 6, 2012

Dave Computes Complex Roots, Poetically


There is a nerdy poem about the square root of three that Kal Penn recites in the movie Harold & Kumar Escape from Guantanamo Bay.  Here is the parody I wrote when I was teaching complex roots in my precalculus course last year.

The Cube Root Of Three

I take the cake, you must agree,
for I'm a cube root of a three!
There must be three of me to make
a product you cannot mistake.
You think I'm one point four four two?
Well I've got something more for you!
Take half of that and multiply
by minus one plus root three i.
Did I say i? I can't be real.
You can't imagine how I feel.
You cannot see how it can be
That three of me can make a three?
Just FOIL me with me and then
that conjugates with me again.
Do you feel foolish next to me?
Confused by my complexity?
My formula you can derive
in Precalc section six point five.

Wednesday, September 5, 2012

Dave Computes Hold'em Poker Starting Hands

Over the past few years, I've put far too much energy into Hold'em Poker computations.  Possibly the most useful thing I've done in this regard is simply to put together what I hope is the definitive source of starting hand data.  I wrote a Java program that simulated 10 million rounds of heads-up play, in which both players see the showdown.  (This would have been impossible without stumbling onto Kevin Suffecool's super-fast Poker Hand Evaluator, which I then ported to Java for convenience.)  I found, for example, that AA had the highest winning percentage of 85% and 32o had the lowest winning percentage of 32%.  I then simulated 10 million 3-player games, in which all 3 players saw the showdown.  This time AA won 73% of its games and 32o won 20%.  I then simulated 10 million 4-player games, then 5-player games, and so on, up to 10 players.  All of this data is available in a spreadsheet.

One obvious observation we can make from this data is that the relative value of a starting hand depends on the number of players.  This phenomenon is easy to explain:

1.  It takes a stronger hand to beat more opponents.
2.  Some hole cards are better at making strong hands (straights and flushes) but are worthless when they miss the board entirely.  Other hole cards will consistently make medium-strength hands (pairs and high cards) but will rarely make strong ones.

Rather than looking at how often a particular starting hand wins, I found it more useful to ask the question:  If I decided to play, say, 20% of the starting hands dealt to me, which 20% should I play? Heads-up, that would mean playing any hand A3s-or-better, and folding any hand K9o-or-worse.  I therefore call A3s a top-20% hand, because it is the least-winning hand of the top 20% of hands dealt in heads-up play.  (These percentages also appear in the spreadsheet)  This way of describing a starting hand makes it easy to analyze how the value of a hand depends on the number of players in the game.  For example, the following table follows the changing values of 3 particularly volatile hands.



77
A9o
JTs
2 players
top 4%
top 13%
top 24%
3 players
top 7%
top 16%
top 15%
4 players
top 10%
top 19%
top 11%
5 players
top 14%
top 20%
top 10%
7 players
top 19%
top 23%
top 8%
10 players
top 15%
top 32%
top 6%