getprop -- query properties of
expressions
Introductiongetprop(f) returns a mathematical property
of the expression f.
Call(s)getprop(f)
getprop()
Parametersf |
- | an arithmetical expression |
Returnsgetprop(f) returns a property of type
Type::Property, or the
expression f itself. The call
getprop() returns a property or the
identifier Global.
Related
Functionsassume, is, property::hasprop, Type::Property, unassume
Detailsassume allows to attach basic
properties (``assumptions'') such as 'x is a real number'
or 'x is an odd integer' to an identifier x,
say. Arithmetical expressions involving x may inherit such
properties. E.g., '1 + x^2 is positive' if 'x
is a real number'.
getprop(f) examines the properties of all
identifiers in the expression
f and derives a property of f.
See the property library for a
description of all available properties.
getprop returns the expression itself. In particular, if
f is an identifier without properties, then the result is
again f. Cf. example 2.
An exception to this rule is the case where f involves
one of the special functions abs, Re, or Im with symbolic arguments. Independent
of the argument, these function values always represent real numbers,
which may give rise to a property of the whole expression
f. Cf. example 4.
getprop() returns the current
``global property''. See assume for details on setting global
properties.
The protected identifier Global is used to store global
properties. If no global property is set, the identifier
Global is returned. Cf. example 3.
getprop performs certain
simplifications during the derivation of a property for an expression.
Thus it may happen that getprop derives a property that is
weaker than the most specific property that can be derived
mathematically. Cf. example 5.is matches
the properties of an expression with a given property.
Example
1If x is an integer, then x^2 +
1 must be a positive integer number:
>> assume(x, Type::Integer): getprop(x^2 + 1)
Type::PosInt
If x represents a number in the interval
[1, infinity[, the expression 1 - x has the
following property:
>> assume(x, Type::Interval([1], infinity)): getprop(1 - x)
]-infinity, 0] of Type::Real
>> unassume(x):
Example
2An expression is returned unchanged if it is constant, or if no properties are attached to the identifiers involved:
>> getprop(x), getprop(x + 2*y), getprop(sin(3))
x, x + 2 y, sin(3)
Example
3Properties that are assumed for all identifiers are
stored in the global variable Global. Presently, no global
property is set:
>> getprop()
Global
In the following, a global property is set. Now, all identifiers have this property:
>> assume(Type::Real): getprop(x), getprop(y), getprop((x + y)^2 + 1/2)
Type::Real, Type::Real, Type::Positive
The functions getprop and is combine the global property and the
properties of individual identifiers with the logical ``and'':
>> assume(Type::Positive): assume(x, Type::Integer): getprop(x)
Type::PosInt
The global property may contradict the individual
properties. In this case the ``empty property'' property::Null is returned:
>> assume(Type::Positive): assume(x < 0): getprop(x)
property::Null
>> delete x: unassume():
Example
4The functions abs, Re, and Im have a ``minimal property'': they
produce real values. In fact, abs produces nonnegative real
values:
>> delete x: getprop(abs(x)), getprop(Re(x)), getprop(Im(x))
Type::NonNegative, Type::Real, Type::Real
Example
5The set containing the squares of all prime numbers
cannot be represented by one of the properties available in the Type library. Therefore,
getprop returns the weaker property 'x^2 is a
positive integer':
>> assume(x, Type::Prime): getprop(x^2)
Type::PosInt
>> unassume(x):