Type::Predicate

Type for testing object satisfying a given predicate

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

```testtype(`obj`, Type::Predicate(<`pname`>, `predicate`, <`p1, p2, …`>))
```

Description

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

The call ```testtype(obj, pname, Type::Predicate(< pname >, predicate , < p1 , p2 >))``` test whether `obj` satisfies `predicate`; that is it returns `predicate(obj, p1, p2, ...)`.

`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, ...)`.

Examples

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)```

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)```

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)```

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: The object '3' is incorrect. The type of argument number 1 must be 'Type::Partition'. Evaluating: f ```

Parameters

 `pname` 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