Type::Predicate --
a type for testing object satisfying a given predicate
IntroductionType::Predicate(predicate) represents the MuPAD objects which satisfy
the predicate predicate.
Call(s)
testtype(obj,
Type::Predicate( <name,> predicate <, p1, p2, ...>))
Parametersname | - | a string which will be used for pretty printing the type |
predicate | - | a function of one argument which can return TRUE,
FALSE or FAIL |
obj, p1, p2, ... | - | any MuPAD objects |
Returnssee testtype
Related Functions
Detailstesttype(obj, Type::Predicate( <name,> predicate
<, p1, p2, ...>)) test whether obj satisfies
predicate; that is it returns predicate(obj, opt1,
opt2, ...).Type::Predicate(predicate), Type::Predicate(name, predicate),
Type::Predicate(predicate <, p1, p2, ...>), and Type::Predicate(name,
predicate <, p1, p2, ...>) are respectively pretty
printed as Type::Predicate(predicate), Type::name,
Type::Predicate(p, p1, p2, ...), and
Type::name(p1, p2, ...).
Example 1We define a type which contains any MuPAD object:
>> t := Type::Predicate(x -> TRUE):
testtype(1, t), testtype(2, t), testtype(x, t)
TRUE, TRUE, TRUE
We define a type which contains all the MuPAD object which
are solution of (x-1)*(x+1)=0:
>> t := Type::Predicate(x -> bool((x - 1)*(x + 1) = 0)):
testtype(1, t), testtype(2, t), testtype(x, t)
TRUE, FALSE, FALSE
We define a type for partitions, that is decreasing lists of integers:
>> part :=
Type::Predicate(l -> _lazy_and(testtype(l, Type::ListOf(Type::Integer)),
bool(revert(sort(l)) = l))):
testtype(a, part), testtype([3, 6, 1], part), testtype([3, 2, 2], part)
FALSE, FALSE, TRUE
Using the naming facility is recommended to improve the readability of error messages:
>> part :=
Type::Predicate("Partition",
l -> _lazy_and(testtype(l, Type::ListOf(Type::Integer)),
bool(revert(sort(l)) = l))):
f := proc(p: part) begin end:
f(3);
Error: Wrong type of 1. argument (type 'Type::Partition' expec\
ted,
got argument '3');
during evaluation of 'f'
Type::Predicate is a new function
MuPAD Combinat, an open source algebraic combinatorics package