Содержание
GEL stands for Genius Extension Language. It is the language you use to write programs in Genius. A program in GEL is simply an expression that evaluates to a number, a matrix, or another object in GEL. Genius Mathematics Tool can be used as a simple calculator, or as a powerful theoretical research tool. The syntax is meant to have as shallow of a learning curve as possible, especially for use as a calculator.
Values in GEL can be numbers, Booleans, or strings. GEL also treats matrices as values. Values can be used in calculations, assigned to variables and returned from functions, among other uses.
Целые числа — первый тип чисел в GEL. Целые числа записываются общепринятым способом.
1234
Шестнадцатиричные и восьмиричные числа можно записать, используя нотацию языка C. Например:
0x123ABC 01234
Можно также набрать числа в произвольной системе счисления, используя запись <основание>\<число>
. Для цифр больше 10 используются буквы, как и в шестнадцатиричном счислении. Например, число по основанию 23 может быть записано в виде:
23\1234ABCD
Второй тип чисел в GEL — это рациональные числа. Они получаются делением двух целых чисел. Поэтому можно написать:
3/4
чтобы обозначить три четвёртых. Рациональные числа также можно записывать в виде смешанных дробей. Чтобы указать одну целую три десятых, можно написать:
1 3/10
The next type of number is floating point. These are entered in a similar fashion to C notation. You can use E
, e
or @
as the exponent delimiter. Note that using the exponent delimiter gives a float even if there is no decimal point in the number. Examples:
1.315 7.887e77 7.887e-77 .3 0.3 77e5
When Genius prints a floating point number it will always append a
.0
even if the number is whole. This is to indicate that
floating point numbers are taken as imprecise quantities. When a number is written in the
scientific notation, it is always a floating point number and thus Genius does not
print the .0
.
The final type of number in GEL is the complex numbers. You can enter a complex number as a sum of real and imaginary parts. To add an imaginary part, append an i
. Here are examples of entering complex numbers:
1+2i 8.01i 77*e^(1.3i)
При вводе мнимых чисел перед символом i
должно стоять число. Если использовать символ i
сам по себе, Genius интерпретирует его как ссылку на переменную i
. Если нужно указать саму мнимую единицу i
, используйте вместо неё 1i
.
Чтобы использовать смешанные дроби в мнимых числах, нужно взять смешанную дробь в круглые скобки: (например, (1 2/5)i
)
Genius также поддерживает логические значения. Определены две логические константы: true
и false
; их можно использовать, как и любую переменную. В качестве псевдонимов к ним можно также использовать True
, TRUE
, False
и FALSE
.
Там, где требуется логическое выражение, можно использовать логическое значение или любое выражение, дающее в результате число или логическое значение. Если Genius нужно использовать число как логическое значение, он будет интерпретировать 0 как false
и любое другое число как true
.
Кроме того, с логическими значениями можно выполнять арифметические операции. Например:
( (1 + true) - false ) * true
это то же самое, что и:
( (true or true) or not false ) and true
Поддерживаются только сложение, вычитание и умножение. Если вы используете в выражении смесь чисел с логическими значениями, то числа преобразовываются в логические значения, как описано выше. То есть, результатом выражения:
1 == true
всегда будет true
, так как 1 преобразовывается в true
перед сравнением с true
.
Like numbers and Booleans, strings in GEL can be stored as values inside variables and passed to functions. You can also concatenate a string with another value using the plus operator. For example:
a=2+3;"Результат равен: "+a
will create the string:
Результат равен: 5
You can also use C-like escape sequences such as \n
,\t
,\b
,\a
and \r
. To get a \
or "
into the string you can quote it with a \
. For example:
"Косая черта: \\ Кавычки: \" Табуляция: \t1\t2\t3"
will make a string:
Косая черта: \ Кавычки: " Табуляция: 1 2 3
Do note however that when a string is returned from a function, escapes are
quoted, so that the output can be used as input. If you wish to print the
string as it is (without escapes), use the
print
or
printn
functions.
In addition, you can use the library function string
to convert anything to a string. For example:
string(22)
will return
"22"
Strings can also be compared with ==
(equal), !=
(not equal) and <=>
(comparison) operators
There is a special value called
null
. No operations can be performed on
it, and nothing is printed when it is returned. Therefore,
null
is useful when you do not want output from an
expression. The value null
can be obtained as an expression when you
type .
, the constant null
or nothing.
By nothing we mean that if you end an expression with
a separator ;
, it is equivalent to ending it with a
separator followed by a null
.
Пример:
x=5;. x=5;
Некоторые функции возвращают null
, если невозможно вернуть значение или произошла ошибка. Также null
используется как пустой вектор или матрица, или пустая ссылка.