| Pascal-XSC |
Institut für Angewandte Mathematik, Forschungsschwerpunkt CAVN, Universität KarlsruheThe programming language PASCAL-XSC was developed to supply a powerful tool for the numerical solution of scientific problems based upon a properly defined and implemented computer arithmetic in the usual spaces of numerical computation. The main concepts of PASCAL-XSC are
Wissenschaftliches Rechnen/Softwaretechnologie, Universität Wuppertal
In the subsequent paragraphs, the most important new concepts are considered briefly.
in Standard PASCAL, the addition of two polynomials is implemented as a procedureconst maximum_degree = 20;
type polynomial = array [0..maximum_degree] of real;
procedure add (a, b: polynomial; var c: polynomial);
{ Computes c = a + b for polynomials }
var i: integer;
begin
for i:= 0 to maximum_degree do
c[i]:= a[i] + b[i];
end;
Several calls of add have to be used to compute
the expression z = a + b + c + d:
In PASCAL-XSC, we define a function with the result type polynomialadd (a,b,z); add (z,c,z); add (z,d,z);
function add (a, b: polynomial): polynomial;
{ Delivers the sum a + b for polynomials }
var i: integer;
begin
for i:= 0 to maximum_degree do
add[i]:= a[i] + b[i];
end;
Now, the expression z = a + b + c + d may be computed as
Even clearer is the operator in PASCAL-XSCz:= add(a,add(b,add(c,d)))
operator + (a, b: polynomial) result_polynomial : polynomial;
{ Delivers the sum a + b for polynomials }
var i: integer;
begin
for i:= 0 to maximum_degree do
result_polynomial[i]:= a[i] + b[i];
end;
Now, the expression may be written in the common mathematical notation
A programmer may also define a new name as an operator. A priority is assigned in a preceding priority declaration.z:= a+b+c+d
As illustrated above, operators may also be overloaded. Even the assignment operator := may be overloaded so that the mathematical notation may be used for assignments:
var
c: complex;
r: real;
operator := (var c : complex; r: real);
begin
c.re := r;
c.im := 0;
end;
...
r:= 1.5;
c:= r; {complex number with real part 1.5 and imaginary part 0}
module poly;
use {other modules}
...
{local declarations}
...
{global declarations}
global type polynomial = ...
...
global procedure read (...
...
global procedure write (...
...
global operator + (...
...
global operator * (...
...
begin
{initialization part of the module}
...
end. {module poly}
When declaring variables of this dynamic type, the index bounds have to be specified:type polynomial = dynamic array [*] of real;
where the values of the expressions for the index range are computed during program execution. To get access to the bounds of dynamic arrays which are specified only during execution of the program, the two functions lbound(...) and ubound(...) and their abbreviations lb(...) and ub(...) are supplied. The multiplication of two polynomials may be realized dynamically as follows:var p, q : polynomial [0..2*n];
operator * (a, b: polynomial)
product: polynomial[0..ubound(a)+ubound(b)];
{ Delivers the product a * b of two polynomials a, b }
var i, j : integer;
result : polynomial[0..ubound(a)+ubound(b)];
begin
for i:= 0 to ubound(a)+ubound(b) do
result[i]:= 0;
for i:= 0 to ubound(a) do
for j:= 0 to ubound(b) do
result[i+j]:= result[i+j] + a[i] * b[j];
product:= result;
end;
A PASCAL-XSC program using dynamic arrays for polynomials follows the
template
program dynatest (input, output);
...
type polynomial = dynamic array [*] of real;
...
var maximum_degree : integer;
...
operator * (a, b:polynomial)...
...
procedure write (var f : text; p: polynomial);
...
procedure main (degree : integer);
var
p,q : polynomial[0..degree];
r : polynomial[0..2*degree];
begin
...
r:= p * q;
writeln ('p*q = ', r);
...
end;
begin {main program}
read (maximum_degree);
main (maximum_degree);
end. {main program}
The following example demonstrates that it is possible to
access a row or a column of dynamic arrays as a single object.
This is called slice notation.
type vector = dynamic array [*] of real;
type matrix = dynamic array [*] of vector;
var v : vector[1..n];
m : matrix[1..n,1..n];
...
v := m[i]; { i-th row of m }
m[*,j] := v; { j-th column of m }
Current releases (Version 3.0 and higher) of PASCAL-XSC include the concept
of flexible arrays. A dynamic array is called
flexible if it can be allocated
with new index bounds and new size at any time during its lifetime.
In the following example, we use a flexible real vector to perform
some computations until a desired accuracy is achieved.
type vector = dynamic array [*] of real;
procedure high_accuracy (basic_length: integer; result: real);
var
accurate : boolean;
rvec : vector;
k : integer;
begin
accurate := false; k := 0;
repeat
k:= k+1;
allocate (rvec, 1..k*basic_length);
... { computations }
accurate := ...
free (rvec); { might be omitted }
until accurate;
result := ...
end;
For a detailed description of flexible arrays, see the references below.
http://www2.math.uni-wuppertal.de/wrswt/xsc/pxsc_download.html
or
http://www.xsc.de