Shirley: Difference between revisions

Jump to navigation Jump to search
81 bytes added ,  22:16, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 3: Line 3:
Polivka observed that since the pupils were writing [[wikipedia:binary code|binary code]] with a handful of [[wikipedia:Hardware register|register]]s and only 1 Kb of memory, this was quite a stiff problem to encounter on your first course.
Polivka observed that since the pupils were writing [[wikipedia:binary code|binary code]] with a handful of [[wikipedia:Hardware register|register]]s and only 1 Kb of memory, this was quite a stiff problem to encounter on your first course.


The webinar participants discussed this for quite a while at the end of which Curtis Jones said [[Adám Brudzewsky]]'s approach was a good example of APL as a [https://www.jsoftware.com/papers/tot.htm tool of thought]. Ellis Morgan commented that the problem is effectively a [[sum]] of a [[wikipedia:geometric series|geometric series]] here. The function <syntaxhighlight lang=apl inline>Shirley</source> is a [[traditional function]] which one might have [[APL\360|written in 1970]] (except for the [[Mix]] in the definition of <syntaxhighlight lang=apl inline>wt</source>):
The webinar participants discussed this for quite a while at the end of which Curtis Jones said [[Adám Brudzewsky]]'s approach was a good example of APL as a [https://www.jsoftware.com/papers/tot.htm tool of thought]. Ellis Morgan commented that the problem is effectively a [[sum]] of a [[wikipedia:geometric series|geometric series]] here. The function <syntaxhighlight lang=apl inline>Shirley</syntaxhighlight> is a [[traditional function]] which one might have [[APL\360|written in 1970]] (except for the [[Mix]] in the definition of <syntaxhighlight lang=apl inline>wt</syntaxhighlight>):


<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
Line 17: Line 17:
  ⍝ wt=sum of (birth, first 20 weeks growth, the next complete months, the last month part)
  ⍝ wt=sum of (birth, first 20 weeks growth, the next complete months, the last month part)
  wt←+⌿a⍪↑(k×5⌊m)(k×b×(n×b=1)+(1-r)÷(b=1)+1-b)(b×r×(m>5)×k×m-c)
  wt←+⌿a⍪↑(k×5⌊m)(k×b×(n×b=1)+(1-r)÷(b=1)+1-b)(b×r×(m>5)×k×m-c)
</source>
</syntaxhighlight>
   
   
Starting with a birth weight of 100 ounces (six pounds four ounces), using a decay factor of 0.9 (meaning that growth in this month is 0.9 times the growth in last month) and using UK Imperial tons<ref>In UK Imperial units, an ounce is 16 drams, a pound is 16 ounces, a stone is 14 pounds, a hundredweight is 8 stone, and a ton is 20 hundredweights. A UK ton is the "long ton" of 2240 pounds (2240=20×8×14). A US "ton" is a "short ton" of 2000 pounds. The metric "ton" (or "tonne") has 2204.6226 pounds, it being 1000 kilograms.</ref> we get this answer:
Starting with a birth weight of 100 ounces (six pounds four ounces), using a decay factor of 0.9 (meaning that growth in this month is 0.9 times the growth in last month) and using UK Imperial tons<ref>In UK Imperial units, an ounce is 16 drams, a pound is 16 ounces, a stone is 14 pounds, a hundredweight is 8 stone, and a ton is 20 hundredweights. A UK ton is the "long ton" of 2240 pounds (2240=20×8×14). A US "ton" is a "short ton" of 2000 pounds. The metric "ton" (or "tonne") has 2204.6226 pounds, it being 1000 kilograms.</ref> we get this answer:
Line 25: Line 25:
       ⌊0.5+((100÷16×2240) 0.9) Shirley 16 52    ⍝ calculate Shirley's weight in ounces  
       ⌊0.5+((100÷16×2240) 0.9) Shirley 16 52    ⍝ calculate Shirley's weight in ounces  
228 424
228 424
</source>
</syntaxhighlight>


For the <syntaxhighlight lang=apl inline>n</source> complete months after month 5 the total weight increase is <syntaxhighlight lang=apl inline>k×+/b*⍳n</source> which we know is <syntaxhighlight lang=apl inline>k×b×(1-b*n)÷1-b</source> ([[wikipedia:Geometric_series#Sum|sum of a geometric series]]).
For the <syntaxhighlight lang=apl inline>n</syntaxhighlight> complete months after month 5 the total weight increase is <syntaxhighlight lang=apl inline>k×+/b*⍳n</syntaxhighlight> which we know is <syntaxhighlight lang=apl inline>k×b×(1-b*n)÷1-b</syntaxhighlight> ([[wikipedia:Geometric_series#Sum|sum of a geometric series]]).


Even if Shirley lives to be 100, applying <syntaxhighlight lang=apl inline>+/</source> over all the weeks is unlikely to cause any problematic performance.
Even if Shirley lives to be 100, applying <syntaxhighlight lang=apl inline>+/</syntaxhighlight> over all the weeks is unlikely to cause any problematic performance.


[https://tio.run/##bVJLbtswFNzrFA9ZkbUViIplIBCSS/QEpExZgkVKoOgovkAaBA7QrrzqrqteIMsudBNexH2UFNc2SgggKc6beZ/hTRWudryq18eje/3WWffy/VnA16I0ldxBl/JUpFm6SVWqUxO495/QyXJdWKjzE6rUUG91JlvguZUGbrobRMlNC8QfFd@BkMDhSWa2NoBfV3Arn6ShAf4WqEnYsj/E8SKiDHf38gOT8MsLitLY4lP2pDUHVWtbVDtYm7pDwEpmKJRzr4G0ntTt36LbZOa5Oe0/2BKm5WltDVpyI1sLK8NVAApDuv5jAXAOGwtBcLXV3IyibQAZgpFewSU6q1VTSStPOI24yO1fszA5x@mtEtgpbOJVxNTCOBqFAzBIIL7oS5mp5LFYnxxvmmoYRMWxnkvOADbIcRfDfzkaORV1NsbckxYS8tIg279chn7Yh3arfOZkGMz8CjXxzgcCLZ@vs2nHlyHPUbfhxqIRBu/N3P4Pd@@/0QFk0x8S32LqT6I/EI3bA6MzwkKD4yTDhYWCEnw1CFCPCe0PiFZhRgP08/HIogjYAnD0bOnefp05ghB886aYjBfd3t/RT0tHPiKJ/wI Try it online!]
[https://tio.run/##bVJLbtswFNzrFA9ZkbUViIplIBCSS/QEpExZgkVKoOgovkAaBA7QrrzqrqteIMsudBNexH2UFNc2SgggKc6beZ/hTRWudryq18eje/3WWffy/VnA16I0ldxBl/JUpFm6SVWqUxO495/QyXJdWKjzE6rUUG91JlvguZUGbrobRMlNC8QfFd@BkMDhSWa2NoBfV3Arn6ShAf4WqEnYsj/E8SKiDHf38gOT8MsLitLY4lP2pDUHVWtbVDtYm7pDwEpmKJRzr4G0ntTt36LbZOa5Oe0/2BKm5WltDVpyI1sLK8NVAApDuv5jAXAOGwtBcLXV3IyibQAZgpFewSU6q1VTSStPOI24yO1fszA5x@mtEtgpbOJVxNTCOBqFAzBIIL7oS5mp5LFYnxxvmmoYRMWxnkvOADbIcRfDfzkaORV1NsbckxYS8tIg279chn7Yh3arfOZkGMz8CjXxzgcCLZ@vs2nHlyHPUbfhxqIRBu/N3P4Pd@@/0QFk0x8S32LqT6I/EI3bA6MzwkKD4yTDhYWCEnw1CFCPCe0PiFZhRgP08/HIogjYAnD0bOnefp05ghB886aYjBfd3t/RT0tHPiKJ/wI Try it online!]
Line 38: Line 38:
4 4 15
4 4 15
0 0  4
0 0  4
</source>
</syntaxhighlight>
So we see, with these assumptions, Shirley grows from 6 pounds and 4 ounces at birth to 1 stone and 4 ounces at 16 weeks and to 1 stone, 13 pounds, 15 ounces and 4 drams when a year old.
So we see, with these assumptions, Shirley grows from 6 pounds and 4 ounces at birth to 1 stone and 4 ounces at 16 weeks and to 1 stone, 13 pounds, 15 ounces and 4 drams when a year old.
=== Notes ===
=== Notes ===
<references/>
<references/>
[[Category:Examples]][[Category:Dyalog APL examples]]
[[Category:Examples]][[Category:Dyalog APL examples]]

Navigation menu