[Previous] [Next] [Contents]

Type::Predicate -- a type for testing object satisfying a given predicate

Introduction

Type::Predicate(predicate) represents the MuPAD objects which satisfy the predicate predicate.

Call(s)


testtype(obj, Type::Predicate( <name,> predicate <, p1, p2, ...>))

Parameters

name- 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

Returns

see testtype

Related Functions

testtype

Details

Example 1

We 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'
        

Changes

[Previous] [Next] [Contents]


MuPAD Combinat, an open source algebraic combinatorics package