⍝ Transpose.tc
⍝ ----------------------------------

)COPY_ONCE 3 INVARIANTS.apl   ⍝ defines INV∆CHECK
³   ⍝ e.g. NEW )COPY_ONCE workspace: 3 INVARIANTS.apl
³   ⍝ e.g. DUMPED 2023-03-22  20:07:13 (GMT+1) 

   ⎕IO←1   ⍝ for proper axis


      A←2 3 4ρ'BEARLYNXDUCKPONYBIRDOXEN'
      A
BEAR
LYNX
DUCK

PONY
BIRD
OXEN

      ρA
2 3 4

      Z←1 3 2⍉A
      ρZ
2 4 3

      Z
BLD
EYU
ANC
RXK

PBO
OIX
NRE
YDN

      W←2 1 3⍉A
      ρW
3 2 4

      W
BEAR
PONY

LYNX
BIRD

DUCK
OXEN


      Y←3 1 2⍉A
      ρY
3 4 2

      Y
BP
EO
AN
RY

LB
YI
NR
XD

DO
UX
CE
KN

⍝ diagonal cross section of B ----------------------------------

      ⊢B←4 4ρι16
 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15 16

      1 1⍉B
1 6 11 16


      ⊢C←3 4ρι12
1  2  3  4
5  6  7  8
9 10 11 12

      1 1⍉C
1 6 11


      ⊢D←3 3⍴'ONE' 'FOR' 'ALL' 'HEAD' 'TO' 'TOE' 'READY' 'SET' 'GO'
 ONE   FOR ALL 
 HEAD  TO  TOE 
 READY SET GO  

      ⊢V←1 1⍉D
 ONE TO GO 

      ρV
3

      ≡V
2

⍝ higher rank arrays ----------------------------------

      ⊢H←2 3 4ρ'ABCDEFGHIJKL',ι12
A  B  C  D
E  F  G  H
I  J  K  L

1  2  3  4
5  6  7  8
9 10 11 12

      ⍝ lrm p, 251 Case 2 (repeated items in A)...
      ⍝
      INV1 ← "I⊃ρZ ←→ ⌊/(L=I)/ρR"              ⍝ invariant 1
      ITER ← "⍴⍴L"                             ⍝ iterator for invariant 1
      INV2 ← "⍴⍴Z  ←→ ,+/(L⍳L) = ⍳⍴L"          ⍝ invariant 2 (without iterator)

      A←1 1 1 ◊ ⊢Z←A⍉H
A 6

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


      A←1 1 2 ◊ ⊢Z←A⍉H
A B C D
5 6 7 8

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


      A←2 2 1 ◊ ⊢Z←A⍉H
A 5
B 6
C 7
D 8

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


     A←1 2 1 ◊ ⊢Z←A⍉H
A E  I
2 6 10

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


     A←2 1 2 ◊ ⊢Z←A⍉H
A  2
E  6
I 10

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


     A←1 2 2 ◊ ⊢Z←A⍉H
A F  K
1 6 11

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


     A←2 1 1 ◊ ⊢Z←A⍉H
A  1
F  6
K 11

      INV1  INV∆CHECK[ITER]  A H Z     ⍝ test invariant #1
      INV2  INV∆CHECK        A H Z     ⍝ test invariant #2


⍝ effect of ⎕IO ----------------------------------

      ⎕IO←0

      K←3 2 4ρι24
      K
 0  1  2  3
 4  5  6  7

 8  9 10 11
12 13 14 15

16 17 18 19
20 21 22 23

      1 0 2⍉K
 0  1  2  3
 8  9 10 11
16 17 18 19

 4  5  6  7
12 13 14 15
20 21 22 23

      ⎕IO←1

⍝ selective spec ----------------------------------

      P←3 3ρι9
      (1 1⍉P)←10 20 30
      P
10  2  3
 4 20  6
 7  8 30

      ⍝ regression
      ⍝
      ⍉⍬


⍝ ==================================

