Chapter 5. Βασικά της GEL

Table of Contents

Τιμές
Αριθμοί
Λογικές τιμές
Συμβολοσειρές
Null
Χρήση μεταβλητών
Ορισμός μεταβλητών
Ενσωματωμένες μεταβλητές
Προηγούμενη μεταβλητή αποτελέσματος
Χρησιμοποίηση συναρτήσεων
Ορισμός συναρτήσεων
Κατάλογοι ορισμάτων μεταβλητής
Πέρασμα συναρτήσεων σε συναρτήσεις
Πράξεις σε συναρτήσεις
Διαχωριστικό
Σχόλια
Μετρικός υπολογισμός
Κατάλογος τελεστών GEL

GEL σημαίνει γλώσσα επέκτασης Genius. Είναι η γλώσσα που χρησιμοποιείτε για να γράψετε προγράμματα στη Genius. Ένα πρόγραμμα στη GEL είναι απλά μια παράσταση που υπολογίζει έναν αριθμό. Το Εργαλείο μαθηματικών Genius μπορεί να χρησιμοποιηθεί ως μια απλή αριθμομηχανή, ή ως ένα ισχυρό θεωρητικό εργαλείο αναζήτησης. Η σύνταξη πρέπει να έχει όσο πιο ρηχή καμπύλη μάθησης γίνεται, ειδικά για χρήση ως αριθμομηχανή.

Τιμές

Οι τιμές στην GEL μπορεί να είναι αριθμοί, Λογικές τιμές ή συμβολοσειρές. Η GEL θεωρεί επίσης πίνακες ως τιμές. Οι τιμές μπορεί να χρησιμοποιηθούν σε υπολογισμούς, εκχωρημένες σε μεταβλητές και να επιστραφούν από τις συναρτήσεις, μεταξύ άλλων χρήσεων.

Αριθμοί

Integers are the first type of number in GEL. Integers are written in the normal way.

1234

Hexadecimal and octal numbers can be written using C notation. For example:

0x123ABC
01234

Or you can type numbers in an arbitrary base using <base>\<number>. Digits higher than 10 use letters in a similar way to hexadecimal. For example, a number in base 23 could be written:

23\1234ABCD

The second type of GEL number is rationals. Rationals are simply achieved by dividing two integers. So one could write:

3/4

to get three quarters. Rationals also accept mixed fraction notation. So in order to get one and three tenths you could write:

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)

Important

Κατά την εισαγωγή φανταστικών αριθμών, ένας αριθμός πρέπει να είναι μπροστά από το i. Αν χρησιμοποιήσετε i αυτό καθεαυτό, η Genius θα το ερμηνεύσει ως αναφορά στη μεταβλητή i. Αν χρειάζεται να αναφέρετε το i αυτό καθεαυτό, χρησιμοποιήστε 1i στη θέση του.

Για να χρησιμοποιήσετε μικτή σημειογραφία κλάσματος με φανταστικούς αριθμούς, πρέπει να έχετε το μικτό κλάσμα σε παρενθέσεις. (δηλαδή, (1 2/5)i)

Λογικές τιμές

Η Genius επίσης υποστηρίζει εγγενείς λογικές τιμές. Οι δύο σταθερές λογικών τιμών ορίζονται ως true και false· αυτά τα αναγνωριστικά μπορούν να χρησιμοποιηθούν όπως κάθε άλλη μεταβλητή. Μπορείτε επίσης να χρησιμοποιήσετε τα αναγνωριστικά True, TRUE, False και FALSE ως παραλλαγές για τα παραπάνω.

Σε οποιαδήποτε θέση όπου αναμένεται παράσταση λογικών τιμών, μπορείτε να χρησιμοποιήσετε μια λογική τιμή ή οποιαδήποτε παράσταση παράγει ή έναν αριθμό ή μια λογική τιμή. Αν η Genius χρειάζεται να υπολογίσει έναν αριθμό ως λογική τιμή θα ερμηνεύσει το 0 ως ψευδή και οποιοδήποτε άλλο αριθμό ως αληθή.

In addition, you can do arithmetic with Boolean values. For example:

( (1 + true) - false ) * true

is the same as:

( (true or true) or not false ) and true

Only addition, subtraction and multiplication are supported. If you mix numbers with Booleans in an expression then the numbers are converted to Booleans as described above. This means that, for example:

1 == true

always evaluates to true since 1 will be converted to true before being compared to 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;"The result is: "+a

will create the string:

The result is: 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:

"Slash: \\ Quotes: \" Tabs: \t1\t2\t3"

will make a string:

Slash: \ Quotes: " Tabs: 	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

Null

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.

Example:

x=5;.
x=5;

Κάποιες συναρτήσεις επιστρέφουν null, όταν καμιά τιμή δεν μπορεί να επιστραφεί ή όταν συμβαίνει ένα σφάλμα. Επίσης η null χρησιμοποιείται ως ένα κενό διάνυσμα ή πίνακας, ή μια κενή αναφορά.