general

is a toolbox that contains most of functions of general use that did not enter the standard library. Examples include the fact, choose, permutations operators, and so on

  • Alias to return the data value paired with an integer key in an associative table
    Pre/Post conds (key::isint)(table::isseqof:ispair) => (tt)
    Example alias:2:< < -1,35>,< 2,1..3>,< 5,41>,< 7,43>,< 18,44>> == < 1,2,3>

  • Assoc returns the pair whose key has smallest distance from the input key. Pairs
    are maintained in increasing key order
    Pre/Post conds (key::isint) => (ispair)
    Example alias:2:< < -1,35>,< 2,1..3>,< 5,41>,< 7,43>,< 18,44>> == < 2,1..3>

  • Bigger is a binary operator that returns the greater of arguments
    Pre/Post conds (pair::and ~ [ispair, lift:or:(AA:isseqof:< isnum, ischar, isstring>)]) => (or ~ [isnum,ischar,isstring])
    Example bigger:< -122,22E2> == 2200.0
    bigger:< John , Robert > == Robert

  • Biggest binary operator that returns the greatest of args values
    Pre/Post conds (args::lift:or:(AA:isseqof:< isnum, isfun, ismat, ispol>))
    => (or ~ [isnum,ischar,isstring])
    Example biggest:< 'fred', 'wilma', 'barney', 'lucy' > == 'wilma'

  • Cart returns the Cartesian product of two sequences
    Pre/Post conds (a,b::isseqof::tt) => (isseqof:ispair)
    Example cart:< < 1,2,3>,< 'a', 'b' >> ==
    < < 1, 'a' >,< 1, 'b' >,< 2, 'a' >,< 2, 'b' >,< 3, 'a' >,< 3, 'b' >>

  • Choose is a generator of binomial numbers
    Pre/Post conds (n,k::isnat) => (isintpos)
    Example 6 choose 2 == 15

  • Fact is a generator of the function n => n!
    Pre/Post conds (n::isnat) => (isintpos)
    Example fact:5 == 120

  • Filter used for filtering a sequence according to a predicate on elements
    Pre/Post conds (predicate::isfun)(sequence::isseq) => (isseq)
    Example filter:(LE:0):< -101,23,0,-37.02,0.1,84> == < 23,0.1,84>

  • In predicate to test the set-membership of element ∈ set
    Pre/Post conds (set::isseq)(element::tt) => (isbool)
    Example in:< a , e , i , o , u >: z == false

  • Iseven predicate to test if n is an even number
    Pre/Post conds (n::isint) => (isbool)
    Example iseven:13 == false

  • Isge binary predicate to test if b ≥ a in some suitable ordering
    Pre/Post conds (a,b::tt) => (isbool)
    Example isge:< Fred , Wilma > == true

  • Isgt binary predicate to test if b > a in some suitable ordering
    Pre/Post conds (a,b::tt) => (isbool)
    Example isgt:< Fred , Wilma > == true

  • Isle binary predicate to test if b ≠a in some suitable ordering
    Pre/Post conds (a,b::tt) => (isbool)
    Example isge:< Fred , Wilma > == false

  • Islt binary predicate to test if b < a in some suitable ordering
    Pre/Post conds (a,b::tt) => (isbool)
    Example isge:< Fred , Wilma > == false

  • Isnat unary predicate to test if a number n is a natural number. A natural number
    is any of the numbers 0, 1, 2, 3, . . .
    Pre/Post conds (n::isnum) => (isbool)
    Example isnat:-1233 == false

  • Isodd predicate to test if n is an odd number
    Pre/Post conds (n::isint) => (isbool)
    Example isodd:13 == true

  • Mean computes the arithmetic mean of a sequence seq of numbers
    Pre/Post conds (seq:isseqof:isnum) => (isnum)
    Example mean:< 10,22,5,16,4> == 57/5

  • Mk returns a 0D polyhedron starting from the coordinates of a point x ∈ IEd, d ≥ 1
    Pre/Post conds (x:ispoint) => (and ~ [ispol,c:eq:0 ~ dim])
    Example (c:eq:0 ~ dim):(mk:< 1,0,0,0>) == true

  • Mod binary operator that returns the remainder of the division of a by b
    Pre/Post conds (a,b::isnum) => (isnum)
    Example mod:< 13.5,9.2> == 4.3

  • Pascaltriangle returns the first n + 1 rows of the Pascal triangle of binomial
    numbers
    Pre/Post conds (n::isnat) => and ~ aa:(isseqof:isintpos)
    Example pascalTriangle:3 == < < 1>,< 1,1>,< 1,2,1>,< 1,3,3,1>>

  • Permutations returns the set of permutations of elements of the input seq
    Pre/Post conds (seq::isseqof:tt) => (and ~ aa:(isseqof:tt))
    Example permutations:< 1,2,3> ==
    < < 1,2,3>,< 1,3,2>,< 2,1,3>,< 2,3,1>,< 3,1,2>,< 3,2,1>>
    permutations:< a , b > == < < a , b >,< b , a >>

  • Powerset returns the powerset 2set of the input set
    Pre/Post conds (set::isseqof:tt) => (and ~ aa:(isseqof:tt))
    Example powerSet:< 1,2,3> == < < 1,2,3>,< 1,2>,< 1,3>,< 1>,< 2,3>,< 2>,< 3>,< >>

  • Progressivesum operator to compute the map {ai ∈ Num} => {bi =Pi
    j=1 aj}
    Pre/Post conds (input::isseqof:isnum) => (isseqof:isnum)
    Example ProgressiveSum:< 1,3,5,7,9,11> == < 1,4,9,16,25,36>

  • Q generalized alias for QUOTE, that is applicable to either numbers or sequences
    Pre/Post conds (params::and~[or~[isnum,isseqof:isnum],and~ aa:(c:neq:0)])
    => (and~[ispol,c:eq:< 1,1>~[dim,rn]])
    Example ispol:(q:1) == true; (ispol ~ q ~ ##:10):< 1,-2> == true

  • Rtail returns the input seq, but the last element
    Pre/Post conds (seq::isseqof:tt) => (isseqof:tt)
    Example rtail:< a , b , c , e > == < a , b , c >

  • Setand set intersection between the argument sequences
    Pre/Post conds (set a, set b::isseqof:tt) => (isseqof:tt)
    Example < id,11, Lucy ,12, Bart > setand < Bart , Homer ,11,id> ==
    < id,11, Bart >

  • Setdiff set difference between the argument sequences
    Pre/Post conds (set a, set b::isseqof:tt) => (isseqof:tt)
    Example < id,11, Lucy ,12, Bart > setdiff < Bart , Homer ,11,id> == < Lucy ,12>

  • Setor set union between the argument sequences
    Pre/Post conds (set a, set b::isseqof:tt) => (isseqof:tt)
    Example < id,11, Lucy ,12, Bart > setor < Bart , Homer ,11,id> == < Lucy ,12, Bart , Homer ,11,id>

  • Setxor symmetric difference (xor) between the argument sequences
    Pre/Post conds (set a, set b::isseqof:tt) => (isseqof:tt)
    Example < id,11, Lucy ,12, Bart > setxor < Bart , Homer ,11,id> == < Lucy ,12, Homer >

  • Sort merge-sort on numbers, characters and strings, with order depending on pred
    Pre/Post conds (pred::isfun)(seq::isseqof:tt) => (isseqof:tt)
    Example sort:isgt:< fred , wilma , barney , lucy > == < barney , fred , lucy , wilma >
    sort:greater:< 8,2,4,2,3,11,-5> == < 11,8,4,3,2,2,-5>

  • Smaller binary operator that returns the smaller argument (in a proper ordering!)
    Pre/Post conds (args::or~[ispairof:isnum,ispairof:isstring])
    => (or ~ [isnum,isstring])
    Example smaller:< -122,22E2> == -122
    smaller:< John , Robert > == John

  • Smallest returns the smallest element of the args input sequence
    Pre/Post conds (args::or~[isseqof:isnum,isseqof:isstring])
    => (or ~ [isnum,isstring])
    Example smallest:< fred , wilma , barney , lucy > == barney

  • Sqr unary operator that returns the square of the arg argument
    Pre/Post conds (arg::or ~ [isnum, isfun]) => (or ~ [isnum, isfun])
    Example sqr:sin:(PI/2) == (sin * sin):(PI/2) == 1.0
    sqr:4 == 16

  • Uk UnmaKe. Returns the point in IEd corresponding to a 0D geometric object
    Pre/Post conds (arg::and ~ [ispol,c:eq:0 ~ dim]) => (ispoint)
    Example (uk ~ embed:2 ~ mk):< 1,1,1> == < 1.0,1.0,1.0,0.0,0.0> 

PLaSM is Free Software and may be distributed under GNU LGPL