Transformation functions - Gianfrancoalongi/murenzhuang GitHub Wiki

The Transformation functions are defined over 'a-z' and 0-9 and no other input elements. Each available transformation function is described with an example of the output - given input data

Order

Returns an array of size |[x_i]|-1 where each element in the array is an integer, indicating the order between two adjacent elements passed through the index array [x_i]. For every element in the returned array, 0 indicates that the adjacent elements where equal, 1 indicates the right one is larger, 2 indicates the left one is larger, 3 indicates they can not be compared (alphabetic vs numeric).

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Order is called with the indices
    Order 1 2 3
  substitution gives
    Order a b 1
  which results in
    a ? b = 1
    b ? 1 = 3
  thus giving the output
    1 3

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Order is called with the indices
    Order 3 1
  substitution gives
    Order a 1
  which gives
    a ? 1 = 3
  thus giving the output
    3

Decrease

Returns an array of size |[x_i]|, each element decreased by one. For numerical elements, the decrease is modulo 10. For alphabetical elements, they are decreased modulo (z+1).

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Decrease is called with the indices
    Decrease 1 2 3
  substitution gives
    Decrease a b 1
  which results in 
    a - 1 = z
    b - 1 = a
    1 - 1 = 0      
  thus giving the output
    z a 0

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Decrease is called with the indices
    Decrease 3 1
  substitution gives
    Decrease a 1
  which results in
    a - 1 = z
    1 - 1 = 0
  thus giving the output
    z 0

Increase

Returns an array of size |[x_i]|, each element increased by one. For numerical elements, the increase is modulo 10. For alphabetical elements, they are increased modulo (z+1).

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Increase is called with the indices
    Increase 1 2 3
  substitution gives
    Increase a b 1
  which results in 
    a + 1 = b
    b + 1 = c
    1 + 1 = 2      
  thus giving the output
    b c 2

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Increase is called with the indices
    Increase 3 1
  substitution gives
    Increase a 1
  which results in
    a + 1 = b
    1 + 1 = 2
  thus giving the output
    b 2

Type

Returns an array of size |[x_i]|, which declares the type of the elements - with integers. 1 means integer, 0 means alphabetic.

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Type is called with the indices
    Type 1 2 3
  substitution gives
    Type a b 1
  which results in 
    a = 0
    b = 0
    1 = 1      
  thus giving the output
    0 0 1

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Type is called with the indices
    Type 3 1
  substitution gives
    Type a 1
  which results in
    a = 0
    1 = 1
  thus giving the output
    0 1

Copy

Creates an array where each element indexed by the index x_i is replaced by |x_i| amount of copies.

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Copy is called with the indices
    Copy 1 2 3
  substitution gives
    Copy a b 1
  which results in 
    a -> a
    b -> b b
    1 -> 1 1 1      
  thus giving the output
    a b b 1 1 1

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Copy is called with the indices
    Copy 3 1
  substitution gives
    Copy a 1
  which results in
    a -> a a a
    1 -> 1
  thus giving the output
    a a a 1

Sum

Returns a data element or an array with two sums which is the sum of the elements indexed by [x_i], the sum is subject to modulo. Adding integers will be modulo 10, adding alphabetic characters is modulo (z+1). If there are mixed types targeted by [x_i], a sum is computed for each group and returned.

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Sum is called with the indices
    Sum 1 2 3
  substitution gives
    Sum a b 1
  which results in 
    a + b = 1 + 2 = 3 = c
    1 = 1      
  thus giving the output
    c 1

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Sum is called with the indices
    Sum 3 1
  substitution gives
    Sum a 1
  which results in
    a 1
  thus giving the output
    a 1

Encode

Returns an array where every targeted element changes domain, integer elements are encoded as alphabetic characters (based on corresponding index), alphabetic characters are encoded as integers - not modulo.

Example 1

Buffer-2
Buffer: [a,b]
Current: 1
[x_i]: 1 2 3
  then Encode is called with the indices
    Encode 1 2 3
  substitution gives
    Encode a b 1
  which results in 
    a = 1
    b = 2
    1 = a    
  thus giving the output
    1 2 a

Example 2

Buffer-2
Buffer: [1,2]
Current: a
[x_i]: 3 1
  then Encode is called with the indices
    Encode 3 1
  substitution gives
    Encode a 1
  which results in
    a = 1
    1 = a
  thus giving the output
    1 a