Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
manual:chapter3:symbolic [2021/03/22 08:58] claudio |
manual:chapter3:symbolic [2021/03/22 13:52] (current) claudio [Using rules and attributes, examples] |
||
---|---|---|---|
Line 75: | Line 75: | ||
The syntax for attributes is intuitive but very strict. Trying to enter invalid attributes will result in a syntax error. | The syntax for attributes is intuitive but very strict. Trying to enter invalid attributes will result in a syntax error. | ||
+ | Attribute strings consist of: | ||
+ | * One or two characters indicating the content type of the variable (real, complex, matrix, etc.) | ||
+ | * Optional two characters indicating a subset of the field (positive only, negative only, non-zero, etc.) | ||
- | + | ^ First one or two characters | |
- | ==== Obsolete section - soon to be removed ==== | + | |
- | + | ||
- | To add attributes to a variable, simply add a combination of subscript numbers after the variable name. For example, if '' | + | |
- | + | ||
- | Notice that these attributes are only visible when editing the expression. Once the expression is in the stack, only the name of the variable will be visible, as the subscript numbers don't become part of the name of the variable. Ideally, the user should provide the same attributes to the same variables all throughout the expression (otherwise the system will think the variable represents different things in different parts of the same expression). | + | |
- | + | ||
- | Attributes are also useful within rules. If a variable (or wildcard special variable) has any attributes given within a rule definition, it will only match variables (or expressions) that have compatible attributes. For example a rule to cancel out factors in an expression could be: '' | + | |
- | + | ||
- | === Default attributes === | + | |
- | + | ||
- | Variables that aren't given any attributes are by default assumed to be real if complex mode is disabled, and complex if complex mode is enabled. No other assumptions are made about their value (could be in any range, could be zero or infinite, etc.). | + | |
- | + | ||
- | === Encoding of attributes === | + | |
- | + | ||
- | Attributes can be any number of up to 8 decimal digits. The value of zero is reserved for 'no attributes' | + | |
- | + | ||
- | The first 3 digits will be referred to as ' | + | |
- | + | ||
- | The first digit provides hints about the type of variable: | + | |
- | ^ First digit ' | + | |
^ Value ^ Meaning ^ | ^ Value ^ Meaning ^ | ||
- | | 0 ((Will be automatically removed)) | Nothing is known about this variable | | + | | '' |
- | | 1 | Variable known to be finite | + | | '' |
- | | 2 | Variable is known to be real, may be infinity/ | + | | '' |
- | | 3 | Variable is known to be real (and finite) | | + | | '' |
- | | 4 | Variable is known to be complex, may be infinity/ | + | | '' |
- | | 5 | Variable is known to be complex (and finite) | | + | | '' |
- | | 6 | Variable is known to be a matrix | | + | | '' |
- | | 8 ((Internal use only)) | Variable is known to be of unknown type | | + | | '' |
+ | | '' | ||
+ | | '' | ||
+ | | ''?'' | ||
- | The second digit provides insight about the sign and range of values. It is meaningful only for real numbers (except for the zero hint), other types don't need or use this digit. | + | Notice that some combinations above are not valid, for example |
- | ^ Second digit ' | + | ^ Optional subset: || |
^ Value ^ Meaning ^ | ^ Value ^ Meaning ^ | ||
- | | 0 ((Will be removed/ | + | | '' |
- | | 1 | Value is known not to be zero ((This is valid for real AND complex numbers)) | | + | | '' |
- | | 2 | Value is known not to be < 0 (therefore it's >=0) | | + | | ''> |
- | | 3 | Value is known not to be < 0 and not to be zero (therefore it's >0) | | + | | '' |
- | | 4 | Value is known not to be > 0 (therefore it' | + | | ''< |
- | | 5 | Value is known not to be > 0 and not to be zero (therefore it's <0) | | + | |
- | The third digit provides insight about the parity | + | The subsets above are only applicable to real numbers and integers, with the exception |
- | ^ Third digit ' | + | ==== Using rules and attributes, examples ==== |
- | ^ Value ^ Meaning ^ | + | |
- | | 0 ((Will be removed/ | + | |
- | | 1 | Value if known to be an integer | | + | |
- | | 2 | Value is known to be odd | | + | |
- | | 3 | Value is known to be an odd integer | | + | |
- | | 4 | Value is known to be even | | + | |
- | | 5 | Value is known to be an even integer | | + | |
+ | Here are a few examples where using attributes is useful to decide whether to apply a rule or not. | ||
- | ==== Using rules and attributes, examples ==== | + | ^ Rule ^ Effect ^ |
+ | | '' | ||
+ | | '' | ||
- | ^ Rule ^ Effect ^ | + | The above rules, for example, it can be applied to expressions with different attributes in its variables giving different results: |
- | | '' | + | |
^ Test cases ^ Result ^ Explanation ^ | ^ Test cases ^ Result ^ Explanation ^ | ||
- | | '' | + | | '' |
- | | '' | + | | '' |
- | | '' | + | | '' |
- | | '' | + | | '' |
- | | '' | + | | '' |
+ | | '' | ||
+ | | '' | ||