Friday, September 08, 2006

Closed-form heel formula

In my notes on modifying the heel from my Widdershins pattern, I gave a recursive formula to determine the number of stitches needed for the heel flap. In the comments on that entry, Carol posted a closed form:
Embarrassingly, I had to ask my son, who's studying math at university what k was. He told me to think about it. It finally clicked.
I still couldn't figure out how to program the formula but did get it into closed form.
I think it reduces to
h(n) = n – 2 – 2 * int(n/9),
where int(n/9) stands for the integer part of n/9.
btw. I really like the heel.
Of course, I had to try this out. Being a bit to lazy to do a real proof, I just coded it up quickly and compared the two functions for values up to 150. If anyone is planning on knitting a sock over 300 stitches around, I could go higher.
>>> def h1(n):
... def h(k):
... if k < n/3:
... return k
... else:
... return 4 + h(k-6)
... return h(n)
>>> h1(33)
>>> def h2(n): return n-2-2*(n/9)
>>> h2(33)
>>> for i in range(150):
... val1 = h1(i)
... val2 = h2(i)
... if val1 != val2:
... print i, val1, val2
8 4 6
17 11 13
26 18 20
35 25 27
44 32 34
53 39 41
62 46 48
71 53 55
80 60 62
89 67 69
98 74 76
107 81 83
116 88 90
125 95 97
134 102 104
143 109 111
For some numbers, my formula suggests one more pair of turning rows than Carol's formula, but given that my original n/3 came from me thinking, "Oh,one-third of the stitches in the center sounds reasonable." I don't think it'll make too much difference unless you are really picky about how pointy you like your sock heels. Thank you, Carol! I was feeling a bit guilty about not providing a closed form, but the guilt didn't motivate me quite enough to get out my college textbooks and remember how to solve it myself. Now I don't have to!
Categories: , , ,


curlypurly said...
This comment has been removed by a blog administrator.
Liz said...

Hi! I just finished the foot on my first ever toe-up sock, using the Widdershins pattern. It's genius! Thanks for writing such a kickass pattern.

My sock has 56 sts, but I really felt like winging it so I was just like "meh... i think I will start the wraps... here!" very unscientific but with just two stitches difference it works fine.

I'll post some WIP pics to my blog in the next few days, hopefully.

Liz said...

It's up there!

Knitty Cat said...

so, um, I don't get it. My sock is 64 stiches around (do you have realy small feet or something? Mine are on the small side of average, and 54 is too small for me) so what do I do?

Natalie said...

i am absolutely in love with the idea of a toe up sock pattern with a flap heel. absolutely genius, your pattern. however, i would much appreciate an idiots guide to helping us brain twisting impaired folk for determining gusset increases. i dont know if im having some brain block or something, but i cannot seem to struggle through modifying the pattern for different numbers of stitches. i have 68 stitch socks, and cannot seem to get the numbers to work out.