>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Phrases

# 7C. Parity & Symmetry

Parity and symmetry each refer to any one of several related notions, including:

Parity

1. Integers - odd or even
2. Permutations - odd if equivalent to an odd number of transpositions of pairs; even otherwise
3. A function - odd if negation of its argument negates its result; even if the result is unchanged; or neither

Symmetry and skew-symmetry

1. A matrix is symmetric if equal to its transpose; skew if equal to the negation of its transpose; or neither
2. function is symmetric if it is invariant under permutations of its argument
3. A function f is symmetric under `g` if `f&.g` is equivalent to `f`; is skew if it is equivalent to `-@f`; or neither. Item c of parity concerns symmetry under -

Symmetric and skew-symmetric parts

> Each has the specified property, and their sum equals the function from which they are derived. For example, sinh and cosh are the odd and even parts of the exponential under negation.

In classifying any entity for parity or symmetry, we will give the result _1 for the odd or skew case, 1 for the even or symmetric case, and 0 for neither.

`m0=: Isodd=: 2&|` | Test if y is an odd integer
`m1=: Iseven=: -.@Isodd` | Test if y is an even integer
`m2=: Isperm=: -: /:@/:` | Test if y is a permutation vector
`a3=: 1 : 'x. -: [: x. ?@!@# A. ]'` | Necessary condition for symmetry of fn.
`m4=: Isperm * _1:^>/~ ~:/@,@:* </~@i.@#` | Classify argument as a permutation
`m5=: L=: >/~` | Left, centre, right limbs of the fork ...
`m6=: C=: ~:/@,@:*` | ... evaluated in`m4` ; see their use below ...
`m7=: R=: </~@i.@#` | ... to demonstrate design of its definition
`m8=: C.!.2` | same as`m4`
`m9=: Isperm * _1:^+/@(<:@#@>@(C.@~.))` | Parity of permutation from cycle lengths
`m10=: -/@(|:-:"2],:-)` | Classify matrix (skew, neither, sym)
`a11=: skn=: .:-` | Skew part with respect to negate
`a12=: syn=: ..-` | Symmetric "
`a13=: skt=: .:|:` | Skew part with respect to transpose
`a14=: syt=: ..|:` | Symmetric "
`m15=: sinh=: 5&o.` | Hyperbolic sine
`m16=: cosh=: 6&o.` | Hyperbolic cosine
`n17=: m=: 3 1 4,2 0 5,:1 4 1` | A 3-by-3 matrix
`d18=: ip=: +/ . *` | Inner (matrix) product
`m19=: LF=: m&ip` | A linear function
`m20=: cst=: C.!.2@(#:i.)@:#~` | Complete skew tensor
`d21=: cross1=: [ip cst@#@[ip]` | Generalized cross-product
`d22=: cross2=: ((_1: |.[)*(1:|.]))-((1: |.[)*(_1: |. ]))` | Conventional cross product (not valid for dimension greater than 3)
`m23=: det1=: +/@,@(*// * cst@#)` | Determinant in terms of cst
`m24=: det2=: -/ . *` | Determinant
`m25=: length=: m24=: +/&.(*:"_)"1` | Length of vector
`m26=: arcsin=: _1&o.` | Arcsine
`m27=: angle=:arcsin@(length@ cross1 % length@[*length@])` | Angle between two vectors
`m28=: dfr=: 180p_1&*` | Degrees from radians

The symmetry of a function may be tested (but not guaranteed) by the adverb`a3` :

       +/ a3
    +/ -: [: +/ ?@!@# A. ]

       (+/a3,-/a3,*/a3,>./a3,/:~a3) 3 1 4 2
    1 0 1 1 1

Sum, product over, max over, and sort are symmetric, but the alternating sum is not.

Phrases may be analyzed by isolating and executing phrases that occur within them. Consider, for example, phrases m4-7:

       p6=: (i.@! A. i.) 3
       n6=: 3 3 3#:i.6
       p6 ; (,. m4"1 p6) ; n6 ; (,. m4"1 n6)
    +-----+--+-----+-+
    |0 1 2| 1|0 0 0|0|
    |0 2 1|_1|0 0 1|0|
    |1 0 2|_1|0 0 2|0|
    |1 2 0| 1|0 1 0|0|
    |2 0 1| 1|0 1 1|0|
    |2 1 0|_1|0 1 2|1|
    +-----+--+-----+-+

       perm=: 3 1 4 2 0
       (L;R;(L*R);(L C R)) perm
    +---------+---------+---------+-+
    |0 1 0 1 1|0 1 1 1 1|0 1 0 1 1|1|
    |0 0 0 0 1|0 0 1 1 1|0 0 0 0 1| |
    |1 1 0 1 1|0 0 0 1 1|0 0 0 1 1| |
    |0 1 0 0 1|0 0 0 0 1|0 0 0 0 1| |
    |0 0 0 0 0|0 0 0 0 0|0 0 0 0 0| |
    +---------+---------+---------+-+

These panels show that `L` compares every pair of elements of the argument for precedence (to see which must be moved over which), and the upper triangle provided by `R` masks out double counting.

Used with various functions such as negate and transpose, the conjunctions `.:` and `..` yield adverbs that produce odd and even parts of functions to which they are applied:

       (^skn,sinh,^syn,cosh,: ^ = ^skn + ^syn) a=:i.6
    0  1.1752 3.62686 10.0179 27.2899 74.2032
    0  1.1752 3.62686 10.0179 27.2899 74.2032
    1 1.54308  3.7622 10.0677 27.3082 74.2099
    1 1.54308  3.7622 10.0677 27.3082 74.2099
    1       1       1       1       1       1

          ]y=: (^t. , ^skn t. , sinh t. , ^syn t. ,: cosh t.) a
    1 1 0.5 0.1666667 0.04166667 0.008333333
    0 1   0 0.1666667          0 0.008333333
    0 1   0 0.1666667          0 0.008333333
    1 0 0.5         0 0.04166667           0
    1 0 0.5         0 0.04166667           0

       % y
    1 1 2 6 24 120
    _ 1 _ 6  _ 120
    _ 1 _ 6  _ 120
    1 _ 2 _ 24   _
    1 _ 2 _ 24   _

       !^:_1 % y
    0 0 2 3 4 5
    _ 0 _ 3 _ 5
    _ 0 _ 3 _ 5
    0 _ 2 _ 4 _
    0 _ 2 _ 4 _

       (LF;LF skt;LF syt;LF skt+LF syt) m
    +----------------------------------------------+
    |15 19 21|_5.5 _3.5   5|20.5 22.5   16|15 19 21|
    |11 22 13|_7.5 _3.5   3|18.5 25.5   10|11 22 13|
    |12  5 25| 0.5   _1 3.5|11.5    6 21.5|12  5 25|
    +----------------------------------------------+

Skew arrays may be used in expressions for orthogonality, as in the vector cross product (orthogonal to the plane defined by its arguments), the curl (orthogonal to the matrix of partial derivatives), and the determinant. We will illustrate this by the completely skew tensor (`cst`), whose sign is reversed by the transposition of any pair of axes.

       v=: a cross1 b [a=: 3 1 4 [ b=: 2 0 5
       v;(v ip a,.b);(a angle b);(dfr 0 0 1 angle 0 1 0)
    +------+---+---------+--+
    |_5 7 2|0 0|0.3274544|90|
    +------+---+---------+--+

       (cst@#;*//;(cst@#**//);+/@,@(cst@#**//);det1) m
    +--------+--------+--------+---+---+
    | 0  0  0| 6 24  6|0   0  0|_25|_25|
    | 0  0  1| 0  0  0|0   0  0|   |   |
    | 0 _1  0|15 60 15|0 _60  0|   |   |
    |        |        |        |   |   |
    | 0  0 _1| 2  8  2|0   0 _2|   |   |
    | 0  0  0| 0  0  0|0   0  0|   |   |
    | 1  0  0| 5 20  5|5   0  0|   |   |
    |        |        |        |   |   |
    | 0  1  0| 8 32  8|0  32  0|   |   |
    |_1  0  0| 0  0  0|0   0  0|   |   |
    | 0  0  0|20 80 20|0   0  0|   |   |
    +--------+--------+--------+---+---+

>> << Ndx Usr Pri Phr Dic Rel Voc !: wd Help Phrases