> <\body> In this section, we describe the basic types of . For the other types, provided by the extension packages, see their respective documentation. The default type of an object is and the corresponding variable type is : <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> a := x <|unfolded-io> <\unfolded-io> <|unfolded-io> type a <|unfolded-io> > The usual boolean constants are and . The equality and inequality tests are and . To build boolean expressions, we use the operators , and the negation operator . <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> a = a <|unfolded-io> <\unfolded-io> <|unfolded-io> a != a <|unfolded-io> <\unfolded-io> <|unfolded-io> a = b and a != c <|unfolded-io> <\unfolded-io> <|unfolded-io> a = b or a != c <|unfolded-io> <\unfolded-io> <|unfolded-io> !( a = b or a != c) <|unfolded-io> Strings can be braced into double quotes . Inside such a string a double quote must be blackslashed. In order to avoid blackslashing one can use the stronger string delimiters . <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> s1 := "This is a string" <|unfolded-io> <\unfolded-io> <|unfolded-io> s2: String := "Print \\"foo\\" " <|unfolded-io> <\unfolded-io> <|unfolded-io> s2 := /" Print "foo" "/ <|unfolded-io> <\unfolded-io> <|unfolded-io> s3 := s2 \\ " and \\"fii\\" " <|unfolded-io> <\unfolded-io> <|unfolded-io> s2 \\ /" and "fuu" "/ <|unfolded-io> <\unfolded-io> <|unfolded-io> #s1 <|unfolded-io> <\unfolded-io> <|unfolded-io> search_forwards (s2, "Print", 0) <|unfolded-io> <\unfolded-io> <|unfolded-io> replace (s2, "fuu", "haha") <|unfolded-io> An integer literal is a sequence of digits, possibly preceded by a minus sign. It matches the regular expression . Examples: , . The default type for integers is . It corresponds to machine type . The usual arithmetic operators are available, as well as the inplace operators . <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> a := 2 <|unfolded-io> <\unfolded-io> <|unfolded-io> a+3; a-5; a*a <|unfolded-io> <\unfolded-io> <|unfolded-io> a += 1; a *= 2; a -= 3 <|unfolded-io> <\unfolded-io> <|unfolded-io> 5 div 2 <|unfolded-io> <\unfolded-io> <|unfolded-io> 5 rem 2 <|unfolded-io> By default, the floating point literals are converted to types. A floating literal is a sequence of digits with a decimal point inside and an optional exponent. It matches the regular expression . Note that is not permitted, >; <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> 2.1 <|unfolded-io> <\unfolded-io> <|unfolded-io> 2.1*3 <|unfolded-io> <\unfolded-io> <|unfolded-io> 2.3/2-1 <|unfolded-io> The type can be used to produce document outputs, represented as lisp-type expressions. It is automatically parsed by TeXmacs to display these outputs. <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> type_mode?:=true <|unfolded-io> : <\unfolded-io> <|unfolded-io> 'x <|unfolded-io> : <\unfolded-io> <|unfolded-io> '(f (x, y, z)) <|unfolded-io> >: <\unfolded-io> <|unfolded-io> '(f (x, y, z)) [2] <|unfolded-io> : <\unfolded-io> <|unfolded-io> $document ("Some ", $with ("color", "red", "red"), " text."; \ \ \ \ \ \ \ \ \ \ \ "Pythagoras said ", $math ('(a^2 + b^2 = c^2)), ".") <|unfolded-io> <\text> Some text. Pythagoras said +b=c>. Vectors are sequences of elements, stored in an array and with a direct access through their index. Their type is parametrized by the type of the elements. The default type is . The indices start from 0. The length of a vector is given by the prefix operator . The concatenation of vectors is performed by the operator \>. The inplace concatenation of vectors is done by the operator \>. The classical operations are available on vectors. <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> v := [1,2,3] <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> v[0]+v[1]+v[2] <|unfolded-io> : <\unfolded-io> <|unfolded-io> #v <|unfolded-io> : <\unfolded-io> <|unfolded-io> w := v \\ [4,5] <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> v \\ [1,2] <|unfolded-io> >: |)>> <\unfolded-io> <|unfolded-io> [car v, cdr v, cons (3, v)] <|unfolded-io> ,|]>>: > <\unfolded-io> <|unfolded-io> reverse v <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> contains?(v,1) <|unfolded-io> : Tuples are written inside .... Elements are separated by , which is associative, so that is the same as . <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> v := (1, 2, 3) <|unfolded-io> > <\unfolded-io> <|unfolded-io> (1, (2, 3)) <|unfolded-io> > <\unfolded-io> <|unfolded-io> v:= [1, 2]; (v, ((v))) <|unfolded-io> ,|)>> Row-tuples rows are separated by , as exemplified with the constructions of matrices (defined in the package): <\session|mathemagix|default> <\input> <|input> use "algebramix" <\unfolded-io> <|unfolded-io> (1, 2; 3, 4; 5, 6) <|unfolded-io> ||>>|)>>: > <\unfolded-io> <|unfolded-io> [1, 2; 3, 4; 5, 6] <|unfolded-io> ||>>|]>>: > Automatic constructions are possible through the notation: <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> ( i^2 \| i in 1..3 ) <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> [ i * j \| i in 1..3, j in 1..4 ] <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> matrix ( i*j \| i in 1..5 \|\| j in 1..5 ) <|unfolded-io> |||>>|]>>: > means the range [a,b], while stands for the half open range [a,b). <\session|mathemagix|default> <\unfolded-io> <|unfolded-io> (1 to 4) <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> 1 .. 4 <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> [1..6] <|unfolded-io> >: > <\unfolded-io> <|unfolded-io> [i*i \| i in 1 to 10] <|unfolded-io> >: > Tables allow to store the association between keys of one type and values of another type. They are defined by providing a default value. The default type for tables used in the interpreter is . In the following example, the default value is : <\session|mathemagix|default> <\input> <|input> t := table(1); <\unfolded-io> <|unfolded-io> t[1] \ := -3; t[34] := \ 2 <|unfolded-io> <\unfolded-io> <|unfolded-io> t[0] <|unfolded-io> <\unfolded-io> <|unfolded-io> contains? (t,2) <|unfolded-io> There is an output stream, which is called . It can be used with the operator \> to print strings: <\session|mathemagix|default> <\input> <|input> type_mode?:= true; <\unfolded-io> <|unfolded-io> mmout <|unfolded-io> |)>>: <\unfolded-io> <|unfolded-io> mmout \\ "Hello\\n"; <|unfolded-io> Hello <\unfolded-io> <|unfolded-io> i := 3; mmout \\ "The square of " \\ i \\ " is " \\ i*i \\ "\\n";\ <|unfolded-io> The square of is Output streams can also be defined from files. Here we write a string into the file , and we load the contents of this file into a string: <\session|mathemagix|default> <\input> <|input> output_file_port ("toto.txt") \\ "Hi there\\n"; <\unfolded-io> <|unfolded-io> load ("toto.txt") <|unfolded-io> : Here are some useful commands to read and save data in files. The command to read a file and to evaluate it is . The command to save a in a file is .\ The file names in a directory can be recovered by the command . The result is a vector of strings, which corresponds to the name of a file or a subdirectory. To check if a file or a directory exists, one can use the predicate . <\session|mathemagix|default> <\input|> include "example.mmx" <\input> <|input> save ("tmp.txt", "A string is stored in the file \\n in two lines"); <\unfolded-io> <|unfolded-io> load "tmp.txt" <|unfolded-io> : <\unfolded-io> <|unfolded-io> load_directory "." <|unfolded-io> ,,,,|]>>: > Several functions are available to interact with the environment. To get the value of a variable defined in the environment, one can use .\ To run a command in this environement, one can use the function :. <\session|mathemagix|default> <\unfolded-io|> get_env "PWD" <|unfolded-io> <\unfolded-io|> set_env ("DISPLAY", "arthur:0") <|unfolded-io> <\unfolded-io> <|unfolded-io> system "ls" <|unfolded-io> emacs_mode.en.tm how_to.en.tm index.en.tm installation.en.tm quick_start.en.tm shell.en.tm shell_tutorial.en.tm syntax.en.tm tmp.txt toto.txt : . If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.>