Package ptolemy.cg.lib.syntactic
Class SyntacticRank
- java.lang.Object
-
- ptolemy.cg.lib.syntactic.SyntacticRank
-
public class SyntacticRank extends java.lang.Object
This class represents the rank of a SyntacticTerm. The rank is composed of four positive numbers referring respectively to the number of forward outputs, reverse outputs, forward inputs, and reverse inputs to the term. The reverse i/o, while supported in this type has not been completely assigned semantics. Currently, the forward elements are only used to characterize the compositionality of terms under combinational operations. At the least, the reverse versions follow an analogy from tensor ranks in linear algebra, where forward ranks refer to vector spaces and reverse ranks to co-vector spaces. I might use this concept to codify reverse propagation of feedback edges against the feed-forward edges that constitute the acyclic component of a term.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Chris Shaver
- Pt.AcceptedRating:
- Red
- Pt.ProposedRating:
- Red (shaver)
-
-
Constructor Summary
Constructors Constructor Description SyntacticRank(int fi, int fo)
Construct a new forward rank.SyntacticRank(int fo, int ro, int fi, int ri)
Construct a new rank.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SyntacticRank
add(SyntacticRank a, SyntacticRank b)
Add the two ranks if possible, else return null.static SyntacticRank
add(SyntacticTerm a, SyntacticTerm b)
Add the ranks of two terms.static SyntacticRank
compose(SyntacticRank a, SyntacticRank b)
Compose two ranks if possible, else return null.static SyntacticRank
compose(SyntacticTerm a, SyntacticTerm b)
Compose the ranks of two terms.static SyntacticRank
contract(SyntacticRank a, int n)
Contract rank about a given number of input/output pairs.SyntacticRank
copy()
Copy a rank.int
forwardIn()
Get the forward input rank.int
forwardOut()
Get the forward output rank.java.lang.String
generateCode()
Generate code representation of rank.static java.lang.String
noCode()
Generate code representation for no rank information.SyntacticRank
product(SyntacticRank a)
Multiply with a given rank.static SyntacticRank
product(SyntacticRank a, SyntacticRank b)
Multiply two ranks.static SyntacticRank
product(SyntacticTerm a, SyntacticTerm b)
Multiply the ranks of two terms.SyntacticRank
quotent(SyntacticRank a)
Divide by given rank.int
reverseIn()
Get the reverse input rank.int
reverseOut()
Get the reverse output rank.
-
-
-
Constructor Detail
-
SyntacticRank
public SyntacticRank(int fo, int ro, int fi, int ri)
Construct a new rank. See the class description for an explanation of these ranks.- Parameters:
fo
- Forward output rank.ro
- Reverse output rank.fi
- Forward input rank.ri
- Reverse input rank.
-
SyntacticRank
public SyntacticRank(int fi, int fo)
Construct a new forward rank. Reverse ranks are set to 0. See the class description for an explanation of these ranks.- Parameters:
fo
- Forward output rank.fi
- Forward input rank.
-
-
Method Detail
-
copy
public SyntacticRank copy()
Copy a rank.- Returns:
- new copied rank.
-
forwardOut
public int forwardOut()
Get the forward output rank. See the class description for an explanation of these ranks.- Returns:
- forward output rank.
-
reverseOut
public int reverseOut()
Get the reverse output rank. See the class description for an explanation of these ranks.- Returns:
- reverse output rank.
-
forwardIn
public int forwardIn()
Get the forward input rank. See the class description for an explanation of these ranks.- Returns:
- forward input rank.
-
reverseIn
public int reverseIn()
Get the reverse input rank. See the class description for an explanation of these ranks.- Returns:
- reverse input rank.
-
generateCode
public java.lang.String generateCode()
Generate code representation of rank. The form of this representation is as follows:
<forward in (reverse out) -> forward out (reverse in)>
or, if the reverse components are 0:
<forward in -> forward out>- Returns:
- code representation of rank.
-
noCode
public static java.lang.String noCode()
Generate code representation for no rank information.- Returns:
- code representation of no rank.
-
compose
public static SyntacticRank compose(SyntacticRank a, SyntacticRank b)
Compose two ranks if possible, else return null. Ranks A and B can be composed if the number of forward outputs of B is equal to the number of forward inputs of A. If reverse connections exist, the number of reverse outputs of B must be equal to the number of reverse inputs of A. (Note that this order is in fact opposite of the forward case since reverse connections form in the opposite direction.) Note that this composition operation should be interpreted as the first rank going into the second rank, rather than the first rank operating on the second as in function composition notation.- Parameters:
a
- First rank.b
- Second rank.- Returns:
- composition of first and second rank.
-
compose
public static SyntacticRank compose(SyntacticTerm a, SyntacticTerm b)
Compose the ranks of two terms.- Parameters:
a
- First term.b
- Second term.- Returns:
- composition of the ranks of the first and second term.
- See Also:
compose(ptolemy.cg.lib.syntactic.SyntacticRank, ptolemy.cg.lib.syntactic.SyntacticRank)
-
add
public static SyntacticRank add(SyntacticRank a, SyntacticRank b)
Add the two ranks if possible, else return null. Ranks are only able to be added if they are the same, and the result is simply the same rank as the operands. A copy is returned. This is a operation rather than just a check for purposes of modularity. An operation adding terms can call this to be symmetric with other operations.- Parameters:
a
- First rank.b
- Second rank.- Returns:
- sum of first and second ranks.
-
add
public static SyntacticRank add(SyntacticTerm a, SyntacticTerm b)
Add the ranks of two terms.- Parameters:
a
- First term.b
- Second term.- Returns:
- sum of the ranks of the first and second terms.
- See Also:
add(SyntacticRank, SyntacticRank)
-
product
public static SyntacticRank product(SyntacticRank a, SyntacticRank b)
Multiply two ranks. This is always possible, following the analogy from tensor products. The product is simply the element-wise sum of the ranks.- Parameters:
a
- First rank.b
- Second rank.- Returns:
- product of ranks.
-
product
public static SyntacticRank product(SyntacticTerm a, SyntacticTerm b)
Multiply the ranks of two terms.- Parameters:
a
- First term.b
- Second term.- Returns:
- product of the ranks of first and second term.
-
contract
public static SyntacticRank contract(SyntacticRank a, int n)
Contract rank about a given number of input/output pairs. This is possible when the number of contracted pairs are fewer than then smaller of the numbers of inputs and outputs.- Parameters:
a
- Rank to contract.n
- Number of contractions.- Returns:
- Contracted rank or null if not possible.
-
product
public SyntacticRank product(SyntacticRank a)
Multiply with a given rank.- Parameters:
a
- Rank to multiply by.- Returns:
- reference to this.
- See Also:
product(SyntacticRank, SyntacticRank)
-
quotent
public SyntacticRank quotent(SyntacticRank a)
Divide by given rank. Division is simply point-wise subtraction in this case.- Parameters:
a
- Divisor rank.- Returns:
- reference to this.
- See Also:
product(SyntacticRank, SyntacticRank)
-
-