Very nice idea.
This is slightly resembles the ZPL programming language:
http://www.cs.washington.edu/research/projects/zpl
Below is attached some information from their webpage
This example is almost self-explanatory.
Maybe it is possible to get some ideas from this example?
(some syntactic sugar).
For example:
1. define class direction for n-tuples of integers.
Symbolic names as south or north are simpler for perception.
class direction {
public:
direction(int);
direction(int,int);
direction(int,int,int);
//...
};
direction north(-1,0);
Some operations (which? maybe adding dimension?) for directions.
(But I don't know what names to chose for 3d, maybe someone help?).
2. improve the concept of region: enable the boundary conditions
and initialization "left to" (e.g. west), "right to" (east), etc.
as in example below.
Regards,
Alexander
1 /* Jacobi */
2
3 program jacobi;
4
5 config var n : integer = 10; -- Declarations
6 delta : float = 0.0001;
7
8 region R = [1..n, 1..n];
9
10 direction north = [-1, 0]; south = [ 1, 0];
11 east = [ 0, 1]; west = [ 0,-1];
12
13 procedure jacobi(); -- Entry point
14 var A, Temp : [R] float;
15 err : float;
16
17 begin
18 [R] A := 0.0; -- Initialization
19 [north of R] A := 0.0;
20 [east of R] A := 0.0;
21 [west of R] A := 0.0;
22 [south of R] A := 1.0;
23
24 [R] repeat -- Main body
25 Temp := (A@north+A@east+A@west+A@south) / 4.0;
26 err := max?? abs(A-Temp);
27 A := Temp;
28 until err < delta;
29
30 [R] writeln(A); -- Output result
31 end;
Figure 1: ZPL program for the Jacobi computation.
--------------------------------------------------------------------
Temp := (A@north+A@east+A@west+A@south)/4.0;
finds for each element in A the average of its four nearest
neighbors and assigns the result to Temp. An expression A@d,
executed in the context of a region R, results in an array of the
same size and shape as R composed of elements of A offset in the
direction d. As illustrated in Figure 3, A@d can be thought of as
adding d to each index, or equivalently in this case, shifting A.
--------------------------------------------------------------------
[Image]
[...]
The four arrays are combined elementwise, yielding the effect of
computing for element (i,j) the sum of its four nearest neighbors.
This can be seen by the following identities:
(i,j)@north = (i, j) + north
= (i, j) + (-1, 0)
= (i-1, j )
(i,j)@east = (i, j) + east
= (i, j) + ( 0, 1)
= (i , j+1)
(i,j)@west = (i, j) + west
= (i, j) + ( 0,-1)
= (i , j-1)
(i,j)@south = (i, j) + south
= (i, j) + ( 1, 0)
= (i+1, j )
The elements are then each divided by 4.0 and the result is stored
into Temp.
[...]
--------------- --------------------------------------------------------------------
Up to top (C) 1997,1998 University of Washington
--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo@oonumerics.org, with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 04:30:05 EST