tutorial_lud

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

Both sides previous revision Previous revision | |||

tutorial_lud [2017/04/19 13:26] waruna [Generating and Testing Alphabets] |
tutorial_lud [2017/04/19 14:09] (current) |
||
---|---|---|---|

Line 28: | Line 28: | ||

Parameters are runtime constants represented with some symbol in the code. In this example, parameter N will be used to define the size of the matrices, which is not known until runtime. | Parameters are runtime constants represented with some symbol in the code. In this example, parameter N will be used to define the size of the matrices, which is not known until runtime. | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

. | . | ||

Line 36: | Line 36: | ||

In most cases, a computation uses some inputs and produces outputs. Such variables must be declared with a name, a data type, and a shape/size. In Alphabets, the shape/size is represented with polyhedral domains. | In most cases, a computation uses some inputs and produces outputs. Such variables must be declared with a name, a data type, and a shape/size. In Alphabets, the shape/size is represented with polyhedral domains. | ||

For this example, the ''A'' matrix is given, and we are computing two triangular matrices ''L'' and ''U''. ''A'' is an NxN square matrix. The declaration for ''A'' looks as follows: | For this example, the ''A'' matrix is given, and we are computing two triangular matrices ''L'' and ''U''. ''A'' is an NxN square matrix. The declaration for ''A'' looks as follows: | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

float A {i,j|1<=(i,j)<=N}; //starting from 1 to be consistent with the equation in the notes | float A {i,j|1<=(i,j)<=N}; //starting from 1 to be consistent with the equation in the notes | ||

</sxh> | </sxh> | ||

Similarly, ''L'' is a lower triangular matrix of size N (with unit diagonals, implicit) and ''U'' is an upper triangular matrix of size N. The declarations should look like the following: | Similarly, ''L'' is a lower triangular matrix of size N (with unit diagonals, implicit) and ''U'' is an upper triangular matrix of size N. The declarations should look like the following: | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

// The convention is that i is the vertical axis going down, and j is the horizontal axis | // The convention is that i is the vertical axis going down, and j is the horizontal axis | ||

float L {i,j|1<i<=N && 1<=j<i}; // Note that the diagonal elements of L are not explicitly declared | float L {i,j|1<i<=N && 1<=j<i}; // Note that the diagonal elements of L are not explicitly declared | ||

Line 47: | Line 47: | ||

Now these variable declarations need to be placed at appropriate places to specify whether they are input/output/local. | Now these variable declarations need to be placed at appropriate places to specify whether they are input/output/local. | ||

''input''/''given'' is the keyword for input, ''output''/''returns'' is the keyword for output, and ''local''/''using'' is the keyword for local variables. | ''input''/''given'' is the keyword for input, ''output''/''returns'' is the keyword for output, and ''local''/''using'' is the keyword for local variables. | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

input float A {i,j|1<=(i,j)<=N}; | input float A {i,j|1<=(i,j)<=N}; | ||

Line 152: | Line 152: | ||

====Final Alphabets Program==== | ====Final Alphabets Program==== | ||

Combine all of the above, and you will get the Alphabets program for LU decomposition. Don't forget the keyword ''let''/''through'' before equations the period at the end (since our example has no local variables). Notice how we can mix and match Show and AShow syntax within the program, but each equation must obviously, be consistent. | Combine all of the above, and you will get the Alphabets program for LU decomposition. Don't forget the keyword ''let''/''through'' before equations the period at the end (since our example has no local variables). Notice how we can mix and match Show and AShow syntax within the program, but each equation must obviously, be consistent. | ||

- | <sxh alphabets; gutter:false> | + | <sxh alphabets; gutter:true> |

affine LUD {N|N>0} | affine LUD {N|N>0} | ||

input | input | ||

Line 229: | Line 229: | ||

====OOPS WHAT HAPPENED==== | ====OOPS WHAT HAPPENED==== | ||

You will see that when you execute the code, **//it will produce an error//**. You may be able to easily fix the error in your Alpha program and regenerate correctly executing C code, or you may want a bit of help. In either case, we would like to know. Please email <Sanjay.Rajopadhye@colostate.edu> with the error message that is produced. | You will see that when you execute the code, **//it will produce an error//**. You may be able to easily fix the error in your Alpha program and regenerate correctly executing C code, or you may want a bit of help. In either case, we would like to know. Please email <Sanjay.Rajopadhye@colostate.edu> with the error message that is produced. | ||

+ |

tutorial_lud.1492630000.txt.gz ยท Last modified: 2017/04/19 13:26 by waruna