need a big pascal's table

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Re: need a big pascal's table

Postby Bob Armstrong on Sun Sep 11, 2022 5:06 pm

I cited this thread in a note to the Silicon Valley Forth Interest Group , https://www.cosy.com/y22/Re_%5bsvfig%5d_(NSF)_(_but_not_strictly_not_)_-_an_APL_level_challenge__10,_000_row_Pascal_Triangle.html , as a candidate for their monthly challenge .

When a follow up brought up Gray codes , I happened to look at my minimal https://cosy.com/4thCoSy/Code/CoSy/math.f collection and saw that I had written a ` Pascal on New Years 2019 .
Code: Select all
|  PascalTri ( n-1 -- n row Pascal triangle ) | 20190101
: PascalTri i1 enc >a { a@ a@ -1 _at ' +i ': i1 braket cL /\a } _nxtimes a> ;


Looking back at my notes for that day I see I was mainly testing my verb ` braket
Code: Select all
: braket ( str strs -- str ) 2p> 0 _at swap cL R@ 1 _at cL 2P> ;
| Prefixes and suffixes str with 2 item strs . Examples : 
|      s" 2 item"  s" <i>" s" </i>" ,L braket


Verbs with prefix ` _ take their preceding int argument directly off the chip ( x86 ) stack and raise it to a 1 item CoSy list .
User avatar
Bob Armstrong
 
Posts: 23
Joined: Wed Dec 23, 2009 8:41 pm
Location: 39.038681° -105.079070° 2500m

Re: need a big pascal's table

Postby Veli-Matti on Wed Sep 14, 2022 7:56 pm

Nice, tclviii, nice!
Usually the old skool ways tend to be efficient, they just don't look that modern, though :)

What follows is a warning about code golfing compared to effectiveness:

I had this idea making the triangle columnwise, i.e. (I have renamed the functions in my workspace)
      ∆←pascal_7 r;c;i;⎕FR
⎕FR←∆fr r
∆←r r⍴r↑1 ⋄ c←r⍴1

:For i :In ⍳r-1
c←∆[i+⍳¯1+≢c;i+1]←¯1↓+\c
:EndFor

∆fr is simply
∆fr←{(⍵>999)(↑⌽)645 1287}

The test seemed promising...

]runtime "pascal_7 10000"
CPU (avg): 3390
Elapsed: 3389

..so what about getting the approach from the quickest pascal function (in my ws this far) and making a tad shorter code to make the function quicker...

      ∆←pascal_7c r;c;i;⎕FR
⎕FR←∆fr r
∆←⍪c←r⍴1

:For i :In ⍳r-1
c←∆,←0,¯1↓+\c
:EndFor

...alas, testing showed something else:

]runtime "pascal_7c 1000"
CPU (avg): 1015
Elapsed: 1020

]runtime "pascal_7c 10000"
CPU (avg): 1122281
Elapsed: 1122749

Be careful what you wish for!

-wm
Veli-Matti
 
Posts: 91
Joined: Sat Nov 28, 2009 3:12 pm

Previous

Return to APL Chat

Who is online

Users browsing this forum: Bing [Bot] and 1 guest