embed a predicate as a structured type
type(expr, 'satisfies'(P1, P2, ... ))
P1, P2, ...
The type satisfies provides a mechanism for embedding arbitrary predicates in Maple's type system. It enables you to define a structured type corresponding to an arbitrary predicate without having to pollute the type namespace. This is helpful when used in conjunction with the few Maple facilities (such as the two-argument form of indets) that accept types, but not arbitrary predicates.
An expression expr is of type satisfies(P1, P2, ...) if all Pk(expr) evaluate to true, or to And, Or, Xor, Implies, Not constructions that, when converted to their corresponding boolean operators (and, or, xor, implies, not; see convert/boolean_operator), evaluate to true. Also all Pk(expr) are expected to evaluate to either true or false, or to And, Or, Xor, Implies, Not constructions with those meanings.
Type satisfies is always used as a structured type with at least one parameter. The function type(expr, 'satisfies'(P)) evaluates to true if the expression expr satisfies the predicate P. More than one predicate P1, P2, ... can be supplied, in which case the expression expr must satisfy all of the predicates P1, P2, ....
Type satisfies evaluates the Pk(expr) in the order supplied until an expression evaluates to false. Then the type(expr, 'satisfies'(P1, P2, ...) call returns false. If no predicate returns false, then the value true is returned.
Predicates are expected to return normally, without raising exceptions. You can use the ordered evaluation of the predicates to test that any preconditions for error-free evaluations are met. See Example 3.
Use this type to filter conditions when computing objects of certain type:
All the functions
Only the functions having y
Only the functions having y and not having z
Use this mechanism to introduce local types within module or procedure bodies. Note that NumberTheory[IsSquareFree] returns true or false when applied to some arguments
m ≔ moduleexportsqrfree;sqrfree ≔ 'satisfies'⁡x→type⁡x,'odd',NumberTheory['IsSquareFree']end module:
Observe that, unlike global type names, which should always be quoted to protect against unwanted evaluation, a local type defined in this way must not be quoted.
For example, the following example cannot have quotes, that is, 'm:−sqrfree'.
The global space of names (including the global name sqrfree) remains distinct and so the definition of type m:-sqrfree does not imply the existence of a sqrfree type
Error, type `sqrfree` does not exist
Giving predicates in certain order, they are evaluated in that order
While constructing predicates (the procedures testing whether a condition is satisfied), the condition being tester may lead to an error, for example, because the test produces a division by zero.
Error, (in unknown) numeric exception: division by zero
You can prevent these situations adding more predicates, taking care of the exceptional cases before the predicate which returns an error is considered
You can use And, Or, Xor, Implies, Not constructions to make them more readable or to have full control of the evaluation rules when constructing your types - these constructions do not automatically evaluate to true or false.
condition ≔ f→And⁡type⁡f,function,Not⁡hastype⁡fⅇ,function
Download Help Document
What kind of issue would you like to report? (Optional)