Mathematica 4.0 for Solaris Copyright 1988-1999 Wolfram Research, Inc. -- Terminal graphics initialized -- Loading MMAlpha... Unix version Alpha v1.0 Initialization The Documentation can be found in /udd/alpha/alpha_beta/Mathematica/doc/user Current version in /udd/alpha/alpha_beta/Mathematica Current directory=/udd/rajopadh/cours/CS670 If you use the notebook interface, you can open the master notebook by typing: start[]. In[1]:= setMMADir[{"demos", "NOTEBOOKS", "Getting-started"}] Out[1]= /udd/alpha/alpha_beta/Mathematica/demos/NOTEBOOKS/Getting-started In[2]:= load["prodVect.alpha"]; [prodVect] Library Loaded In[3]:= show[] system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var C : {i,j | 1<=i<=N; 0<=j<=N} of integer; let C = case {i,j | j=0} : 0.(i,j->); {i,j | 1<=j} : C.(i,j->i,j-1) + a.(i,j->i,j) * b.(i,j->j); esac; c = C.(i->i,N); tel; In[4]:= ?ashow ashow[] pretty prints the program in $result in array notation. ashow[var] pretty prints the program contained in var in array notation. In[5]:= ashow[ ] system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var C : {i,j | 1<=i<=N; 0<=j<=N} of integer; let C[i,j] = case { | j=0} : 0[]; { | 1<=j} : C[i,j-1] + a[i,j] * b[j]; esac; c[i] = C[i,N]; tel; In[6]:= asave["myFile.alpha"] sh: myFile.alpha: cannot create In[7]:= analyze[] Static Analysis of system prodVect --Checking declaration of variables. --Checking single assignment rule. --Checking definitions of output/local variables. --Checking definition of input variables. --Checking that input/local variables are used. --Checking type and domain consistency in the equations: ----equation defining C ----equation defining c Analysis Successful... Out[7]= True In[8]:= writeC["prodVect.c", "-p 10"] sh: /udd/alpha/alpha_beta/Mathematica/demos/NOTEBOOKS/Getting-started/prodVect.c: cannot create In[9]:= SetDirectory[Environment["HOME"]<>"/alpha"] Out[9]= /udd/rajopadh/alpha In[10]:= asave["myFile.alpha"] In[11]:= writeC["prodVect.c", "-p 10"] In[12]:= !! prodVect.c /* system prodVect */ /* C-Code generated by Alpha Code Generator version 1.2 */ #include typedef struct { int value; int computed; } intvar; typedef struct { int value; int computed; } boolvar; typedef struct { double value; int computed; } realvar; double atof(); int atoi(); #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) #define INFINITY 0x7fffffff #define SHR(x,y) ((x)/(double)(1<<(y))) #define SHL(x,y) ((x)*(double)(1<<(y))) #define EXP(x,y) pow((x),(y)) #define TRUNCATE(x) ((int)(x)) #define CEILING(x) ((int)(ceil(x))) #define FLOOR(x) ((int)(floor(x))) #define ROUND(x) ((int)(rint(x))) #define FLOAT(x) ((double)(x)) /* parameters */ #define N 10 /* input variables */ char __s_[32]; intvar __a[100]; #define a(i,j) __a[(i)+10*(j)-11] intvar __b[10]; #define b(i) __b[(i)-1] /* output variables */ intvar __c[10]; #define c(i) __c[(i)-1] /* local variables */ intvar __C[110]; #define C(i,j) __C[(i)+10*(j)-1] static int compute_a(i,j) int i,j; { intvar *tmp; /* printf("Computing: a[%d,%d]\n" ,i,j); */ tmp = &(a(i,j)); if (!tmp->computed) { printf("Input a[%d,%d] =" ,i,j); gets(__s_); tmp->value = atoi(__s_); tmp->computed = 1;} return tmp->value; } static int compute_b(i) int i; { intvar *tmp; /* printf("Computing: b[%d]\n" ,i); */ tmp = &(b(i)); if (!tmp->computed) { printf("Input b[%d] =" ,i); gets(__s_); tmp->value = atoi(__s_); tmp->computed = 1;} return tmp->value; } static int compute_c(); static int compute_C(); /* --let equations */ static int compute_C(i,j) int i,j; { intvar *tmp; /* printf("Computing: C[%d,%d]\n" ,i,j); */ tmp = &(C(i,j)); if (!tmp->computed) { tmp->value = ( j==0 ) ? ( 0 ) : ( j-1>=0 ) ? ( compute_C(i,j-1) + compute_a(i,j) * compute_b(j) ) : ( printf("? case error\n"), exit(-1)); tmp->computed = 1;} return tmp->value; } static int compute_c(i) int i; { intvar *tmp; /* printf("Computing: c[%d]\n" ,i); */ tmp = &(c(i)); if (!tmp->computed) { tmp->value = compute_C(i,N); tmp->computed = 1;} return tmp->value; } int main() { int j, i ; /* --inputs */ for (i=1; i<=N; i++) { for (j=1; j<=N; j++) { printf("a[%d,%d]= %d\n", i,j, compute_a(i,j) ); } } for (i=1; i<=N; i++) { printf("b[%d]= %d\n", i, compute_b(i) ); } /* --outputs */ for (i=1; i<=N; i++) { printf("c[%d]= %d\n", i, compute_c(i) ); } } In[12]:= In[12]:= pipeall["C", "b.(i,j->j)", "B1.(i,j->i+1,j)"]; In[13]:= ashow[] system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var B1 : {i,j | 1<=i<=N; 1<=j<=N; 3<=N} of integer; C : {i,j | 1<=i<=N; 0<=j<=N} of integer; let B1[i,j] = case { | i=1; 1<=j<=N; 3<=N} : b[j]; { | 2<=i<=N; 1<=j<=N; 3<=N} : B1[i-1,j]; esac; C[i,j] = case { | j=0} : 0[]; { | 1<=j} : C[i,j-1] + a[i,j] * B1; esac; c[i] = C[i,N]; tel; In[14]:= changeOfBasis["C.(i,j->i+j,j)"]; In[15]:= ashow[] system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var B1 : {i,j | 1<=i<=N; 1<=j<=N; 3<=N} of integer; C : {i,j | j+1<=i<=j+N; 0<=j<=N} of integer; let B1[i,j] = case { | i=1; 1<=j<=N; 3<=N} : b[j]; { | 2<=i<=N; 1<=j<=N; 3<=N} : B1[i-1,j]; esac; C[i,j] = case { | j=0} : 0[]; { | 1<=j} : C[i-1,j-1] + a[i-j,j] * B1[i-j,j]; esac; c[i] = C[i+N,N]; tel; In[16]:= simplifySystem[]; ashow[] system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var B1 : {i,j | 1<=i<=N; 1<=j<=N} of integer; C : {i,j | j+1<=i<=j+N; 0<=j<=N} of integer; let B1[i,j] = case { | i=1} : b[i+j-1]; { | 2<=i} : B1[i-1,j]; esac; C[i,j] = case { | j=0} : 0[]; { | 1<=j} : C[i-1,j-1] + a[i-j,j] * B1[i-j,j]; esac; c[i] = C[i+N,N]; tel; In[17]:= schedule[] Checking options... Dependence analysis... Building LP... LP: 98 variables, 88 Constraints Writing file for PIP.... Solving the LP... Version D.1 cross : 818252, alloc : 1, compa : 0 n 1 u 39''' s 1''' ******************************* 0.41 Second PIP time ******************************* Shift coef: 0 Total execution Time: 1 + 2 N T_a{i, j, N} = 0 T_b{i, N} = 0 T_c{i, N} = 1 + i + N T_B1{i, j, N} = i T_C{i, j, N} = i Out[17]= scheduleResult[prodVect, {{a, {i, j, N}, sched[{0, 0, 0}, 0]}, {b, {i, N}, sched[{0, 0}, 0]}, {c, {i, N}, sched[{1, 1}, 1]}, {B1, {i, j, N}, sched[{1, 0, 0}, 0]}, {C, {i, j, N}, sched[{1, 0, 0}, 0]}}, {2, 1}] In[18]:= schedule[scheduleType -> sameLinearPart, addConstraints -> {"Ta[i,j,N]=i+j"}] Checking options... Dependence analysis... Building LP... 4 Recognized added Constraints: -1 + TaD1 = 0, -1 + TaD2 = 0, TaD3 = 0, Ca = 0, LP: 98 variables, 102 Constraints Writing file for PIP.... Writing line 100 Solving the LP... Version D.1 cross : 1099609, alloc : 1, compa : 0 n 1 u 51''' s 0''' ******************************* 0.54 Second PIP time ******************************* Shift coef: 0 Total execution Time: 2 + 2 N T_a{i, j, N} = i + j T_b{i, N} = 0 T_c{i, N} = 2 + i + N T_B1{i, j, N} = i T_C{i, j, N} = 1 + i Out[18]= scheduleResult[prodVect, {{a, {i, j, N}, sched[{1, 1, 0}, 0]}, {b, {i, N}, sched[{0, 0}, 0]}, {c, {i, N}, sched[{1, 1}, 2]}, {B1, {i, j, N}, sched[{1, 0, 0}, 0]}, {C, {i, j, N}, sched[{1, 0, 0}, 1]}}, {2, 2}] In[19]:= load["binaryAdder.alpha"]; ashow[] load::notFound: File binaryAdder.alpha not found system prodVect :{N | 3<=N} (a : {i,j | 1<=i<=N; 1<=j<=N} of integer; b : {i | 1<=i<=N} of integer) returns (c : {i | 1<=i<=N} of integer); var B1 : {i,j | 1<=i<=N; 1<=j<=N} of integer; C : {i,j | j+1<=i<=j+N; 0<=j<=N} of integer; let B1[i,j] = case { | i=1} : b[i+j-1]; { | 2<=i} : B1[i-1,j]; esac; C[i,j] = case { | j=0} : 0[]; { | 1<=j} : C[i-1,j-1] + a[i-j,j] * B1[i-j,j]; esac; c[i] = C[i+N,N]; tel; In[20]:= setMMADir[{"demos", "NOTEBOOKS", "Getting-started"}] Out[20]= /udd/alpha/alpha_beta/Mathematica/demos/NOTEBOOKS/Getting-started In[21]:= load["binaryAdder.alpha"]; ashow[] [FullAdder][Plus] Library Loaded system Plus : {W | 2<=W} (A : {b | 0<=b<=W-1} of boolean; B : {b | 0<=b<=W-1} of boolean) returns (S : {b | 0<=b<=W} of boolean); var Cin : {b | 0<=b<=W-1} of boolean; Cout : {b | 0<=b<=W-1} of boolean; X : {b | 0<=b<=W-1} of boolean; let Cin[b] = case { | b=0} : False[]; { | 1<=b} : Cout[b-1]; esac; use {b | 0<=b<=W-1} FullAdder[] (A, B, Cin) returns (X, Cout) ; S[b] = case { | b<=W-1} : X; { | b=W} : Cout[W-1]; esac; tel; In[22]:= getSystem["FullAdder"]; ashow[] system FullAdder (A : boolean; B : boolean; Cin : boolean) returns (X : boolean; Cout : boolean); let X[] = A xor B xor Cin; Cout[] = A and B or A and Cin or B and Cin; tel; In[23]:= getSystem["Plus"]; In[24]:= assignParameterValue["W", 8]; ashow[] Plus replaced in library. system Plus (A : {b | 0<=b<=7} of boolean; B : {b | 0<=b<=7} of boolean) returns (S : {b | 0<=b<=8} of boolean); var Cin : {b | 0<=b<=7} of boolean; Cout : {b | 0<=b<=7} of boolean; X : {b | 0<=b<=7} of boolean; let Cin[b] = case { | b=0} : False[]; { | 1<=b} : Cout[b-1]; esac; use {b | 0<=b<=7} FullAdder[] (A, B, Cin) returns (X, Cout) ; S[b] = case { | b<=7} : X; { | b=8} : Cout[7]; esac; tel; In[25]:= inlineAll[]; ashow[] True Expanding occurence #1 of subsystem FullAdder in system Plus XFullAdder1 Renaming variable Cin to CinXFullAdder1 Renaming variable B to BXFullAdder1 Renaming variable A to AXFullAdder1 Renaming variable Cout to CoutXFullAdder1 Renaming variable X to XXFullAdder1 system Plus (A : {b | 0<=b<=7} of boolean; B : {b | 0<=b<=7} of boolean) returns (S : {b | 0<=b<=8} of boolean); var Cin : {b | 0<=b<=7} of boolean; Cout : {b | 0<=b<=7} of boolean; X : {b | 0<=b<=7} of boolean; AXFullAdder1 : {b | 0<=b<=7} of boolean; BXFullAdder1 : {b | 0<=b<=7} of boolean; CinXFullAdder1 : {b | 0<=b<=7} of boolean; XXFullAdder1 : {b | 0<=b<=7} of boolean; CoutXFullAdder1 : {b | 0<=b<=7} of boolean; let Cin[b] = case { | b=0} : False[]; { | 1<=b} : Cout[b-1]; esac; AXFullAdder1[b] = A; BXFullAdder1[b] = B; CinXFullAdder1[b] = Cin; XXFullAdder1[b] = AXFullAdder1 xor BXFullAdder1 xor CinXFullAdder1; CoutXFullAdder1[b] = AXFullAdder1 and BXFullAdder1 or AXFullAdder1 and CinXFullAdder1 or BXFullAdder1 and CinXFullAdder1; X[b] = XXFullAdder1; Cout[b] = CoutXFullAdder1; S[b] = case { | b<=7} : X; { | b=8} : Cout[7]; esac; tel; In[26]:=