The following phrases illustrate the production of various numbers, including such lists and tables as the binomial coefficients, various grids, Stirling numbers, primes and prime factors:
n0 =: pi=: 1p1 | π |
v1 =: PI=: 1p1"_ | Other ranks are possible |
n2 =: 2p1 1r2p1 1r6p1 | List of multiples of π |
n3 =: 2p_1 1r2p_1 1r6p_1 | Multiples of reciprocal π |
n4 =: 1x1 | Euler's number (2.71828 ...) |
v5 =: 1x1 1x_1 _1x_1"0 | List function of rank zero |
m6 =: pitimes=: 1p1&* | Like o. but infinite rank |
m7 =: ln=: 1x1&^. | Like ^. (natural log) |
m8 =: ln=: 1x1"_ ^. ] | " |
m9 =: [:^ 0j2p1&% * i. | Roots of unity; e.g. m9 5 |
m10=: 1:=1:^m9 | Roots of unity; e.g. m10 5 |
m11=: sbase=: %:@(2p1&%)* %&1x1 ^] | Stirling's approximation, base term |
m12=: scorr=: 1 1r12 1r288 _139r51840 _571r2488320&p.@% | Stirling's approximation, correction |
m13=: stirg =: sbase * scorr | Stirling's approx for Γ(y) [AS[1] 6.1.37] |
n14=: |1-(!10)%stirg 1+10 | Relative error for !10 |
m15=: stirf =: ^@(1r12&%) *%:@(2p1&*) * %&1x1 ^ ] | Stirling's approx to !y [AS[1] 6.1.38] |
n16=: |1-(!10)%stirf 10 | Relative error for !10 |
m17=: even=: 2:*i. | Even integers |
m18=: odd=: >:@even | Odd integers |
m19=: odd=: 1:+2:*i. | Odd integers |
m20=: grid=: +`(*i.)/ | grid b,s,n is From b step s for n |
m21=: Ai=: >:@i. | Augmented integers (1 to y) |
m22=: +/\@($&1) | " (but not negint arg) |
m23=: Ei=: i.@>: | Extended integers (0 to y) |
m24=: Si=: Ei@+: - ] | Symmetric integers (-y to y) |
m25=: bc=: Ei ! ] | Binomial coefficients |
m26=: (0&,+,&0)^:([`1:) | " |
m27=: bct=: Ei !/ Ei | Pascal's triangle (bc table) |
m28=: !/~@Ei | " |
m29=: !~/~@Ei | Pascal's triangle |
m30=: (0&,+,&0)^:(i.`1:) | " |
m31=: 1 1&([: +//. */)^:(i.`1:) | " |
m32=: +/\@(|.!.0)^:(i.`($&1)) | " |
m33=: odometer=: #: i.@(*/) | All #s in radix y (odometer) |
m34=: >@,@{@(i.&.>"_) | " Try m34 10 10 |
m35=: ,:@i.@0:`([: ,/ i.@{. ,."0 2$:@}.)@.(*@#) | " Try m35 2 2 2 |
m36=: tt=: #:@i.@(2&^) | Truth table of order y |
m37=: odometer@($&2) | " |
m38=: >@,@{@($&(<0 1)) | " |
m39=: ,:@i.`([: ,/ i.@2: ,."0 2 $:@<:)@.* | " |
m40=: [:|:2&^($ #&0 1)"(0)2&^@i.@- | " |
m41=: (i.@# = i.~) # ] | Nub (all distinct items of) ~. |
m42=: ~: # ] | " Try m42 2 7 1 8 2 8 |
m43=: +./@(</\"1"_)@= # ] | " Try m43 ;:'all in all' |
m44=: ~.@(i.~) { ] | " |
m45=: {./.~ | " |
m46=: ({.;#)/.~ | Nub and count |
m47=: #/.~ | " Try m47 2 7 1 8 2 |
m48=: +/"1@= | " Try m48 ;: 'all in all' |
m49=: 1: #. = | " |
m50=: ifb=: # i.@# | Index from boolean |
d51=: bfi=: i.@[ e. ] | Boolean from index; e.g. 0 d51 5 7 |
d52=: 1:`]`($&0@[)} | Boolean from index |
m53=: cfpv=: #;.1 | Count from partition vector |
m54=: pvfc=: [: ; {.&1&.> | Partition vector from count |
m55=: i.@(+/) e. 0&,@(+/\) | " |
n56=: 2147483647=p: 105097564 | The 105,097,564-th prime (0 origin) |
m57=: lp=: p:@i. | List first y primes |
m58=: fotp=: (2&(_2:=-/\)#}:)@lp | First of twin primes among first y |
m59=: p:^:_1 | Number of primes less than y |
n60=: 2 2 2 3 5 -: q: 120 | Prime factorization of 120 |
m61=: taut=: -: */@q: | y = product of factors. Try m61 12345 |
m62=: dpe=: (~. ,: 1: #. =)@q: | Distinct primes with exponents |
m63=: |:@(({.,#)/.~)@q: | " |
m64=: taut=: = */@(^/)@dpe | y = product over powers. Try m64 120 |
m65=: = */ .^/@dpe | " |
m66=: divisors=: /:~@(~. */ .^"1 odometer@:>:@(#/.~))@q: | Divisors of y. Try m66 900 |
m67=: /:~@~.@(*/ .^"1 tt@#)@q: | " |
m68=: /:~@,@>@(*/&.>/)@ (<@(1&,) @(*/\)/.~) @ q: | " |
m69=: >:@i. ([ #~ 0: = |) ] | " |
m70=: perfect=: +: = +/@divisors | Perfect number test |
m71=: 1: = #@q: | Prime test |
d72=: q:@[ -: -.&q: | Relatively prime test |
d73=: 1: = +. | " |
m74=: totient=:* -.@%@~.&.q: | Totient [GKP[3] 4.53] |
m75=: */@(^/-(^<:)/)@dpe | " |
m76=: 1: #. 1: = (+.i.) | " |
m77=: [:/:~[:~.]|[:*:[:m50]m73[:i.] | Quadratic residues |
d78=: L=: [:{&_1 1|~e.(|*:@}.@i.)@] | Legendre symbol |
d79=: L * L~ | Quadratic reciprocity |
d80=: cfe=:<.@(([:%1:|])^:(i.@[`])) | x terms of continued fraction expan of y |
m81=: rapprox=: (, % +.)&1"0 | Rational approximation to y |
m82=: [:>:[:m50]m72"0[:>:[:i.[:<:] | Numbers prime to y |
m83=: 3 : '<.@o.&.((10^y.)&*) 1' | y digits of pi |
m84=: [: +/ %@!@i. | y digits of e |
d85=: 4 : '-:@(+y.&%)^:(>.2^.1>.x.-16) x:%:y.' | x digits of the square root of integer y |
The last three phrases illustrate operations on extended precision arguments. (0j_40 ": y formats y in exponential notation using 40 digits.)