operator: flatten-seq
description:
flatten-seq[merge-str] seq
flatten-seq merges a sequence into a superposition of sequences, separated by the merge-string.
Each sequence in the superposition is another "pathway" through the input sequence
The coefficients of each piece of the sequence multiply the final sequence
examples:
flatten-seq[" . "] (|a> + |b> . |c> + |d> + |e> . |f> + |g>)
|a . c . f> + |a . c . g> + |a . d . f> + |a . d . g> + |a . e . f> + |a . e . g> + |b . c . f> + |b . c . g> + |b . d . f> + |b . d . g> + |b . e . f> + |b . e . g>
-- how many pathways:
how-many flatten-seq[" . "] (|a> + |b> . |c> + |d> + |e> . |f> + |g>)
|number: 12>
flatten-seq[" . "] (|a> + 2|b> . 0.5|c> + 0.7|d> + 3|e>)
0.5|a . c> + 0.7|a . d> + 3|a . e> + |b . c> + 1.4|b . d> + 6|b . e>
-- how many pathways:
how-many flatten-seq[" . "] (|a> + 2|b> . 0.5|c> + 0.7|d> + 3|e>)
|number: 6>
Let's say we have a four step pathway:
A -> B -> C -> D
A -> B has |A to B path 1> and |A to B path 2> and |A to B path 3>
B -> C has |B to C path 1>
C -> D has |C to D path 1> and |C to D path 2>
then to find all permutations of pathways, we do:
print flatten-seq[" . "] (|A to B path 1> + |A to B path 2> + |A to B path 3> . |B to C path 1> . |C to D path 1> + |C to D path 2>)
A to B path 1 . B to C path 1 . C to D path 1
A to B path 1 . B to C path 1 . C to D path 2
A to B path 2 . B to C path 1 . C to D path 1
A to B path 2 . B to C path 1 . C to D path 2
A to B path 3 . B to C path 1 . C to D path 1
A to B path 3 . B to C path 1 . C to D path 2
|A to B path 1 . B to C path 1 . C to D path 1> + |A to B path 1 . B to C path 1 . C to D path 2> + |A to B path 2 . B to C path 1 . C to D path 1> + |A to B path 2 . B to C path 1 . C to D path 2> + |A to B path 3 . B to C path 1 . C to D path 1> + |A to B path 3 . B to C path 1 . C to D path 2>
further, if each step in the pathway has a weight, a coefficient, then the full pathway will have the weight of the multiple of the weights for each step.
see also:
smerge
Home