User Tools

Site Tools


tutorial_lud

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
Next revision Both sides next revision
tutorial_lud [2015/03/06 09:32]
guillaume input/output/local keywords used
tutorial_lud [2017/04/19 13:26]
waruna [Generating and Testing Alphabets]
Line 2: Line 2:
  
 The equation for LU Decomposition, derived from first principles using simple algebra in {{:foundations.pdf|Foundations}} (pg.3), is as follows: The equation for LU Decomposition, derived from first principles using simple algebra in {{:foundations.pdf|Foundations}} (pg.3), is as follows:
-<latex> + 
-    $U_{i,j}=\begin{cases}+/*<latex>*/ 
 +$
 +    U_{i,j}=\begin{cases}
 1=i\le j & A_{i,j}\\ 1=i\le j & A_{i,j}\\
 1<i\le j & A_{i,j}-\sum_{k=1}^{i-1}L_{i,k}U_{k,j} 1<i\le j & A_{i,j}-\sum_{k=1}^{i-1}L_{i,k}U_{k,j}
-\end{cases}+\end{cases}\\
  
 L_{i,j}=\begin{cases} L_{i,j}=\begin{cases}
-1=j\le & \frac{A_{i,j}}{U_{j,j}}\\ +1 = i\le & \frac{A_{i,j}}{U_{j,j}}\\ 
-1<i\le j & \frac{1}{U_{j,j}}(A_{i,j}-\sum_{k=1}^{j-1}L_{i,k}U_{k,j}) +1< i\le j & \frac{1}{U_{j,j}}(A_{i,j}-\sum_{k=1}^{j-1}L_{i,k}U_{k,j}) 
-\end{cases}$ +\end{cases} 
-</latex>+$
 +/*<\latex>*/ 
  
-[Temp note: in the last case of L, the condition is "1 < j <= i"]+[Temp note due to : in the last case of L, the condition is "1 < j <= i"]
  
 =====Writing Alphabets===== =====Writing Alphabets=====
Line 42: Line 46:
 </sxh> </sxh>
 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'' (old: ''given''is the keyword for input, ''output' (old: ''returns''is the keyword for output, and ''local'' (old: ''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:false>
 affine LUD {N|N>0} affine LUD {N|N>0}
-input +input   float A {i,j|1<=(i,j)<=N}; 
-   float A {i,j|1<=(i,j)<=N}; +
 output output
    float L {i,j|1<=j<i<=N};    float L {i,j|1<=j<i<=N};
Line 144: Line 147:
 L = case L = case
    {i,j|1==j} : (A / (i,j->j,j)@U);    {i,j|1==j} : (A / (i,j->j,j)@U);
-   {i,j|1<i} : (A - reduce(+, (i,j,k->i,j), (i,j,k->i,k)@L*(i,j,k->k,j)@U))/(i,j->i,i)@U;+   {i,j|1<i} : (A - reduce(+, (i,j,k->i,j), (i,j,k->i,k)@L*(i,j,k->k,j)@U))/(i,j->j,j)@U;
 esac; esac;
 </sxh> </sxh>
 ====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 ''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:false>
 affine LUD {N|N>0} affine LUD {N|N>0}
Line 156: Line 159:
    float L {i,j|1<i<=N && 1<=j<i};    float L {i,j|1<i<=N && 1<=j<i};
    float U {i,j|1<=j<=N && 1<=i<=j};    float U {i,j|1<=j<=N && 1<=i<=j};
-local+let
    U[i,j] = case    U[i,j] = case
       {|1==i} : A[i,j];       {|1==i} : A[i,j];
Line 170: Line 173:
 Analyses, transformations, and code generation of Alphabets programs are performed using the AlphaZ system. The normal interface for using AlphaZ is the scripting interface called compiler scripts. Analyses, transformations, and code generation of Alphabets programs are performed using the AlphaZ system. The normal interface for using AlphaZ is the scripting interface called compiler scripts.
 Given below is an example script for that does several things using the LUD program we wrote above. Given below is an example script for that does several things using the LUD program we wrote above.
-<sxh cs; gutter:false>+<sxh cs; gutter:true>
 # read program and store the internal representation in variable prog # read program and store the internal representation in variable prog
 prog = ReadAlphabets("./LUD.ab"); prog = ReadAlphabets("./LUD.ab");
tutorial_lud.txt · Last modified: 2019/04/05 09:02 by sanjay