Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter3:symbolic [2019/01/24 08:12]
claudio [Attributes]
manual:chapter3:symbolic [2019/01/30 06:02] (current)
claudio [Attributes]
Line 11: Line 11:
 Expressions can be manipulated in various ways: Expressions can be manipulated in various ways:
  
-**Normal operations using the stack:** ''​%%'​%%X+1%%'​%%''​ ''​2''​ ''​*''​ will produce the expression ''​%%'​%%(X+1)*2%%'​%%''​ as expected. The result of operations involving expressions is always an expression. No other processing is performed, the expression remains as the user input, for example: ''​%%'​%%(X+1)*2%%'​%%''​ ''​2''​ ''/''​ will produce ''​%%'​%%((X+1)*2)/​2%%'​%%''​.+**Normal operations using the stack:** ''​%%'​%%X+1%%'​%%''​ ''​2''​ ''​*''​ will produce the expression ''​%%'​%%(X+1)*2%%'​%%''​ as expected. The result of operations involving expressions is always an expression. No other processing is performed, the expression remains as the user input, for example: ''​%%'​%%(X+1)*2%%'​%%''​ ''​2''​ ''/''​ will produce ''​%%'​%%%%((%%X+1)*2)/​2%%'​%%''​.
  
 **Evaluating the expression:​** Using the commands ''​EVAL1'',​ ''​EVAL''​ and ''​->​NUM''​ will replace the contents of any variables that exist in the current directory (or upper) or as local variables while running a program, into the expression. The behavior of each command is only slightly different: **Evaluating the expression:​** Using the commands ''​EVAL1'',​ ''​EVAL''​ and ''​->​NUM''​ will replace the contents of any variables that exist in the current directory (or upper) or as local variables while running a program, into the expression. The behavior of each command is only slightly different:
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 ''​VAR''​ is used as an example and can be substituted freely. 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 ''​VAR''​ is used as an example and can be substituted freely.
    
-Wildcard ​Meaning ​|+Wildcard ​Meaning ​^
 | ''​.iVAR''​ | Match a single integer number | | ''​.iVAR''​ | Match a single integer number |
 | ''​.oVAR''​ | Match a single odd integer number | | ''​.oVAR''​ | Match a single odd integer number |
Line 46: Line 46:
 For examples on the use of wildcards, let's use the expression ''​%%'​%%√3*X^2+2.5*X+5*X*Y+(A+B)*Y^2%%'​%%''​ and apply some rules to it using ''​RULEAPPLY'':​ For examples on the use of wildcards, let's use the expression ''​%%'​%%√3*X^2+2.5*X+5*X*Y+(A+B)*Y^2%%'​%%''​ and apply some rules to it using ''​RULEAPPLY'':​
  
-Rule Result ​Why? |+Rule Result ​Why? ^
 | ''​%%'​%%X^.iN:​->​Z^.iN%%'​%%''​ | ''​%%'​%%√3*Z^2+2.5*X+5*X*Y+(A+B)*Y^2%%'​%%''​ | Only the first term has the form ''​X^i''​ | | ''​%%'​%%X^.iN:​->​Z^.iN%%'​%%''​ | ''​%%'​%%√3*Z^2+2.5*X+5*X*Y+(A+B)*Y^2%%'​%%''​ | Only the first term has the form ''​X^i''​ |
 | ''​%%'​%%.vX^.iN:​->​Z^.iN%%'​%%''​ | ''​%%'​%%√3*Z^2+2.5*X+5*X*Y+(A+B)*Z^2%%'​%%''​ | The variable wildcard ''​.vX''​ matches both ''​X''​ and ''​Y''​ and makes 2 replacements. Because we used ''​RULEAPPLY'',​ it tries again and then matches ''​Z''​ and replaces it in 2 places, reporting 4 total changes after stopping due to the expression not changing | | ''​%%'​%%.vX^.iN:​->​Z^.iN%%'​%%''​ | ''​%%'​%%√3*Z^2+2.5*X+5*X*Y+(A+B)*Z^2%%'​%%''​ | The variable wildcard ''​.vX''​ matches both ''​X''​ and ''​Y''​ and makes 2 replacements. Because we used ''​RULEAPPLY'',​ it tries again and then matches ''​Z''​ and replaces it in 2 places, reporting 4 total changes after stopping due to the expression not changing |
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 ''​A''​ and ''​B''​ in the expression ''​%%'​%%A*B*INV(A)%%'​%%''​ represent a matrix, the system should not simplify that expression to ''​%%'​%%B%%'​%%''​. Furthermore,​ if ''​A''​ and ''​B''​ are real numbers, the simplification is only valid when ''​A''​ is known not to be zero. 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 ''​A''​ and ''​B''​ in the expression ''​%%'​%%A*B*INV(A)%%'​%%''​ represent a matrix, the system should not simplify that expression to ''​%%'​%%B%%'​%%''​. Furthermore,​ if ''​A''​ and ''​B''​ are real numbers, the simplification is only valid when ''​A''​ is known not to be zero.
  
-Attributes allow the user to let the system know that ''​A''​ is a real number and it cannot be zero. To add attributes to a variable, simply add a combination of subscript numbers after the variable name. For example, if ''​A''​ is a real number known not to be zero, simply write ''​A₂₁''​ in the expression (the exact meaning of the numbers will be explained in the next section). 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 allow the user to let the system know that ''​A''​ is a real number and it cannot be zero. To add attributes to a variable, simply add a combination of subscript numbers after the variable name. For example, if ''​A''​ is a real number known not to be zero, simply write ''​A₂₁''​ in the expression (the exact meaning of the numbers will be explained in the next section). 
 + 
 +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: ''​%%'​%%.xX/​.xX:​->​1%%'​%%''​. But this is not correct if the expression being canceled may be zero. Using attributes, we can write ''​%%'​%%.xX₂₁/​.xX₂₁:​->​1%%'​%%''​ and now it will only match expressions that are known to be real and are known not to be zero. 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: ''​%%'​%%.xX/​.xX:​->​1%%'​%%''​. But this is not correct if the expression being canceled may be zero. Using attributes, we can write ''​%%'​%%.xX₂₁/​.xX₂₁:​->​1%%'​%%''​ and now it will only match expressions that are known to be real and are known not to be zero.
Line 68: Line 70:
  
 === Encoding of attributes === === Encoding of attributes ===
 +
 Attributes can be any number of up to 8 decimal digits. The value of zero is reserved for 'no attributes'​ and will be automatically removed from the variables. The newRPL algebraic engine uses only 3 digits (other digits may or may not be used in the future). Attributes can be any number of up to 8 decimal digits. The value of zero is reserved for 'no attributes'​ and will be automatically removed from the variables. The newRPL algebraic engine uses only 3 digits (other digits may or may not be used in the future).
 +
 The first 3 digits will be referred to as '​t'​ (for type), '​s'​ (sign) and '​p'​ (parity) from now on. They go after a variable in '​tsp'​ order, and trailing zeros can be omitted. The first 3 digits will be referred to as '​t'​ (for type), '​s'​ (sign) and '​p'​ (parity) from now on. They go after a variable in '​tsp'​ order, and trailing zeros can be omitted.
  
-First digit '​t':​ || +The first digit provides hints about the type of variable: 
-| Value | Meaning |+First digit '​t' ​(type): || 
 +^ Value ^ Meaning ^ 
 +0 ((Will be automatically removed)) | Nothing is known about this variable | 
 +| 1 | Variable known to be finite (cannot be infinity or NaN) | 
 +| 2 | Variable is known to be real, may be infinity/​NaN | 
 +| 3 | Variable is known to be real (and finite) | 
 +| 4 | Variable is known to be complex, may be infinity/​NaN | 
 +| 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. 
 + 
 +^ Second digit '​s'​ (sign): || 
 +Value ^ Meaning ^ 
 +0 ((Will be removed/​omitted)) | Nothing is known about the sign or range of this value | 
 +| 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 '​s'​ digit, this is only meaningful for real values. 
 + 
 +^ Third digit '​p'​ (parity): || 
 +^ Value ^ Meaning ​
 +0 ((Will be removed/​omitted)) | Nothing is known regarding parity of this value | 
 +| 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 ^ 
 +| ''​%%'​%%ABS(.xX₂₂):​->​.xX%%'​%%''​ | Simplify absolute value of an expression that is known to be real >=0 | 
 + 
 +^ Test cases ^ Result ^ Explanation ^ 
 +| ''​Y*ABS(X₂₃)''​ | ''​Y*X₂₃''​ | The expression matches because ''​X''​ is known to be a real >0 | 
 +| ''​Y*ABS(-4)''​ | ''​Y*ABS(-4)''​ | The expression doesn'​t match because ''​-4''​ is known to be a real <0 | 
 +| ''​Y*ABS(X₂₃+1)''​ | ''​Y*(X₂₃+1)''​ | The expression matches because ''​X+1''​ is known to be a real >0 | 
 +| ''​Y*ABS(X₂₃-1)''​ | ''​Y*ABS(X₂₃-1)''​ | The expression doesn'​t match because ''​X-1''​ could be <0 for 0<x<1 | 
 +| ''​Y*ABS%%((X₂₃-1)%%^2)''​ | ''​Y*(X₂₃-1)^2''​ | The expression matches because ''​(X-1)^2''​ is known to be >=0 | 
 + 
  
  
  
 ---- ----
  • manual/chapter3/symbolic.1548346360.txt.gz
  • Last modified: 2019/01/24 08:12
  • by claudio