next up previous contents index
Next: Deleting assignments Up: Declaring and using linear Previous: Using assignments

Recursion in assignments

Recursion is available for assignments. For example, suppose that you

wish to generate a random walk with noise: tex2html_wrap_inline34666 . This could be generated via the following assignment:

BD>assign  X.t=X.(t-1)+V.t tex2html_wrap_inline33712

Whenever we reference this assignment, [B/D] notes the recursive aspect and deduces, by back tracking through the recursion, what is actually intended. This requires some termination criterion. By default, any quantity with a varying index which becomes zero, becomes zero itself. (If a varying index becomes negative, this results in an error.) Under this rule, [B/D] would deduce that tex2html_wrap_inline34668 , as tex2html_wrap_inline34670 is taken to be zero. Otherwise, termination criteria can be set explicitly by defining an element. This works as follows.

An assignment is defined as a linear combination of elements, components, and other assignments. Therefore, and ignoring self-referential assignments which cause an error, it is possible to trace through the definition part until it is solely in terms of elements and components.

When an assignment is referenced, [B/D] tries to determine the linear combination of elements and components intended in the definition part of the assignment. If the definition part of the assignment contains other assignments, these too are tracked through to determine the intended linear combination of elements and components. Eventually all the assignments in the definition part will either vanish because they are replaced by their own definitions, or as the recursion nears zero, they become zero by default, or because of terminating criteria established beforehand. Consider, for example, the following fragment of code (#phi is an example of a function, described more fully in chapter 7).

BD>element : A, X.1, Z.2 tex2html_wrap_inline33712

BD>assign : X.t=X.(t-1)+V.t tex2html_wrap_inline33712

BD>assign : Z.t=(#phi) Z.(t-1)+E.t tex2html_wrap_inline33712

BD>assign : Y.t=X.t+Z.t+ A tex2html_wrap_inline33712

When the assignment tex2html_wrap_inline34672 is referenced, [B/D] will take into account the recursion involving tex2html_wrap_inline34674 and tex2html_wrap_inline34676 . Moreover, as the elements X.1 and Z.2 exist, these will take priority over the implied assignments of the same name, and the recursion will terminate at these points. For example, suppose that we now wished to construct tex2html_wrap_inline34678 . The assignments and termination criteria imply

displaymath34664

 


next up previous contents index
Next: Deleting assignments Up: Declaring and using linear Previous: Using assignments

David Wooff
Wed Oct 21 15:14:31 BST 1998