%==================================
Recursive simplex of any dimension and depth ==================================%
DEF MediumPoint = AA:Half ~ TRANS
WHERE
Half = / ~ [ID,K:2] ~ +
END;
%---------------------------------- Transforms point sequences in E^n into a new sequence
----------------------------------%
DEF component (i::IsIntPos; seq::IsSeq) = CAT: < firstPart, <pivot>, lastPart >
WHERE
firstSeq = AS:SEL:(1..(i - 1)): seq,
pivot = SEL:i:seq,
lastSeq = AS:SEL:((i + 1).. LEN:seq): seq,
firstPart = (AA:MediumPoint ~ DISTR): <firstSeq,pivot>,
lastPart = (AA:MediumPoint ~ DISTR): <lastSeq,pivot>
END;
%------------------------------------ Black box to transform an UnPacked
n-simplex into a sequence of di n+1 UnPacked simplexes
------------------------------------%
DEF Expand (unpackedSimplex::IsSeq) = (AA:AL ~ DISTR):<newVertLists, <cells,pols>>
WHERE
verts = s1:unpackedSimplex,
cells = s2:unpackedSimplex,
pols = s3:unpackedSimplex,
indices = 1..LEN:verts,
newVertLists = AA:component:(DISTR:<indices,verts>)
END;
%----------------------------------Recursive simplex in FL-style (nor recursion neither iteration but via stream processing)
----------------------------------%
DEF RecursiveSimplex (dim, depth::IsIntPos) =
(MkStruct ~ Splitting ~ unpackSimplex):dim
WHERE
MkStruct = @2 ~ STRUCT ~ AA:MKPOL,
Splitting = (COMP ~ #:depth):(CAT ~ AA:Expand),
unpackSimplex = LIST ~ UKPOL ~ SIMPLEX
END;
% 3D Example ---------------------- RecursiveSimplex:<2,5>; 2D Example -----------------------%
RecursiveSimplex:<3,3>;