#] #] ********************* #] "$d_Qroot""help - [develop, debug, error list, etc]/help- transformers.txt" # wwwBillHowell.ca 12Oct2021 initial (long overdue!) # I wrote transformer notes over the decades somewhere, good luck finding them. # 12Oct2021 - I massively under-use the standard transformers, and am incompetent at making new ones. #] 13Oct2021 comparison between TRANSFORMER and OPERATOR as a general transformer : I find that IS OP is more [general, powerful] than a TANSFORMER definition!? optrPhr_LEAF_ary_aryStatic_tables IS OP optrPhr dat_tbl allTr_tbl outRpt LEAF_ary1aryStatic IS TRANSFORMER f OPERATION ary1aryStatic This is because IS OP : - allows optrPhr to be a variable, which is important for general code. I have not found any way to use "non-fixed" coding of f for transformers, which may be possible. - is much [easy, fast]er to [code,bug] CONCLUSION : A general TRANSFORMER is either a formal QNial definition, or an optr (IS OP) with at least one argument that is an optrPhr (phrase of the name of an operator). - For most of what I do, standard QNial transformers are great : [EACH[,Right,LEFT,BOTH,ALL], FOR, WHILE] - For special code, the "IS OP" form is more powerful, and easier to [code, debug, track]. 24************************24 #**************************** # List of items, generated with : # $ grep "^#]" "$d_Qroot""help - [develop, debug, error list, etc]/help- transformers.txt" | sed 's/^#\]/ /' # ********************* "$d_Qroot""help - [develop, debug, error list, etc]/help- transformers.txt" 13Oct2021 comparison between TRANSFORMER and OPERATOR as a general transformer : +-----+ Examples 13Oct2021 opPhr_ary_LEAFreplaceWith_aryStatic versus LEAF_ary1aryStatic 13Oct2021 transformer LOWER - dimensionality reduction of cart result 12Oct2021 pack - seems a bit too complex for me at this time, not directly usefur what I'm doing +-----+ List of transformers with quick description : 08********08 #] +-----+ #] Examples 08********08 #] 13Oct2021 opPhr_ary_LEAFreplaceWith_aryStatic versus LEAF_ary1aryStatic # opPhr_ary_LEAFreplaceWith_aryStatic IS OP optrPhr ary aryStatic - # aryStatic value doesn't change through recursion [depth, breadth]s # 11Oct2021 initial # for [TR versus IS OP] comments see : # "$d_Qroot""help - [develop, debug, error list, etc]/help- transformers.txt" opPhr_ary_LEAFreplaceWith_aryStatic IS OP optrPhr ary aryStatic { IF isAtom ary THEN apply optrPhr (ary aryStatic) ELSE EACH opPhr_ary_LEAFreplaceWith_aryStatic (EACH first (1 lower (cart optrPhr ary [aryStatic]))) ENDIF } # LEAF_ary1aryStatic IS TRANSFORMER f OPERATION ary1aryStatic - # aryStatic value doesn't change through recursion [depth, breadth]s # 11Oct2021 initial # for [TR versus IS OP] comments see : # "$d_Qroot""help - [develop, debug, error list, etc]/help- transformers.txt" LEAF_ary1aryStatic IS TRANSFORMER f OPERATION ary1aryStatic { ary1 aryStatic := ary1aryStatic ; IF isAtom ary1 THEN f ary1 aryStatic ELSE % intermediate := ary1 EACHLEFT pair aryStatic ; % write intermediate ; EACH (LEAF_ary1aryStatic f) (ary1 EACHLEFT pair aryStatic) ENDIF } 08********08 #] 13Oct2021 transformer LOWER - dimensionality reduction of cart result cart produces a result that has the sum of the input top-most dimensions. In some applications this must be reduced to that of one of the inputs, or something else. This is especially clear with [atom, solitary] arguments. The LOWER transformer helps here. Care must be taken with the selection of axis. In the example below, with 2 solitary arguments, it is important to first LOWER the axis of the >[atom, solitary] argument. The "EACH first" second step is the most [clear, general]. qnial> aryStatic l qnial> ary := ((2 2 reshape ('hot' ((2 2 reshape (l (ll) (2 2 reshape l) l))) (2 2 reshape (1 `t `z ['all'])) 'small')) ) +---------+-------+ |hot |+--+--+| | || l|ll|| | |+--+--+| | ||ll| l|| | ||ll| || | |+--+--+| +---------+-------+ |+-+-----+|small | ||1|t || | |+-+-----+| | ||z|+---+|| | || ||all||| | || |+---+|| | |+-+-----+| | +---------+-------+ qnial> c := EACH first (1 lower (cart "hello ary [aryStatic])) +-------------------+-----------------+ |+-----+---+-+ |+-----+-------+-+| ||hello|hot|l| ||hello|+--+--+|l|| |+-----+---+-+ || || l|ll|| || | || |+--+--+| || | || ||ll| l|| || | || ||ll| || || | || |+--+--+| || | |+-----+-------+-+| +-------------------+-----------------+ |+-----+---------+-+|+-----+-----+-+ | ||hello|+-+-----+|l|||hello|small|l| | || ||1|t || ||+-----+-----+-+ | || |+-+-----+| || | || ||z|+---+|| || | || || ||all||| || | || || |+---+|| || | || |+-+-----+| || | |+-----+---------+-+| | +-------------------+-----------------+ qnial> c := first (2 lower (cart "hello [aryStatic] ary)) +-------------------+-----------------+ |+-----+-+---+ |+-----+-+-------+| ||hello|l|hot| ||hello|l|+--+--+|| |+-----+-+---+ || | || l|ll||| | || | |+--+--+|| | || | ||ll| l||| | || | ||ll| ||| | || | |+--+--+|| | |+-----+-+-------+| +-------------------+-----------------+ |+-----+-+---------+|+-----+-+-----+ | ||hello|l|+-+-----+|||hello|l|small| | || | ||1|t |||+-----+-+-----+ | || | |+-+-----+|| | || | ||z|+---+||| | || | || ||all|||| | || | || |+---+||| | || | |+-+-----+|| | |+-----+-+---------+| | +-------------------+-----------------+ qnial> c := 1 lower (cart "hello ary [aryStatic]) +---------------------+-------------------+ |+-------------+ |+-----------------+| ||+-----+---+-+| ||+-----+-------+-+|| |||hello|hot|l|| |||hello|+--+--+|l||| ||+-----+---+-+| ||| || l|ll|| ||| |+-------------+ ||| |+--+--+| ||| | ||| ||ll| l|| ||| | ||| ||ll| || ||| | ||| |+--+--+| ||| | ||+-----+-------+-+|| | |+-----------------+| +---------------------+-------------------+ |+-------------------+|+---------------+ | ||+-----+---------+-+|||+-----+-----+-+| | |||hello|+-+-----+|l|||||hello|small|l|| | ||| ||1|t || ||||+-----+-----+-+| | ||| |+-+-----+| |||+---------------+ | ||| ||z|+---+|| ||| | ||| || ||all||| ||| | ||| || |+---+|| ||| | ||| |+-+-----+| ||| | ||+-----+---------+-+|| | |+-------------------+| | +---------------------+-------------------+ 08********08 #] 12Oct2021 pack - seems a bit too complex for me at this time, not directly usefur what I'm doing A := 9 [2] (4 4 reshape (5+tell 16)) +-+-+-----------+ |9|2| 5 6 7 8| | | | 9 10 11 12| | | |13 14 15 16| | | |17 18 19 20| +-+-+-----------+ pack A +------+------+------+------+ |9 2 5 |9 2 6 |9 2 7 |9 2 8 | +------+------+------+------+ |9 2 9 |9 2 10|9 2 11|9 2 12| +------+------+------+------+ |9 2 13|9 2 14|9 2 15|9 2 16| +------+------+------+------+ |9 2 17|9 2 18|9 2 19|9 2 20| +------+------+------+------+ >> use pack instead of cart? (but cart is simple, pack is not?) 08********08 #] +-----+ #] List of transformers with quick description : Applicative transformers: bykey converse applies binary operation f to the pair formed by reversing the arguments of CONVERSE f fold N FOLD A -> apply f, N times, applying it first to A and subsequently to the result of the previous application. 3 FOLD rest 4 5 6 7 8 9; 2 FOLD sum (2 3 4) (5 6 7) inner INNER [+,*] is equivalent to matrix multiplication in linear algebra INNER [or,and] is boolean matrix product. outer applies f to each item of the cartesian product of its argument (Howell - I use just cart) team applies the operations of atlas f to corresponding items in the list of A (Howell - cute but what help is this? could reduce useless intermediate variables, add clarity) Apply-by-partition transformers: bycols applies an operation f to the columns of a table A, byrows applies an operation f to the rows of a table A, where f is an operation that maps lists to lists partition ??? split, blend stuff- handy to reorder rank applies f to arrays formed from the last N axes of A, eg 1 RANK sum (3 4 reshape count 12) reducecols reduction of the columns of A with the operation f REDUCECOLS sum (5 6 reshape count 30) reducerows reduction of the rows of A with the operation f Control flow transformer: catch handy??? regain control when the called argument function f applied to the argument A terminates its computation early by the application of the control flow function throw Control structure transformers: fork iterate Distributive transformers: each eachall applies f to arrays formed by selecting the items of the items of A in corresponding positions, assuming that the items of A are all of the same shape. When the items of A are not all the same shape, A is examined to see if all the items with tally greater than one have the same shape. If so, all the items of tally 1 are replicated to that shape. If not, the fault ?conform is returned. eachboth eachleft eachright leaf applies f to every atom of the argument A twig applies f to every simple array in the nested structure of A Recursion transformers: across down recur Reduction transformers: A reductive operation is one which when applied to an array having a number of items returns a single result accumulate ??? computes the partial reductions of the initial lists of the items of A, using reduce f reduce f is placed between the items of A, with grouping done in a right-to-left manner. eg REDUCE divide 3 4 5 6 Selection transformer: filter produce a list of the items of A that satisfy the predicate f Sorting transformers: grade returns an array of addresses of the same shape as A that orders A according to the comparator. The addresses can be used to select the items of A (using choose) so that the items are in order according to f. sort returns the list of items of array A ordered according to the comparator f. The operations <= and >= are the usual comparators. System transformer: no_tr transforms any operation f to an operation that returns the fault ?missing_tr when applied to any array A. It is the default value for a transformer name declared to be external or that has been erased. Reshaping optrs : # enddoc