APL Exercises 1 ⎕io←0 throughout. This set of exercises is on some useful utilities.
The ones which are from the dfns workspace and are documented in http://dfns.dyalog.com,
for example http://dfns.dyalog.com/n_cmpx.htm.
1.0 cmpx )copy dfns cmpx n←1e5 cmpx '+/⍳n' '2!n' '2÷⍨n×n-1'
1.1 wsreq )copy dfns wsreq n←1e5 wsreq '+/⍳n' wsreq '2!n' wsreq¨ '+/⍳n' '2!n' 1.2 assert The dfn assert is defined as follows: assert←{⍺←'assertion failure' ⋄ 0∊⍵:⍺ ⎕SIGNAL 8 ⋄ shy←0} The details of the definition are not at issue at present (it’s full of technical arcana). Here we just want to use it. In a dfn, assert is used as: assert condition : (The trailing colon is required.) If condition is all 1, then execution merely proceeds to the next line; otherwise an assertion failure is signalled. Write a function transpose2 to do ⍺⍉⍵ which thoroughly checks that ⍺ and ⍵ are valid arguments for ⍉ . For example: transpose2←{ assert ⍺=⌊⍺: ⍺⍉⍵ } x←3 4⍴⍳12 1 0 transpose2 x 0 4 8 1 5 9 2 6 10 3 7 11 1.5 0 transpose2 x assertion failure transpose2[1] assert ⍺=⌊⍺: ∧ An arithmetic progression vector is a vector
of the form a+b×⍳n where a and b
are real scalars and n is a non-negative integer.
Write a function apv ⍵ with result 1
if ⍵ is an arithmetic progression vector
and signals assertion failure otherwise.
|