manual:chapter3:symbolic

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:46]
claudio [Attributes]
manual:chapter3:symbolic [2021/03/22 13:52] (current)
claudio [Using rules and attributes, examples]
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 indeed a real number and it cannot be zero, allowing the rules to perform the desired simplifications. Attributes can simply be typed immediately after the variable name enclosed by colonsFollowing with the previous example ''%%'%%A:R>0:%%'%%'' is an identifier representing variable ''A''but it includes a hint showing that ''A'' is a finite positive real value and cannot be zero. If that hint is included wherever ''A'' is used within the expressionthe system will know that ''%%'%%A*B*INV(A)%%'%%'' can be safely simplified to ''%%'%%B%%'%%''.
  
-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.+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. Ideally, the user should provide the same attributes to the same variables all throughout the expression (in other words, assumptions about a variable must be consistent, the variable cannot represents different things in different parts of the same expression). 
 + 
 +The simplest way to assure the attributes are used consistently is using the command ''ASSUME''. For example ''%%'%%X^2+3*X%%'%% %%'X:R>0:'%% ASSUME'' will replace all occurrences of ''X'' within the given expression with the new identifier that includes the attributes. After the ''ASSUME'' command, trying to edit the expression will reveal the attributes: ''%%'%%X:R>0:^2+3*X:R>0:%%'%%'' which may make the expression more difficult to read. To remove the attributes, simply use an identifier without any attributes as the second argument: ''%%'%%X^2+3*X%%'%% %%'X'%% ASSUME'' will replace all occurrences of ''X'' with the new identifier which makes no assumptions (no attributes included). 
 + 
 +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:R≠0:/.xX:R≠0::->1%%'%%'' and now it will only match expressions that are known to be real and are known not to be zero.
  
 === Default attributes === === Default attributes ===
Line 68: Line 72:
  
 === 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). 
-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 digit provides hints about the type of variable: +The syntax for attributes is intuitive but very strict. Trying to enter invalid attributes will result in syntax error.
-^ First digit 't' (type): || +
-^ 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/NaN | +
-| 4 | Variable is known to be complex | +
-| 5 | Variable is known to be complex, may be infinity/NaN | +
-| 6 | Variable is known to be 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.+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.)
  
-Second digit 's' (sign): ||+First one or two characters (type): ||
 ^ Value ^ Meaning ^ ^ Value ^ Meaning ^
-((Will be removed/omitted)) | Nothing is known about the sign or range of this value +''*'' ((Will be automatically removed)) | Nothing is known about this variable 
-Value is known not to be zero ((This is valid for real AND complex numbers)) | +''R∞'' Variable is known to be real, may be infinite | 
-Value is known not to be < 0 (therefore it's >=0) | +| ''R'' | Variable is known to be real (and finite) | 
-Value is known not to be < 0 and not to be zero (therefore it's >0) | +''Z'' Variable is known to be integer (and finite) | 
-Value is known not to be > 0 (therefore it's <=0) | +''Z∞'' Variable is known to be integer, may be infinite | 
-Value is known not to be > 0 and not to be zero (therefore it's <0) |+| ''O'' | Variable is known to be integer and odd (and finite) | 
 +''E'' Variable is known to be integer and even (and finite) | 
 +''C∞'' Variable is known to be complex, may be infinite | 
 +| ''C'' | Variable is known to be complex (and finite) | 
 +''M'' | Variable is known to be a matrix | 
 +| ''?'' ((Internal use only)) | Variable is known to be of unknown type |
  
-^ Third digit 'p(parity): ||+Notice that some combinations above are not valid, for example ''E∞'' is not valid since infinity cannot be odd or even. Also a matrix cannot be infinite. 
 + 
 +^ Optional subset: ||
 ^ Value ^ Meaning ^ ^ Value ^ Meaning ^
-| 0 | ((Will be removed/omitted)) | Nothing is known regarding parity of this value +''0'' Value is known not to be zero ((This is valid for real AND complex numbers)) | 
-| Value if known to be an integer +| ''≥0'' | Value is known not to be negative (therefore it's >=0) 
-| Value is known to be odd +''>0'' | Value is known not to be negative and not to be zero (therefore it's >0) 
-| Value is known to be an odd integer +''≤0'' | Value is known not to be positive (therefore it's ≤0) 
-| 4 | Value is known to be even +''<0'' | Value is known not to be positive and not to be zero (therefore it's <0) | 
-Value is known to be an even integer |+ 
 +The subsets above are only applicable to real numbers and integers, with the exception of ''≠0'' which also applies to complex numbers. Other types cannot have subsets (for example, cannot define what's a positive complex, or a negative matrix). 
 + 
 +==== Using rules and attributes, examples ==== 
 + 
 +Here are a few examples where using attributes is useful to decide whether to apply a rule or not. 
 + 
 +^ Rule ^ Effect ^ 
 +| ''%%'%%ABS(.xX:R∞≥0:):->.xX:R∞≥0:%%'%%'' | Simplify absolute value of an expression that is known to be real ≥0 
 +''%%'%%ABS(.xX:R∞<0:):->-.xX:R∞<0:%%'%%'' | Simplify absolute value of an expression that is known to be real <0 | 
 + 
 +The above rules, for example, it can be applied to expressions with different attributes in its variables giving different results: 
 + 
 +^ Test cases ^ Result ^ Explanation ^ 
 +| ''Y*ABS(X)'' | ''Y*ABS(X)'' | No rules are applied because X doesn't fit within the subsets defined in the rules | 
 +| ''Y*ABS(X:R>0:)'' | ''Y*X'' | The expression matches the first rule because ''X'' is known to be a real >0 | 
 +| ''Y*ABS(-4)'' ''Y*(-(-4))'' | The expression matches the second rule because ''-4'' is known to be a real <0 
 +''Y*ABS(X:R>0:+1)'' ''Y*(X+1)'' | The expression matches the first rule because ''X+1'' is known to be a real >0 | 
 +| ''Y*ABS(X:R>0:-1)'' | ''Y*ABS(X-1)'' | The expression doesn't match either rule because ''X-1'' could be <0 for 0<x<1 | 
 +| ''Y*ABS%%((X:R>0:-1)%%^2)'' | ''Y*(X-1)^2'' | The expression matches because ''(X-1)^2'' is known to be >=0 | 
 +| ''Y*ABS%%((X-1)%%^2)'' | ''Y*(X-1)^2'' | The expression matches because ''(X-1)^2'' is known to be >=0 regardless of X | 
 + 
  
  
  
 ---- ----
  • manual/chapter3/symbolic.1548348407.txt.gz
  • Last modified: 2019/01/24 08:46
  • by claudio