Shirley: Difference between revisions

Jump to navigation Jump to search
81 bytes added ,  21:03, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
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 <source 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 <source 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</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>):


<source lang=apl>
<syntaxhighlight lang=apl>
wt←xb Shirley w;a;b;c;k;m;n;r
wt←xb Shirley w;a;b;c;k;m;n;r
⍝ weight of Shirley in ounces after "w" weeks ("w" may be a vector or whatever)
⍝ weight of Shirley in ounces after "w" weeks ("w" may be a vector or whatever)
Line 22: Line 22:


[https://tio.run/##bVJBbqswEN1zilFXdhMqoKXSF@q/xD@BTYaAgg0yTmku0FZVKrWrrHqBXqDLLrgJF2nHQNMk@gjJBj@/92bmibr0FxtRVsuvr/7xobX9/cudhH95YUrcQJuIRCZpskpUohPj9c9v0GKxzC1U2R5VaKjWOsUGRGbRwFl7RihcNcDcVokNSAQBt5jaygC9bS4s3qLhHv2WpMnC624XRVcBD2nt71/JhHucoCyMzX9k91pzUJW2ebmBpalaAiwwJaFMOA2idaT99im4iGeOW/DuI7yG6XG0tgKNwmBjYWGE8kDRlbb7uAI4hI2FELhca2FG0caDlMBEr@AYnVaqLtHiHqcJF/Tbx9SPD3F6rSR1ipp4cmNqYRSMwh4YIpDn@lhmKnks1pkTdV0OgygF1XPM6cGKOC4j@C9HjVNRB2PMHGmOkBWG2H69DP2wN81aOedsGMz8BDXxzgcCjXenbprxZPA56tbCWArCkL1Zv/0U/fM7JYCtul3sWszdTnY7pmm5CfmMhb6hcbLhI/QlZ3RqCKD@xrzbEVr5KfcozxTqMQKMhUHgEjClDIKLP3wfYApGHH0D Try it online!]
[https://tio.run/##bVJBbqswEN1zilFXdhMqoKXSF@q/xD@BTYaAgg0yTmku0FZVKrWrrHqBXqDLLrgJF2nHQNMk@gjJBj@/92bmibr0FxtRVsuvr/7xobX9/cudhH95YUrcQJuIRCZpskpUohPj9c9v0GKxzC1U2R5VaKjWOsUGRGbRwFl7RihcNcDcVokNSAQBt5jaygC9bS4s3qLhHv2WpMnC624XRVcBD2nt71/JhHucoCyMzX9k91pzUJW2ebmBpalaAiwwJaFMOA2idaT99im4iGeOW/DuI7yG6XG0tgKNwmBjYWGE8kDRlbb7uAI4hI2FELhca2FG0caDlMBEr@AYnVaqLtHiHqcJF/Tbx9SPD3F6rSR1ipp4cmNqYRSMwh4YIpDn@lhmKnks1pkTdV0OgygF1XPM6cGKOC4j@C9HjVNRB2PMHGmOkBWG2H69DP2wN81aOedsGMz8BDXxzgcCjXenbprxZPA56tbCWArCkL1Zv/0U/fM7JYCtul3sWszdTnY7pmm5CfmMhb6hcbLhI/QlZ3RqCKD@xrzbEVr5KfcozxTqMQKMhUHgEjClDIKLP3wfYApGHH0D Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       ⌊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>
</source>


For the <source lang=apl inline>n</source> complete months after month 5 the total weight increase is <source lang=apl inline>k×+/b*⍳n</source> which we know is <source 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</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]]).


Even if Shirley lives to be 100, applying <source 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>+/</source> 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!]
<source lang=apl>
<syntaxhighlight lang=apl>
       100 14 16 16⊤⌊0.5+16×((100÷16×2240)0.93)Shirley 0 16 52
       100 14 16 16⊤⌊0.5+16×((100÷16×2240)0.93)Shirley 0 16 52
0 1  1
0 1  1

Navigation menu