Jump to content

Binomial transform: Difference between revisions

add RPL
m (→‎{{header|J}}: exercise inverse mechanisms)
(add RPL)
Line 776:
Re inverted:
1 0 0 1 0 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37</pre>
 
=={{header|RPL}}==
We use here the <code>SEQ</code> and <code>∑LIST</code>instructions, available for HP-48G or newer models only.
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ DUP SIZE → seq n
{ 1 } 2 n '''FOR''' j
'COMB(j-1,k)' 'k' 0 j 1 - 1 SEQ
seq 1 j SUB
* ∑LIST +
'''NEXT'''
≫ ≫ ‘'''FBITR'''’ STO
≪ DUP SIZE → seq n
{ 1 } 2 n '''FOR''' j
'(-1)^(j-k-1)*COMB(j-1,k)' 'k' 0 j 1 - 1 SEQ
seq 1 j SUB * ∑LIST +
'''NEXT'''
≫ ≫ ‘'''RBITR'''’ STO
|
'''FBITR''' ''( { a(n) } -- { b(n) } ) ''
output = { 2 } ; loop for j=2 to n
get a j-list of c(j-1,k) with k from 0 to j-1
get a j-list of a(k)
multiply the 2 lists, reduce and append result to output
end loop
return list
'''RBITR''' ''( { b(n) } -- { a(n) } )''
same implementation as '''FBITR'''
only the formula for kth term is different here
|}
{{in}}
<pre>
{ 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 } 'ZCAT' STO
{ 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 } 'ZPFF' STO
{ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 } 'ZFIB' STO
{ 1 0 0 1 0 1 1 1 2 2 3 4 5 7 9 } 'ZPAD' STO
ZCAT FBITR ZCAT RBITR ZCAT FBITR RBITR
ZPFF FBITR ZPFF RBITR ZPFF FBITR RBITR
ZFIB FBITR ZFIB RBITR ZFIB FBITR RBITR
ZPAD FBITR ZPAD RBITR ZPAD FBITR RBITR
</pre>
{{out}}
<pre>
12: { 1 2 5 15 51 188 731 2950 12235 51822 223191 974427 4302645 19181100 86211885 }
11: { 1 0 1 1 3 6 15 36 91 232 603 1585 4213 11298 30537 }
10: { 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 }
9: { 0 1 3 6 11 20 37 70 134 255 476 869 1564 2821 5201 }
8: { 0 1 -1 0 3 -10 25 -56 118 -237 456 -847 1540 -2795 5173 }
7: { 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 }
6: { 0 1 3 8 21 55 144 377 987 2584 6765 17711 46368 121393 317811 }
5: { 0 1 -1 2 -3 5 -8 13 -21 34 -55 89 -144 233 -377 }
4: { 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 }
3: { 1 1 1 2 5 12 28 65 151 351 816 1897 4410 10252 23833 }
2: { 1 -1 1 0 -3 10 -24 49 -89 145 -208 245 -174 -176 1121 }
1: { 1 0 0 1 0 1 1 1 2 2 3 4 5 7 9 }
</pre>
 
=={{header|Wren}}==
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.