Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
manual:chapter3:symbolic [2019/01/24 07:57] claudio |
manual:chapter3:symbolic [2019/01/24 10:14] claudio [Using rules and attributes, examples] |
||
---|---|---|---|
Line 11: | Line 11: | ||
Expressions can be manipulated in various ways: | Expressions can be manipulated in various ways: | ||
- | **Normal operations using the stack:** '' | + | **Normal operations using the stack:** '' |
**Evaluating the expression: | **Evaluating the expression: | ||
Line 32: | Line 32: | ||
The usefulness of rules only becomes evident when wildcards are used. Wildcards are special variable names that will match different objects. The rules engine recognizes wildcards by the 2 first characters of the variable name. All wildcards start with a dot, and the character that follows indicates what type of wildcard it is (what objects it will match). Other characters are an arbitrary name assigned by the user. In the table below the name '' | The usefulness of rules only becomes evident when wildcards are used. Wildcards are special variable names that will match different objects. The rules engine recognizes wildcards by the 2 first characters of the variable name. All wildcards start with a dot, and the character that follows indicates what type of wildcard it is (what objects it will match). Other characters are an arbitrary name assigned by the user. In the table below the name '' | ||
- | | Wildcard | + | ^ Wildcard |
| '' | | '' | ||
| '' | | '' | ||
Line 46: | Line 46: | ||
For examples on the use of wildcards, let's use the expression '' | For examples on the use of wildcards, let's use the expression '' | ||
- | | Rule | Result | + | ^ Rule ^ Result |
| '' | | '' | ||
| '' | | '' | ||
Line 59: | Line 59: | ||
Attributes are hints that the user can include in an expression to increase the knowledge that the system has about certain variables. For example, if variables '' | Attributes are hints that the user can include in an expression to increase the knowledge that the system has about certain variables. For example, if variables '' | ||
- | Attributes allow the user to the system know that '' | + | Attributes allow the user to let the system know that '' |
+ | |||
+ | 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: '' | 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 ^ | ||
+ | | 0 ((Will be automatically removed)) | Nothing is known about this variable | | ||
+ | | 1 | Variable may be infinity or NaN | | ||
+ | | 2 | Variable is known to be real | | ||
+ | | 3 | Variable is known to be real, may be infinity/ | ||
+ | | 4 | Variable is known to be complex | | ||
+ | | 5 | Variable is known to be complex, may be infinity/ | ||
+ | | 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. | ||
+ | |||
+ | ^ Second digit ' | ||
+ | ^ 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's <=0) | | ||
+ | | 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 of the number, and whether a real is an integer or not. Much like the ' | ||
+ | |||
+ | ^ Third digit ' | ||
+ | ^ 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 | | ||
+ | |||
+ | |||
+ | ==== Using rules and attributes, examples ==== | ||
+ | |||
+ | ^ Rule ^ Effect ^ | ||
+ | | '' | ||
+ | |||
+ | ^ Test cases ^ Result ^ Explanation ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | |||
---- | ---- |