- " at the prompt. This has to be done
on the top level and not inside any function or whatnot, and it cannot
be part of any expression. It also has a slightly different syntax then the
rest of genius, more similiar to a shell. You can enter the file in
quotes. If you use the '' quotes, you will get exactly the string
that you typed, if you use the "" quotes, special characters will be
unescaped as they are for strings. Example:
load program1.gel program2.gel
load "Weird File Name With SPACES.gel"
There are also cd, pwd and ls commands built in. "cd" can will take one
argument, "ls" will take an argument which is like the glob in the unix shell,
that is you can use wildcards. "pwd" will take no arguments. Example:
cd directory_with_gel_programs
ls *.gel
Calculator parameters:
----------------------
There are several basic parameters provided by the calculator in addition
to the ones provided by the standard library. These control how the
calculator behaves.
FloatPrecision The floating point precision in bits
MaxDigits The maximum digits in a result
ResultsAsFloats If the results should be always printed as floats
ScientificNotation If floats should be in scientific notation
FullExpressions Boolean, should we print out full expressions
for non-numeric return values (longer then a line)
MaxErrors The maximum number of errors to return on one
evaluation
MixedFractions If fractions should be printed as mixed fractions
such as "1 1/3" rather then "4/3"
IntegerOutputBase The base that will be used to output integers
OutputStyle A string, can be "normal", "latex", "mathml" or "troff"
and it will effect how matrices (and perhaps other
stuff) is printed, useful for pasting into documents
To set a paramater just set it as a variable. For example To set the
MaxDigits to 12 you would do:
MaxDigits = 12
Standard startup procedure:
---------------------------
First the program looks for the installed library file (the compiled
version lib.cgel) in the installed directory, then it looks into the
current directory, and then it tries to load an uncompiled file called
~/.geniusinit
If you ever change the the library its installed place, you'll have to
first compile it with "genius --compile loader.gel > lib.cgel"
EXAMPLE PROGRAMS in GEL:
=======================
Here is a user factorial function (there already is one built in so
this function is useless):
function f(x) = if x <= 1 then 1 else (f(x-1)*x)
With indentation it becomes:
function f(x) = (
if x <= 1 then
1
else
(f(x-1)*x)
)
This is a direct port of the factorial function from the bc manpage.
The syntax seems similar to bc, but different in that in gel, the
last expression is the one that is returned. It can however be done
with with 'return's as:
function f(x) = (
if (x <= 1) then return (1);
return (f(x-1) * x)
)
Which is almost verbatim bc code, except for then and the function
definition.
Here's a smaller, nicer, iterative version, that uses the product
loop.
function f(x) = prod k=1 to x do k
Here's a larger example, this basically redefines the internal ref
function to calculate the same thing, but written in GEL:
# Calculate the row-echelon form of a matrix
function MyOwnREF(m) = (
if not IsMatrix(m) or not IsValueOnly(m) then
(error("ref: argument not a value only matrix");bailout);
s = min(rows(m), columns(m));
i = 1;
d = 1;
while d <= s and i <= columns(m) do (
# This just makes the anchor element non-zero if at
# all possible
if m@(d,i) == 0 then (
j = d+1;
while j <= rows(m) do (
if m@(j,i) == 0 then
(j=j+1;continue);
a = m@(j,);
m@(j,) = m@(d,);
m@(d,) = a;
j = j+1;
break
)
);
if m@(d,i) == 0 then
(i=i+1;continue);
# Here comes the actual zeroing of all but the anchor
# element rows
j = d+1;
while j <= rows(m)) do (
if m@(j,i) != 0 then (
m@(j,) = m@(j,)-(m@(j,i)/m@(d,i))*m@(d,)
);
j = j+1
);
m@(d,) = m@(d,) * (1/m@(d,i));
d = d+1;
i = i+1
);
m
)
Have fun,
George