This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Type for testing object satisfying a given predicate

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


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


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


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 :=
                    l -> _lazy_and(testtype(l, Type::ListOf(Type::Integer)),
                                   bool(revert(sort(l)) = l))):
f := proc(p: part) begin end:
Error: Invalid object '3'. Type of argument number 1 must be 'Type::Partition'.
  Evaluating: f



A string which will be used for pretty printing the type


A function of one argument which can return TRUE, FALSE or FAIL

obj, p1, p2, …

Any MuPAD objects

Return Values

See testtype

See Also

MuPAD Functions

Was this topic helpful?