Rascal is based on an extremely modular approach; depending on the user's needs, various powerful modules can be compiled into the system. Thus Rascal can be a light-weight tool as well as a very powerful computational system. This user documentation is created during compilation and describes the included features.
Invoking the program leads to a prompt where you can enter expressions. The expressions or definitions are being evaluated as soon you press return. A semicolon at the end suppresses any output. As an example:
The user can also define functions of one variable (n-ary functions can be implemented using vectors or matrices as arguments). The names follow the same rules as the names of variables:
Conditional expressions can be realized using the C-style ``?:''-operator:
You can exit Rascal by entering ``quit'' followed by a return.
If Rascal was compiled using the ``libreadline'', then you may use the cursor-keys to flip back to commands and results from before, as well as benefit of command completition using the ``tab''-key.
Furthermore the different modules predefine functions, which are documented in the following sections.
Using double precision floating-point numbers overcomes this problem, but rounding errors may occur. A number is being interpreted as a floating-point number when there is a decimal-point within or at the end of the number and/or an exponent. As an example 1.234e+12 represents . Be warned that there is no exact representation for 0.1 and many many other numbers in binary floating-point representations.
All operands like +,-,*,/,^ ,% are defined for integers and doubles, together with standard functions sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth, log, exp, sqrt, sqr. A postfix ! computes the factorial of the operand (currently just in integer).
The values can be compared using the operators ==,!=,<,<=,>,>=, logical expression can be connected using &,| and the logical negation ~ .
Besides strings can be used as "evaluation variable": As all the standard operators and functions are also defined for strings, one can determine the expression Rascal would evaluate if the argument only had been a real value.
Strings are enclosed in quotes:
But the operators ==,!= are still used to compare two strings. The strlen function returns the length of the string.
In Rascal vectors are just matrices with either just one row or one column. You can enter a matrix by using brackets, where values within a line are separated by spaces, lines are separated by semicolons. matrices of same size can be added and subtracted using the usual operators:
[1 2;3 4;5 6]
>B=[-3 -4;2 7;2 9]
[-3 -4;2 7;2 9]
[-2 -2;5 11;7 15]
[4 6;1 -3;3 -3]
Scalars can be multiplied to the matrices and two matrices can be multiplied if the number of columns of the first matches the number of rows of the second. Dividing by a matrix means multiplying with the inverse, of course this is only defined for quadratic matrices. The functions rows, cols, size return the number of rows, columns and maximum of the two values of a matrix or vector.
Types using the matrix inversion must be able to be compared to integers. If there is no inverse, an empty matrix is being returned. You may compute the determinant using the det function.
[3 4;6 8]
>A=[1 3;4 13];
[13 -3;-4 1]
>[2 0;0 3]/A
[26 -6;-12 3]
The cells of matrices can be of any type; here an example for an integer, double, matrix, string matrix:
The summation of matrices and scalars is defined as the addition between the matrix and the identity of same size times the scalar. Vector valued functions can be defined easily, also with multiple arguments.
>f([1 2;3 4])
[[7 10;15 22];[3 2;3 6]]
>f[1 2;3 4]
[[7 10;15 22];[3 2;3 6]]
The support for loops is experimental- it is very likely that the syntax will change in future releases.
Rascal supports C(++)-style loops to a certain extend. The syntax is
for( <initialization> ; <condition> ; <expression 1> ) <expression 2>
First the initialization expression is being evaluated- this should be used to initialize the variable used for the loop. If the given condition is true then expression 2 and 1 are evaluated (in that order) until the condition is false after the evaluation of 1. Have a look at this example:
The above example computes the sum of the numbers between 0 and 10. If you would like to see the intermediate results, leave out the semicolon at the end of the for statement:
In contrast to C(++) there is no "comma-operator" in rascal yet, thus you cannot use it in for-statements. Sorry.
You can interrupt running computations in Rascal by sending a SIGINT signal- just press CTRL-C. Rascal will then try to stop all computations. If you press CTRL-C again before Rascal was able to get back to the interactive shell, Rascal will terminate.
If you press CTRL-C while you are in the interactive shell, Rascal will beep you and terminate if you repeat your signal.
Thus if you "for"-statement doesn't seem to terminate or you were trying to compute the factorial of "100000", just press CTRL-C and you won't lose you work done before.
The real and imaginary part of a complex number can be accessed like the cells of vectors: The first cell is the real, the second the imaginary value. Additionally like matrices complex values can consist of all different types of data. The "transpose" of a complex value is the complex conjugate.
The following standard functions are defined for complex: exp, log, pow, sqrt, sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acoth, atanh, acoth. The function arg computes the argument, the function abs the absolute value. The standard functions sqrt, pow for integers and doubles are being overridden by the corresponding complex versions.
The log represents the main value of the natural logarithm, the pow(a,b) or a^b is evaluated as , the sqrt(a) as and the rest is determined based on these functions and the pendants on the real axis.
One could also define a complex out of matrices, but this is not advisable as this easily gets confusing and Rascal prefers complex values within matrices. You should also be aware that naively plugging interval-datatypes into a generic complex datatype will not yield verified results: As an example the arg function has to be treated differently, and most other standard functions depend on this.
This module introduces polynomials in one variable to Rascal. You may create polynomials by the "poly"-function, but it is very useful to assign the variable X the monome 1*X^ 1. Then you can easily enter the polynomials.
X^ 4+4*X^ 3+12*X^ 2+16*X+16
You can evaluate the polynomials like functions, as well as compute the derivate polynomial.
With this arithmetics you may easily compute powers of polynomial expressions or compute shifted polynomials:
X^ 4-12*X^ 3+54*X^ 2-108*X+81
X^ 4-4*X^ 3+6*X^ 2-4*X+1
For polynomials the evaluation, derivation, addition, substraction, equality, inequality and powering by an integer are defined.
As an example with :
Together with the string arithmetic this module can also be used to determine formulas for the derivatives:
As you can see there is a short-cut to this functionality, but you can only compute the first derivatives, for higher order derivatives you need to use taylor by yourself.
Besides the basic operations +,-,*,/ the following standard functions are defined: sqrt, sqr, exp, log, pow, sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth. Of course the datatype you put into the taylor arithmetic should have defined these functions as well. The cells can be accessed the same way like the cells of vectors.
It is also possible to define a function which computes the derivative of an arbitrary function at an arbitrary point:
As the derivative of "square" is two times the argument, this result is correct.
Intervals can be constructed out of integers and doubles using the constructor Interval or the bracket-notation:
[ 1.000000, 2.000000]
[ 3.000000, 4.000000]
[ 0.099999, 0.100001]
Note that  would denote a 1 x 1 matrix, not a point interval. It seems to be confusing that c is not a point interval, but the actual value 0.1 cannot be represented using the binary floating point representation, thus it is correct to represent this value as an actual interval. This module overrides the parsing of floating point numbers to achieve this. For compatibility reasons you can still also use the string constructor:
[ 0.099999, 0.100001]
You can compute the intersection of two intervals using the &-operator, the convex hull using the |-operator. The relational operators <,<=,>,>= can be used to compute the relations .
You can access the upper and lower boundary of an interval using the functions sup, inf, the middle point using mid and the diameter with the help of the function diam.
The following standard functions are defined for intervals: abs, exp, log, pow, sqrt, sqr, sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acoth, atanh, acoth.
The output format can be configured using the Precision(width,digits) command:
This datatype allows computations of arbitrary accuracy and supports the same features as the usual doubles datatype.
Long reals are created using the LReal-constructor:
As you can see the standard LReal has about twice as many accurate digits than the usual double arithmetic. The accuracy can be configured during runtime using the Stagprec-function:
The following standard functions are defined for LReals: abs, exp, log, pow, sqrt, sqr, sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acoth, atanh, acoth.
LIntervals can be constructed out of integers and doubles using the constructor Interval or the bracket-notation, when at least one of the arguments is a staggered precision LReal:
LInterval( 1.0000000000, 2.0000000000)
LInterval( 3.0000000000, 4.0000000000)
LInterval( 0.0999999999, 0.1000000001)
As you can see there are several ways of defining a long interval.
As with LReals the accuracy of LIntervals can be adjusted by invoking the function Stagprec.
You can compute the intersection of two long intervals using the &-operator, the convex hull using the |-operator. The relational operators <,<=,>,>= can be used to compute the relations .
You can access the upper and lower boundary of an long interval using the functions sup, inf, the middle point using mid and the diameter with the help of the function diam.
The following standard functions are defined for long intervals: abs, exp, log, pow, sqrt, sqr, sin, cos, tan, cot, asin, acos, atan, acot, sinh, cosh, tanh, coth, asinh, acoth, atanh, acoth.
The results above were shortened.
The division between long integers and integers results in an integer division, the remainder can be computed using the modulo operator.
The function longrandom(n) creates a long pseudo random number with about 7n to 8n digits.
>A=[1 2;3 4];
[-2 1;3/2 -1/2]
[-2 1;1.5 -0.5]
As you can see any operation with a double will round the fraction to the next floating-point number. The fractions are normalized in each step, only the numerator can be negative.
The standard-operators and functions should be defined for fractions, thus the user shouldn't feel any difference between fractions and doubles, but that the latter is less accurate.
As the underlying datatype are long integers, fractions can get as large as much time or memory you have:
Again above numbers were shortened.
This will plot the function f from -10 to 10, computing values with stepsize 0.1.
Parametric plots are done as follows:
Last but not least rascal can do surface plots:
The output of plots may be saved in postscript files using the plotOutput function:
This is very basic plotting support and it is likely that the syntax will change in later versions.
This modules includes several algorithms of the Toolbox into rascal. Please refer to the book
R. Hammer, M. Hocks, U. Kulisch, D. Ratz: C++ Toolbox for Verified Computing I - Basic Numerical Problems. Springer-Verlag, Heidelberg, New York, 1995.
or the webpage http://www.xsc.de/ for more information.
In Rascal you may enter help toolbox to check what toolbox modules are included.
The function RPolyeval(p,t) evaluates the real polynomial p at t at maximum accuracy, even in the neighborhood of a root where cancellation dooms an ordinary floating-point evaluation.
The function returns a vector with the entries [y;iy;it;err] where y is the result of a Horner scheme evaluation, iy represents a maximum accuracy enclosure, it the number of iterations needed and err an eventual error message. The function rpeval(p,t) just returns the resulting interval.
X^ 4-8*X^ 3+24*X^ 2-32*X+16
The function CPolyZero(p,t) computes verified enclosures of the roots of a complex polynomial p starting from t by enclosing the zeros in narrow bounds. The coefficients of the deflated polynomial are also enclosed.
The function returns a vector with entries [y;p;err] where y is a complex enclosure of the root close to t, p the complex enclosure of the reduced polynomial and err represents an eventual error messages. The functions cpzero(p,t) and cpreduce(p,t) just return the enclosure of the root or of the reduced polynomial.
[([ 1.4142135623, 1.4142135624]+[ 2.8284271247, 2.8284271248]*i);
X^ 3+([-3.5857864377, -3.5857864376]+[-0.1715728753,-0.1715728752]*i)*X^ 2
+([ 1.4142135623, 1.4142135624]+[ -3.3847763109,-3.3847763108]*i)*X
The function LinSolve(A,b) computes a verified solution to the square linear system A*x=b for a real square matrix A and real vector b based on a Newton-like method for an equivalent fixed-point problem.
The function returns a vector with entries [x;cond;err] where x represents the verified enclosure or exact solution to the system, cond a condition number estimate and err an eventual error message. The function linsys(A,b) just returns the resulting vector enclosure.
The functions RevSimplex(A,b,c) and LinOpt(A,b,c,BStart) determine the optimal solution of the linear optimization problem: Maximize z=cT*x where A*x=b and . LinOpt validates the solution and determines enclosures of the true optimal solution set.
RevSimplex returns a vector with entries [x;v;z;err] where x denotes the optimal solution vector, v the optimal basic index set, which can be used as bstart for LinOpt, z the optimal value and err might contain an error message. LinOpt returns a vector [z;V;X;no;err] where z is the enclose of the optimal value, V is a matrix which no lines represent the different index vectors, X a matrix which lines represent the different solution vectors and err again is the eventual error message.
[2500;[1 2 3;1 2 4;1 3 4];[14 200 36 0 0;50 0 0 200 0;50 0 0 200 0];3;""]
Send questions, ideas, hints and congratulations to firstname.lastname@example.org.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
This document was generated using the LaTeX2HTML translator Version 2K.1beta (1.47)
Copyright © 1993, 1994, 1995, 1996,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split 0 -nonavigation -transparent -math -math_parsing -dir rascal_html -mkdir -image_type gif rascal.tex
The translation was initiated by Sebastian Ritterbusch on 2002-05-14