{\rtf1\mac\deff2 {\fonttbl{\f0\fswiss Chicago;}{\f2\froman New York;}{\f3\fswiss Geneva;}{\f4\fmodern Monaco;}{\f6\fdecor London;}{\f8\fdecor San Francisco;}{\f11\fnil Cairo;}{\f12\fnil Los Angeles;}{\f13\fnil Zapf Dingbats;}{\f14\fnil Bookman;} {\f16\fnil Palatino;}{\f18\fnil Zapf Chancery;}{\f20\froman Times;}{\f21\fswiss Helvetica;}{\f22\fmodern Courier;}{\f23\ftech Symbol;}{\f24\fnil Mobile;}{\f33\fnil Avant Garde;}{\f34\fnil New Century Schlbk;}{\f101\fnil Wartburg;}{\f118\fnil Warwick S;} {\f128\fnil Moscow;}{\f129\fnil Russian;}{\f135\fnil MATH-BES;}{\f140\fnil Lovell;}{\f149\fnil Detroit;}{\f171\fnil XB Futura ExtraBold;}{\f176\fnil H Futura Heavy;}{\f201\fnil ¡Math;}{\f512\fnil Alexandrie;}{\f2500\fnil Konstanz;}} {\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;}{\stylesheet{\s243\qj\tqc\tx4320\tqr\tx8640 \f20 \sbasedon0\snext243 footer;}{\s247\qj\li720 \i\f20\fs20 \sbasedon0\snext0 heading 9;}{\s248\qj\li720 \i\f20\fs20 \sbasedon0\snext0 heading 8;}{\s249\qj\li720 \i\f20\fs20 \sbasedon0\snext0 heading 7;}{\s250\qj\li720 \f20\fs20\ul \sbasedon0\snext0 heading 6;}{\s251\qj\li720 \b\f20\fs20 \sbasedon0\snext0 heading 5;}{\s252\qj\li354\sb40\sa40 \f20\ul \sbasedon0\snext0 heading 4;}{\s253\qj\li354\sb120\sa80 \b\f20 \sbasedon0\snext0 heading 3;}{\s254\qj\sb200\sa140 \b\f20\fs36\ul \sbasedon0\snext0 heading 2;}{\s255\qc\sb240 \b\f20\fs48 \sbasedon0\snext0 heading 1;}{\qj \f20 \sbasedon222\snext0 Normal;}{\s2\sb120\keep\keepn \b\f22 \sbasedon0\snext2 input;}{\s3 \f22\fs20 \sbasedon0\snext3 output;}{\s4\qj\li1120 \f20\fs20 \sbasedon0\snext4 commentaire;}}{\info{\title chap4.doc}{\author EBM}}\paperw11880\paperh16800\margl1701\margr1701\margt1417\margb1417\deftab709\widowctrl\ftnbj\pgnstart36 {\*\nextfile disque dur:chap5.doc}\sectd \sbknone\linemod0\linex0\headery1077\footery1077\cols1\colsx709\endnhere {\footer \pard\plain \s243\qj\tqc\tx4320\tqr\tx8640 \f20 \par \pard \s243\qc\tqc\tx4320\tqr\tx8640 {\fs20 Calcul formel avec Maple page }{\fs20 \chpgn }\par \pard \s243\qj\tqc\tx4320\tqr\tx8640 \par }\pard\plain \s255\qc\sb240 \b\f20\fs48 Les structures de donn\'8ees\par \pard\plain \qj \f20 Maple est un langage qui est typ\'8e au niveau des objets, mais non typ\'8e au niveau des variables, c'est \'88 dire que toute variable peut contenir un objet de n'importe quel type (contrairement \'88 Pascal ou C). Dans ce chapitre nous allons nous int\'8eresser aux types des objets (et non des variables), puis au contr\'99le des types et enfin aux m\'8ecanismes de l'\'8evaluation des objets.\par \pard\plain \s254\qj\sb200\sa140 \b\f20\fs36\ul I. Types simples\par \pard\plain \qj \f20 Nous avons d\'8ej\'88 rencontr\'8e pr\'8ec\'8edemment la plupart des types simples.\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 1. Types num\'8eriques\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?integer\par \pard\plain \s4\qj\li1120 \f20\fs20 SYNOPSIS: \par \pard \s4\qj\li1120 - An expression is of type integer if it is an (optionally signed) sequence of one or more digits of arbitrary length. The length limit of an integer is system dependent but generally much larger than users will encounter -- typically great er than 500,000 decimal digits.\par \pard \s4\qj\li1120 - In addition to arithmetic operators, other basic functions of integers are\par abs sign min max factorial\par irem iquo modp mods mod\par isqrt iroot isprime ifactor ifactors\par igcd ilcm igcdex iratrecon rand\par \pard \s4\qj\li1120 - There are also many special functions for integers in the numtheory and combinat packages including the binomial coefficients, Fibonacci numbers, Stirling numbers, Jacobi symbol, Eulers totient function etc.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?fraction\par \pard\plain \s4\qj\li1120 \f20\fs20 SYNOPSIS: \par - / \par \pard \s4\qj\li1120 - An expression of type fraction is represented by a pair of integers (numerator and denominator) with all common factors removed and with a positive denominator.\par \pard \s4\qj\li1120 - Like integers, fractions can be of arbitrary length.\par \pard \s4\qj\li1120 - The op function considers the fraction data type to have two operands, where the first operand is the numerator and the second operand is the denominator.\par \pard \s4\qj\li1120 - A rational is defined to be either an integer or a fraction.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?float\par \pard\plain \s4\qj\li1120 \f20\fs20 CALLING SEQUENCE:\par .\par .\par .\par Float(mantissa, exponent)\par PARAMETERS:\par mantissa, exponent - integers\par SYNOPSIS: \par \pard \s4\qj\li1120 - A floating-point number (called type float) is shown as a sequence of digits with a decimal point.\par \pard \s4\qj\li1120 - Floating-point numbers are represented internally by a pair of integers (the mantissa and the exponent), which represent the number mantissa * 10^(exponent). The exponent is ``word-size'' but the mantissa can be of any length. \par - An alternative way to input floating-point numbers is Float(mantissa, exponent) which corresponds to the internal representation. The latter notation is used to output numbers with very small or very large magnitudes.\par \pard \s4\qj\li1120 - The op function considers this data type to have two operands: the mantissa and the exponent. For example, op(150.1) yields 1501, -1.\par \pard \s4\qj\li1120 - Arithmetic with floating-point numbers is performed by the evalf function, although floating-point evaluation takes place automatically for arithmetic operations whenever one of the operands is a float.\par \pard \s4\qj\li1120 - The number of digits carried in the mantissa for floating-point arithmetic is determined by the global variable Digits (default 10).\par \pard\plain \qj \f20 Remarquons que Maple (contrairement \'88 d'autres langages de calcul formel) ne connait pas de type complexe. Pour lui un complexe est une expression alg\'8ebrique de la forme a+b*sqrt(-1) qui s'\'8e crit sous la forme a+b*I par l'interm\'8ediaire d'un {\i alias}.\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 2. Les chaines de caract\'8fres et le type "name"\par \pard\plain \qj \f20 Les cha\'94nes de caract\'8fre ont dans Maple un double r\'99le. D'une part elles servent (comme en Pascal ou en C) \'88 stocker des expressions alphanum\'8eriques, mais elles servent \'8egalement comme variables. C'est l\'88 un premier aspect d\'8eroutant de la plupart des langages de calcul formel. Alors qu'en Pascal ou en C il n'y a aucun risque de confusion entre la variable {\i monTableau } et la cha\'94ne de caract\'8fres {\i "monTableau"} (en C, {\i 'monTableau' } ), dans Maple il n'y a aucune diff\'8erence. Une cha\'94ne de caract\'8fres devient automatiquement une variable par le seul fait qu'on l'utilise en tant que telle (et en particulier si on l' affecte). En fait, le vocabulaire des concepteurs de Maple \'8e tablit une dsitinction artificielle mais utile entre les cha\'94nes de caract\'8fre utilis\'8ees en tant que telles ({\b string}) et les cha\'94nes de caract\'8fres utilis\'8ees comme variables ({\b name} ), mais il faut savoir que rien dans le langage ne distingue les deux et que l'on peut au cours d'une m\'90me seance ou proc\'8edure utiliser le m\'90me objet alternativement dans un sens ou dans l'autre.\par \pard \qj \tab Une cha\'94ne de caract\'8fres est d\'8elimit\'8ee par des {\b accents graves} (en anglais backquotes) que l'on prendra garde \'88 ne pas confondre avec les accents aigus ou apostrophes qui servent \'88 emp\'90cher une \'8e valuation. Ces accents graves sont facultatifs si la cha\'94ne de caract\'8fres satisfait aux r\'8fgles habituelles de formation des noms de varaibles dans les langages de haut niveau (commencer par une lettre ou un _ et ne comporter que des caract\'8f res alphanum\'8eriques).\par \pard \qj \tab Ceci a pour cons\'8equence que rien ne vous interdit de nommer une variable comme `n-1` ou `Monsieur le Pr\'8esident Directeur G\'8en\'8e ral` avec tous les risques de confusion que cela comporte au niveau de l'affichage (imaginez l'affectation `n-1`:=n-1).\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?string\par \pard\plain \s4\qj\li1120 \f20\fs20 SYNOPSIS: \par \pard \s4\qj\li1120 - A name is usually a string, which in its simplest form is a letter followed by zero or more letters, digits, and underscores with lower and upper case letters distinct. The maximum length of a name is 499 characters.\par \pard \s4\qj\li1120 - Any expression may be assigned to a name. If no value has been assigned to the name then it stands for itself.\par - More generally, names (strings) may be formed with the concatenation operator: . or with the function: cat.\par \pard \s4\qj\li1120 - A string may also be formed by enclosing any sequence of characters in a pair of backquotes ` `. Since any string is a valid in Maple, the following is valid: `This is a name!` := 1.\par \pard \s4\qj\li1120 - For any valid Maple name formed without using backquotes, the name formed by surrounding it with backquotes is precisely the same name. Thus x and `x` both refer to the same name x. However, a keyword may not be used as a name or string unless it is enclosed in backquotes.\par \pard \s4\qj\li1120 - Strings formed using backquotes are often used in the sense of character strings rather than names. A common example is the string used as an error message, as in: ERROR(`the argument must be an integer`).\par \pard \s4\qj\li1120 - Two successive backquotes appearing after the opening of a string will be parsed as a single backquote. Thus, `abc``de` yields abc`de.\par - The type function understands the typenames string and indexed, and type name is defined to be either of: string or indexed.\par \pard\plain \s254\qj\sb200\sa140 \b\f20\fs36\ul II. Types compos\'8es\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 1. Sequences\par \pard\plain \qj \f20 Le type compos\'8e le plus simple (et celui qui provoque le plus de surprise) est la s\'8equence. Il s'agit uniquement d'une suite d'objets Maple s\'8epar\'8es par une virgule. En particulier les param\'8ftres d'une fonction, les \'8e l\'8ements d'une liste ou d'un ensemble forment une s\'8equence. le type des s\'8equences est {\b exprseq}.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?sequence\par \pard\plain \s4\qj\li1120 \f20\fs20 SYNOPSIS: \par \pard \s4\qj\li1120 - Expression sequences, (or simply sequ ences), are created using the comma operator ,. For example s := 1,2,3 assigns s the sequence 1,2,3. In Maple, sequences form the basis of many data types. In particular, they appear in function calls, lists, sets and subscripts. \par \pard \s4\qj\li1720 Example:\par - f(s) applies the function f to the sequence 1,2,3,\par - [s] creates the list containing the elements 1,2,3,\par - \{s\} creates the set containing the elements 1,2,3, and\par - a[s] is the 1,2,3 subscript.\par - These are equivalent to f(1,2,3), [1,2,3], \{1,2,3\}, and a[1,2,3] respectively. \par \pard \s4\qj\li1120 - When sequences are concatenated with a comma, the result is a single, unnested sequence. Thus t := s,s assigns t the sequence 1,2,3,1,2,3. The empty sequence is available as the value of the global variable NULL. It also appears implicitly in the e mpty list [], the empty set \{\}, a function call f() with no parameters, and an indexed name a[] with no subscripts.\par \pard \s4\qj\li1120 - Two key tools for constructing sequences are the {\b seq} function and the repetition operator {\b $}. For example, the call seq(f(i ), i=1..3) will generate the sequence f(1), f(2), f(3). The call x$3 will generate the sequence x, x, x.\par - Sequences can also be constructed using the op function. The op function when applied to any Maple expression (except a sequence itself) returns a sequence of the operands of that expression. For example, op([x,y,z]) and op(x+y+z) both return the se quence x, y, z.\par \pard \s4\qj\li1120 - The op and nops functions cannot be applied to a sequence because the elements of the sequence are taken to be individual arguments to the function. However, the i-th operand of a sequence s may be accessed using the selection operation s[i]. The length of a sequence may be determined by doing nops([s]), that is, by determining the length of the list containing the expression seq uence.\par \pard \s4\qj\li1120 \par \pard\plain \qj \f20 On peut cr\'8eer une s\'8equence soit en \'8ecrivant les objets s\'8epar\'8es par une virgule soit en utilisant une fonction de construction de sequence comme {\b seq} ou l'op\'8erateur de r\'8ep\'8etition\~{\b $}.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?seq\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: seq - create a sequence\par CALLING SEQUENCE:\par seq(y, i = m..n)\par seq(y, i = x)\par PARAMETERS:\par y - any expression\par i - name\par m, n - numerical values\par x - an expression\par SYNOPSIS: \par \pard \s4\qj\li1120 - The seq function is related to the for loop construct. It behaves in a similar manner to for except that seq constructs a sequence of values.\par \pard \s4\qj\li1120 - The most typical call is seq(f(i), i = 1..n) which generates the sequence f(1), f(2), ..., f(n). More generally, seq(f(i), i = m..n) generates the sequence f(m), f(m+1), f(m+2), ..., f(n). Here m and n do not have to b e integers.\par \pard \s4\qj\li1120 - The call seq(f(i), i = x) generates a sequence by applying f to each operand of x. Here, x would most commonly be a set or list, but could be a sum, product, etc.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?$\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: $ - operator for forming an expression sequence\par CALLING SEQUENCE:\par expr $ i = m..n; expr $ n; $ m..n;\par PARAMETERS:\par expr - an expression\par i - an unevaluated name\par m,n - expressions\par SYNOPSIS: \par - $ returns the expression sequence produced by substituting for i in expr the\par values m,m+1,...,n (or up to the last value not exceeding n).\par \pard \s4\qj\li1120 - If m>n then the NULL expression sequence is returned.\par - A call to $ in the form: $ m..n; will have the same effect as the call:\par i $ i = m..n;.\par - A call to $ in the form: expr $ n; will have the same effect as the call:\par expr $ i = 1..n ; (assuming that expr does not contain i).\par - Note: It is recommended (and often necessary) that both 'expr' and 'i' be\par enclosed in single quotes to prevent premature evaluation. (E.g., i may have\par had a previous value). I.e., the common format is 'expr' $ 'i' = m..n;\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 2. Listes\par \pard\plain \qj \f20 Une liste dans Maple est une suite d'objets ordonn\'8es, s\'8epar\'8es par des virgules et encadr\'8es par des crochets. Une liste est donc de la forme {\b [}{\i sequence }{\b ]}.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?list\par \pard\plain \s4\qj\li1120 \f20\fs20 CALLING SEQUENCE:\par [es] \par PARAMETERS:\par es - an expression sequence\par SYNOPSIS: \par - A list is an ordered sequence of expressions enclosed in square brackets. The ordering of the expressions is the ordering of es.\par - Note that es may be empty so that the empty list is represented by [].\par - The elements of list may be extracted via the selection operation. Thus, if S is a set or list then the i-th element of S can be obtained by: S[i] or equivalently, op(i,S).\par \pard\plain \qj \f20 Les listes peuvent \'90tre construites explicitement, ou alors en utilisant les fonctions de construction de s\'8equences. Un certain nombre d'op\'8erateurs s'appliquent aux listes comme union, intersect, minus, member.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet [x,y,y,z];\par \pard\plain \s3 \f22\fs20 [x, y, y, z]\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet [seq(i^2,i=-2..5)];\par \pard\plain \s3 \f22\fs20 [4, 1, 0, 1, 4, 9, 16, 25]\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet [$1..6];\par \pard\plain \s3 \f22\fs20 [1, 2, 3, 4, 5, 6]\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 3. Ensembles\par \pard\plain \qj \f20 Un ensemble dans Maple est une suite d'objets distincts, non ordonn\'8es, s\'8epar\'8es par des virgules et encadr\'8es par des accolades Une liste est donc de la forme {\b \{}{\i sequence }{\b \}}. Un ensemble est toujours simplifi \'8e par Maple pour \'8eviter les r\'8ep\'8etitions et il est stock\'8e et affich\'8e dans un ordre interne \'88 Maple, sur lequel on n'a aucune prise.\par \par \pard\plain \s4\qj\li1120 \f20\fs20 CALLING SEQUENCE:\par \{es\} \par PARAMETERS:\par es - an expression sequence\par SYNOPSIS: \par - A set is an unordered sequence of di stinct expressions enclosed in braces, representing a set in the mathematical sense. The user should not assume that the expressions will be maintained in any particular order because Maple uses an ordering convenient for its implementation.\par - Note that es may be empty so that the empty set is represented by \{\}.\par - The elements of a setmay be extracted via the selection operation. Thus, if S is a set or list then the i-th element of S can be obtained by: S[i] or equivalently, op(i,S).\par \pard\plain \qj \f20 Les ensembles peuvent \'90tre construits explicitement, ou alors en utilisant les fonctions de construction de s\'8equences. Un certain nombre d'op\'8erateurs s'appliquent aux ensembles comme union, intersect, minus, member.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet \{z,x,y,y\};\par \pard\plain \s3 \f22\fs20 \{x, y, z\}\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet \{seq(i^2,i=-2..5)\};\par \pard\plain \s3 \f22\fs20 \{0, 1, 4, 9, 16, 25\}\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet \{$1..6\};\par \pard\plain \s3 \f22\fs20 \{1, 2, 3, 4, 5, 6\}\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 4. Type index\'8e\par \pard\plain \qj \f20 Le type index\'8e est une facilit\'8e de Maple pour cr\'8eer de nouveaux noms \'88 l'aide d'un symbole index\'8e. C'est ainsi que, de m\'90me qu'en Math\'8ematiques on peut nommer trois points du plan sous la forme A{\dn4 1}, A{\dn4 2 } et A{\dn4 3}, on peut cr\'8eer en Maple trois noms A[1], A[2] et A[3]. Bien entendu, les indices peuvent \'90tre des s\'8equences de n'importe quels objets Maple. On prendra garde \'88 ne pas confondre les objets index\'8e s de Maple avec les tableaux de Pascal ou C.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?indexed\par \pard\plain \s4\qj\li1120 \f20\fs20 CALLING SEQUENCE:\par [ ]\par SYNOPSIS: \par - [ ]\par - An indexed name may appear anywhere a name may appear. In particular, since A[1,2,3] is valid so is A[1,2,3][x,y] and A[1,2,3][x,y][2,1].\par - The op function applied to an indexed name yields the expression sequence of indices appearing within the rightmost brackets, and the zero'th operand is the corresponding .\par - The use of the indexed name b[1] does not imply that b is an array. For instance: \par \tab \tab a := b[1] + b[2] + b[1000]; \par simply forms a sum of three indexed names.\par - The assignment of a value to an indexed name will implicitly create a table. Thus the statement:\par \tab \tab b[1] := 10; \par creates a table for b and assigns the value 10 to the component of the table indexed by 1.\par \par \pard\plain \qj \f20 On prendra garde \'8egalement \'88 ne pas confondre les crochets des symboles index\'8es avec les crochets qui permettent d'acc\'8eder (en tant que {\i rvalue} ne pouvant \'90tre affect\'8ee) aux diff\'8erents \'8el\'8ements d'une s \'8equence, d'une liste ou d'un ensemble.\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 5. Tables\par \pard\plain \qj \f20 La structure de table est tout \'88 fait particuli\'8fre \'88 Maple. Elle reprend la notion math\'8ematique de famille index\'8ee, avec la seule diff\'8erence que, alors qu'en mat\'8ematiques on notre a{\fs20\dn4 i} , en Maple on note a[i]. Bien entendu, aussi bien en math\'8ematiques qu'en Maple, "i " peut \'90tre une s\'8equence, et alors on notera a[i,j,k,\'c9] \'88 la place de a{\dn4 i,j,k,\'c9}.\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?table\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: table - create a table\par CALLING SEQUENCE:\par table( F, L )\par PARAMETERS:\par F - (optional) the indexing function\par L - (optional) list of initial table entries\par SYNOPSIS: \par - A table is created either explicitly by a call to the table function or implicitly by assigning to an indexed name. Unlike arrays, where indices must be integers, {\b the indices (or keys) of a table can be any value}.\par - The table function creates a table with initial values specified by L. If L is a list of equations then the left-hand-side is taken to be the table index (key), and the right-hand-side the entry (value). Otherwise, L is taken to be a list of entries with indices 1, 2, ... etc. If L is not specified, then an empty table is created.\par - New entries can be added to a table using the subscript notation. Thus T := table([ 4]) is equivalent to: T := table() and T[1] := 4 or equivalently: T[1] := 4 if T was unassigned (implicit creation). Entries can be removed from a table by assigning a table entry to its own name. Thus T[1] := 'T[1]' removes the entry 4 from T.\par - The indexing function F can be a procedure or a name specifying how indexing is to be performed; if null then ordinary indexing is implied. The built in indexing functions are: symmetric, antisymmetric, sparse, diagonal, and identity. \par - Tables have speci al evaluation rules (like procedures) so that if the name T has been assigned a table then T evaluates to T. The call op(T) yields the actual table structure; and op(op(T)) yields the components of the table, i.e. the indexing function (if there is one ) and a list of equations for the tables values.\par - The indices function can be used to obtain a sequence of a tables indices and likewise, the entries function returns a sequence of the table's entries.\par \pard\plain \qj \f20 Il faut donc faire un certain nombre de remarques:\par \tab - les indices d'une table n'ont aucune raison d'\'90tre entiers ni m\'90me d'\'90tre homog\'8fnes, rien ne vous interdit de poser a[1]:=1 et a[sin,alpha,2]:=x\par \tab - si aucune fonction d'indexage n'est fournie, les appels a[{\i sequence d'indices} ] non affect\'8es retournent simplement non \'8evalu\'8es, il n'y a donc pas de d\'8ebordement possible (au contraire de Pascal ou C); le r\'99 le des fonctions d'indexage est de donner des valeurs par d\'8efaut aux a[{\i sequence d'indices} ]\par \tab - les tables peuvent \'90tre cr\'8e\'8ees explicitement par la fonction {\b table} mais aussi implicitement simplement en assignant une valeur \'88 un a[...].\par \par Exemple:\par \tab - une table cr\'8e\'8ee explicitement sans initialisations\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet a:=table():{\plain \f20 \line }\bullet a[1]:=1: a[cos,alpha,1]:=x:\line \bullet a[2],a[1],a[x],a[toto,truc],a[cos,alpha,1];\par \pard\plain \s3 \f22\fs20 a[2], 1, a[x], a[toto, truc], x\par \par \pard\plain \qj \f20 \tab - une table cr\'8e\'8ee implicitement avec initialisations\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet b[2,\{x,y\}]:=1: \line \bullet b[1],b[2,x,y],b[2,\{x,y\}];\par \pard\plain \s3 \f22\fs20 b[1], b[2, x, y], 1\par \pard\plain \qj \f20 \par \tab - une table cr\'8e\'8ee explicitement avec initialisations; remarquer la syntaxe des initialisations : {\b (}{\i s\'8equence d'indices }{\b ) = \'c9}\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet c:=table([(1)=1,(cos,alpha,1)=x]):\line \bullet c[cos,alpha,1];\par \pard\plain \s3 \f22\fs20 x\par \par \pard\plain \qj \f20 Les entr\'8ees initialis\'8ees d'une table peuvent \'90tre r\'8ecup\'8er\'8ees avec les fonctions {\b indices} (qui donne les indices affect\'8es sous forme de s\'8equence de listes) et {\b entries} (qui donne, dans le m\'90 me ordre, leurs affectations \'8egalement sous forme de s\'8equence de listes)\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: indices - indices of a table or array , entries - entries of a table or array\par CALLING SEQUENCE:\par indices(t); and entries(t);\par PARAMETERS:\par t - a table or array\par SYNOPSIS: \par - The indices and entries functions return sequences of the indices (or keys) and the entries respectively of the table or array t corresponding to the entries that are explicitly stored.\par - The result returned is a sequence of lists in an apparently arbitrary order which cannot be controlled by the user. There is though a one to one correspondence between the result of indices and entries.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet t:=table([(1,2)=moi,(3,2)=toi,(1,3)=lui]):\par \bullet indices(t);\par \pard\plain \s3 \f22\fs20 [2, 3], [1, 3], [1, 2]\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet entries(t);\par \pard\plain \s3 \f22\fs20 [toi], [lui], [moi]\par \par \pard\plain \qj \f20 Attention: contrairement aux autres objets de Maple, le nom d'une table ne d\'8esigne pas la table elle-m\'90me mais un pointeur sur la table (autrement dit l'adresse en m\'8e moire de la table). C'est ainsi qu'une affectation entre tables ne r\'8ealise par une recopie de la table. Apr\'8fs une affectation du type b:=a, o\'9d a est une table, b ne r\'8ealise pas une copie de a, mais au contraire a et b d\'8esignent la m\'90 me table (en particulier toute modification de b se r\'8epercute sur a et r\'8eciproquement)\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet a[1]:=1: b:=a: b[1]:=x:\line \bullet a[1];\par \pard\plain \s3 \f22\fs20 x\par \pard\plain \qj \f20 De m\'90me, une variable de type table ne renvoie pas le contenu de la table elle m\'90me mais son nom.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet a;\par \pard\plain \s3 \f22\fs20 a\par \pard\plain \qj \f20 Si l'on veut le contenu de a (en fait l'objet point\'8e par a) il faut demander un niveau d'\'8evaluation suppl\'8ementaire.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet eval(a);\par \pard\plain \s3 \f22\fs20 table([\par 1 = x\par ])\par \pard\plain \qj \f20 Pour plus de d\'8etail, voir le paragraphe sur l'\'8evaluation ci-dessous.\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 5. Array\par \pard\plain \qj \f20 \tab Le type {\b array} est un type particulier du type table dans lequel l'ensemble d'indices est un intervalle d'entiers ou un produit cart\'8esien de tels intervalles d'entiers. L'acc\'8fs \'88 un \'8el\'8ement se fait donc n\'8e cessairement sous la forme a[i,j,k,\'c9] dans lequel i,j,k,\'c9 sont des entiers dont le nombre et les bornes sont fix\'8es {\i a priori} . Bien entendu un tel objet doit \'90tre cr\'8e\'8e explicitement pour d\'8e finir le nombre d'indices et les intervalles dans lesquels ils varient. C'est le r\'99le de la fonction {\b array}.\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: array - create an array\par CALLING SEQUENCE:\par array( indexfcn, bounds, list)\par PARAMETERS:\par indexfcn - (optional) an indexing function\par bounds - (optional) sequence of ranges\par list - (optional) list of initial values\par SYNOPSIS: \par - An array is a specialization of a table, with zero or more specified dimensions, where each dimension is an integer range. The result of execu ting the array function is to create an array. For example, V := array(1..10) creates a one dimensional array (a Maple vector) of length 10 but with no explicit entries. The command A := array(1..m,1..n) creates a two dimensional array (a Maple matri x) with m rows and n columns.\par - All parameters to the array function are optional and may appear in any order. The bounds parameter is a sequence of integer ranges which must appear consecutively. If the bounds are not specified then they are deduced from the list of initial values.\par - The indexfcn can be a procedure or a name specifying how indexing is to be performed - see indexfnc for more information. The built-in indexing functions are symmetric, antisymmetric, sparse, diagonal, and identity. If indexfnc is not specified, then ``ordinary'' indexing is used.\par - The list of initial values may be a list of equations (cf. tables), or a list of values (one-dimensional), or a nested list of lists (row-by-row).\par - The map function can be used to apply a function to each entry of an array. For example, map (simplify, A) simplifies each entry of the array A.\par - Arrays have special evaluation rules (like procedures) so that if the name A has been assigned an array then A evaluates to the name A and eval(A) yields the actual array structure.\par - The op function can be used to pick apart an array structure. Specifically op(eval(A)) yields indexfcn, bounds, and entries where entries is a list of equations corresponding to the explicit entries in the array (c f. entries). Hence op(1,eval(A)) returns the array dimensions.\par \pard\plain \qj \f20 Contrairement \'88 une table g\'8en\'8erale, dans une {\b array}, un contr\'99le du nombre d'indices et de leurs bornes est effectu\'8e, si bien qu'aucun d\'8ebordement n'est possible.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet m:=array(1..3,0..2,[(1,1)=1,(3,2)=x]):{\plain \f22 \line }\bullet m[1,2],m[3,2];\par \pard\plain \s3 \f22\fs20 m[1, 2], x\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet m[1];\par \pard\plain \s3 \f22\fs20 Error, index incompatible with bounds\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet m[0,10];\par \pard\plain \s3 \f22\fs20 Error, index outside of bound\par \pard\plain \s254\qj\sb200\sa140 \b\f20\fs36\ul III. Types expressions. Op\'8erandes\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 1. Arbre d'une expression\par \pard\plain \qj \f20 Consid\'8erons une op\'8eration {\i n-aire} que nous noterons &. Si expr{\dn4 1},\'c9,expr{\dn4 n }sont n expressions alg\'8ebriques, nous consid\'8ererons comme \'8equivalentes les expressions\par \pard \qc (expr{\dn4 1)} & \'c9 & (expr{\dn4 n}){\dn4 \par }\pard {\dn4 et\par }\pard \qc {\dn4 &(}expr{\dn4 1},\'c9,expr{\dn4 n}).\par \pard \qj Dans la premi\'8fre notation, nous nous autoriserons \'88 supprimer les parenth\'8fses autour des expressions alg\'8ebriques qui sont r\'8eduites \'88 des atomes. La premi\'8fre forme sera appel\'8ee la forme parenth\'8es\'8e e de l'expression alg\'8ebrique, la deuxi\'8fme forme la forme pr\'8enexe. Un moyen classique de stocker une expression alg\'8ebrique sous forme pr\'8enexe est de la stocker sous forme de liste "\'88 la LISP"\par \pard \qc (& (expr{\dn4 1) }\'c9 (expr{\dn4 n}))\par \pard \qj en supprimant encore une fois les parenth\'8fses autour des atomes.\par Par exemple l'expression Sin(2x+y+f(z)) sera stock\'8ee sous la forme\par \pard \qc {\f22 (Sin (Plus (Mult 2 x) y (f z)))}\par \pard \qj Un autre moyen classique est de la stocker sous forme d'arbre\par \pard \qc {{\pict\macpict\picw356\pich211 022e0000000000d301641101a10064000c574f52440000000000d3016401000a0000000000d3016430000600b4001f00f130007800450091008230003d00b4005600f130007800b2009100ef3000b6000500cf00423000b8007900d100b63000770126009001633000b9012600d20163a10096000c01000000010000000000 00000300140d000e2bc6180353696ea00097a10096000c01000000010000000000000028004f00c104506c7573a00097a10096000c01000000010000000000000028008a0053044d756c74a00097a10096000c0100000001000000000000002800c8001a0132a00097a10096000c0100000001000000000000002b76020178 a00097a10096000c01000000010000000000000028008a00c70179a00097a10096000c01000000010000000000000029780166a00097a10096000c0100000001000000000000002800cc013e017aa00097a000ab61002f00c2004900dcffe8003022001d00cf0019a000ada000ab61006a00600084007a002d003022005500 c2b120a000ada000ab61006a00bf008400d9ffe8003022005500cc001ca000ada000ab610069013e008301580106003022005500de6720a000ada000ab6100a8001800c20032001e00302200900057d322a000ada000ab6100aa008800c400a201210030220090006b2623a000ada000ab6100ac013500c6014fffe8003022 008f01420024a000ada10096000c010000000100000000000000280018000c0e53696e2832782b792b66287a2929a00097ff}}\par \pard \qj \page La solution retenue par Maple (comme par Mathematica) est une solution interm\'8ediaire.\par \par {{\pict\macpict\picw381\pich184 027f0000000000b8017d1101a10064000c574f52440000000000b8017d01000a0000000000b8017d0a0000000000000000340023004300360071383400230070003600d03834005e0073007100a13834005e00a0007101613822007000d900ee220070012300eea10096000c0100000001000000000000000300020d000c2b f46b027920a000973400a2004500b500e6382200b400a500eea10096000c0100000001000000000000002800af0088023220a00097a10096000c0100000001000000000000002932027820a000973400a4010e00b7017c38a10096000c0100000001000000000000002b9a02027a20a00097a10096000c0100000001000000 0000000028000e00701453696e28322078202b2079202b2066287a292920a00097a10096000c01000000010000000000000028006b0003096e6976656175203220a00097a10096000c0100000001000000000000002b0142096e6976656175203320a000970a01020408102040803400a4010e00b7013c383400a2004500b5 00733834005e0073007100a13834002300430036007138a10096000c010000000100000000000000040128006b007505506c757320a00097a10096000c0100000001000000000000002800b00047054d756c7420a00097a10096000c0100000001000000000000002bd801026620a00097a000ab6100510084006b009effe8 00302200290091002fa000ada000ab610094004a00ae00640023003022006600b9a338a000ada000ab610097011b00b10135fffe00302200670140ea37a000ada10096000c01000000010000000000000004002800300002096e6976656175203120a00097a10096000c010000000100000000000000040129450453696e20 a00097ff}}\par \par Bien entendu le passage d'une forme liste \'88 la forme arbre (ou \'88 la forme interm\'8ediaire de maple) et inversement est un exercice de programmation \'88 peu pr\'8fs trivial. Par contre la passage de la forme parenth\'8es\'8ee \'88 l'une de ces trois formes est beaucoup plus d\'8elicat (surtout si l'expression n'est pas compl\'90tement parenth\'8es\'8ee et utilise des priorit\'8es entre les op\'8erateurs, comme l'on fait habituellement), mais est fait de fa\'8don transparente \'88 l'utilisateur par Maple.\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 2. Type et op\'8erandes d'une expression\par \pard\plain \qj \f20 Pour Maple, le type d'une expression alg\'8ebrique non atomique est son en-t\'90te (ou encore sa racine). C'est ainsi que\par \pard \qj\li560 - le type de sin(2x+y+f(z)) est sin\par - le type de 2x+y+f(z) est sum {\i (plus en anglais)}\par - le type de 2x est times {\i (multipli\'8e en anglais)}\par - le type de f(z) est f .\par \pard \qj Quand aux op\'8erandes ce sont les diverses sous expressions (\'8eventuellement atomiques) auxquelles s'appliquent l'op\'8erateur de l'en t\'90te.\par \pard \qj\li560 - l'expression sin(2*x+y+f(z)) a un seul op\'8erande 2*x+y+f(z)\par - l'expression 2*x+y+f(z) a trois op\'8erandes 2x,\tab y, \tab f(z)\par \pard \qj\li580 - l'expression 2*x a deux op\'8erandes 2 , \tab x\par - l'expression f(z) a un seul op\'8erande z.\par \pard \qj Dans la notation en arbre, le type correspond \'88 la racine de l'arbre et les op\'8erandes a chacun des sous arbres partant de la racine. La fonction {\b op} retourne les divers op\'8erandes d'une expression alg\'8ebrique. Quant \'88 la fonction {\b nops} elle renvoie le nombre d'op\'8erandes (c'est \'88 dire le nombre de fl\'8fches partant de la racine).\par \pard\plain \s2\sb120\keep\keepn \b\f22 ?op, nops\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: op - extract operands from an expression\par FUNCTION: nops - the number of operands of an expression\par CALLING SEQUENCE:\par op(i,e) op(i..j,var e); op(e); and nops(e);\par PARAMETERS:\par i,j - non-negative integers marking positions of operands\par e - any expression\par SYNOPSIS: \par - The op function extracts the components of an expression. The nops function returns the number of components of an expression.\par - If the first argument is a nonnegative integer i then the result is the i'th operand of e.\par - If the first argument is a range i..j then the result is an expression sequence of the i'th to j'th operands of e. If there is only one argument: op(e) = op(1..nops(e),e)\par - If e is an integer or a string, nops(e) yields 1 and op(1,e) yields e.\par - For some data structures, op 0 is defined as a special case. For subscripts and functions, op 0 is the name of the subscript or function and for series, op 0 is the expansion point of the series.\par \par \pard\plain \qj \f20 Retenez en particulier que op(i,exp) renvoie le i-i\'8fme op\'8erande de exp et que op(exp) renvoie la s\'8equence des op\'8erandes de f.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet expr:=sin(2*x+y+f(z)):\par \bullet expr2:=op(1,expr);\par \pard\plain \s3 \f22\fs20 expr2 := 2 x + y + f(z)\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet op(0,expr);\par \pard\plain \s3 \f22\fs20 sin\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet op(1,expr2);\par \pard\plain \s3 \f22\fs20 2 x\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet op(expr2);\par \pard\plain \s3 \f22\fs20 2 x, y, f(z)\par \pard\plain \s254\qj\sb200\sa140 \b\f20\fs36\ul IV. Typage\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 1. Les types pr\'8ed\'8efinis\par \pard\plain \qj \f20 Nous avons rencontr\'8e pr\'8ec\'8edemment la plupart des types usuels de Maple. \par * les types simples \par \tab - {\b boolean}\par \tab - {\b integer} (lui m\'90me subdivis\'8e en {\b odd} et {\b even} d'une part, en {\b posint }et {\b negint }d'autre part)\par \tab - {\b fraction}\par \tab - {\b rational } (qui englobe \'88 la fois integer et fraction)\par \tab - {\b float}\par \tab - {\b numeric} (qui englobe \'88 la fois integer, fraction et float)\par \tab - {\b string}\par * les types compos\'8es\par \tab - {\b sequence}\par \tab - {\b list}\par \tab - {\b set\par }\tab - {\b array} (qui englobe un type {\b matrix} pour les array dont les indices commencent \'88 1 et un type {\b vector} pour les matrices \'88 une dimension)\par \tab - {\b range} (pour les intevalles d'entiers, not\'8es a..b)\par * les types d'expressions alg\'8ebriques\par \tab - {\b polynom} (qui englobe un type {\b monomial} pour les mon\'99mes et un type {\b expanded} pour les polyn\'99mes d\'8evelopp\'8es)\par \tab - {\b ratpoly} pour une fraction rationnelle\par \tab - {\b series} pour des s\'8eries (en fait des d\'8eveloppements limit\'8es)\par En fait, la gamme des types connus est beaucoup plus riche. En voici la liste:\par \pard\plain \s4\qj\li1120 \f20\fs20 \par * ** + . .. <\par <= <> = RootOf ^ algebraic\par algext algfun algnum algnumext and anything\par array boolean constant cubic equation even\par expanded facint float fraction function indexed\par integer intersect laurent linear list listlist\par logical mathfunc matrix minus monomial name\par negative negint nonneg nonnegint not numeric\par odd operator or plot plot3d point\par polynom posint positive primeint procedure quadratic\par quartic radext radfun radfunext radical radnum\par radnumext range rational ratpoly realcons relation\par scalar series set sqrt square string\par taylor trig type uneval union vector\par \par \pard\plain \qj \f20 Les appellations sont la plupart du temps suffisamment parlantes. Vous pouvez demander des explications suppl\'8ementaires avec la fonction {\b help(type[}{\i nom_du_type }{\b ])}.\par Remarque: \'88 la lumi\'8fre des types ci dessus, on peut constater qu'il y d'une part une hi\'8erarchie de types de type h\'8eritage, que d'autre part le type ne d\'8ecrit pas seulement un pur stockage informatique de l'objet, mais \'8e galement un certain nombre de ses propri\'8et\'8es. On est l\'88 en plein dans les principaux concepts de la {\b programmation par objet} (en anglais Object Oriented Programming, ou OOP).\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 2. Le contr\'99le des types\par \pard\plain \qj \f20 Il se fait \'88 partir d'un petit nombre de fonctions. La fonction {\b type} permet de tester si une expression est bien d'un type donn\'8e. On en verra la principale utilit\'8e en programmation o\'9d presque toute fonction commencera par un {\b if type(....) then }.\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: type - type-checking function\par CALLING SEQUENCE:\par type(x, t)\par PARAMETERS:\par x - any expression\par t - type name or set of type names\par SYNOPSIS: \par - The type function is a boolean function which returns true if x is of type t;\par false otherwise.\par - In the case where t is specified as a set of type names, the value returned\par is true if x is any of the types in the set; false otherwise.\par - Note: If a type name is an operator, it must be back-quoted to prevent a syn-\par tax error. See the examples below.\par - For further information, see type[] where is one of the\par names in the above list.\par - A user can make a datatype known to the type function in the following way.\par If the user has defined the procedure `type/mytype` then a call to type of\par the form: type(a, mytype(b, c, ...)); will generate the function call\par `type/mytype`(a, b, c, ...).\par - See type[definition] and type[structured] for information on defining and\par using type expressions.\par - See type[surface] for information on the distinction between a ``surface\par type'' and a ``nested type''.\par \par \pard\plain \qj \f20 Le but de la fonction {\b whattype} permet au contraire de r\'8ecup\'8erer directement sous forme de symbole le type d'une expression.\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: whattype - query the basic data type of an expression\par CALLING SEQUENCE:\par whattype(expr)\par PARAMETERS:\par expr - any expression\par SYNOPSIS: \par - The function whattype returns the data type name of expr, which may be any of the following basic data types:\par \par `+` `*` `^` `=` `<>` `<`\par `<=` `.` `..` `and` `or` `not`\par exprseq float fraction function indexed integer\par list procedure series set string table\par uneval\par \par - For a general expression, whattype returns the ``top level'' data type as determined by the order of precedence of the operators.\par \par \pard\plain \qj \f20 Quant \'88 la fonction {\b hastype }elle permet de tester la pr\'8esence dans une expression de sous-expressions d'un type donn\'8e {\b \par }\pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: hastype - test for a specified type\par CALLING SEQUENCE:\par hastype( expr, t );\par PARAMETERS:\par expr - any expression\par t - name of a datatype\par SYNOPSIS: \par - The boolean function hastype returns true if and only if expr has any subexpressions of the type t.\par \par \pard\plain \qj \f20 Exemples:\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type( a + b, polynom );\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type( a + b, `+` );\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type( a * b, `+` );\par \pard\plain \s3 \f22\fs20 false\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type( a and b, `and` );\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type(1+2*sqrt(3),numeric);\par \pard\plain \s3 \f22\fs20 false\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type(1+2*sqrt(3),algebraic);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type(x,name);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet whattype(a+b);\par \pard\plain \s3 \f22\fs20 +\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet whattype(2*sqrt(3));\par \pard\plain \s3 \f22\fs20 *\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet whattype(f(x));\par \pard\plain \s3 \f22\fs20 function\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet hastype(3+sqrt(2*sin(x)),function);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet hastype(3+sqrt(2*sin(x)),`*`);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s253\qj\li354\sb120\sa80 \b\f20 3. Les types d\'8efinis par l'utilisateur\par \pard\plain \qj \f20 Maple permet comme beaucoup de langages de programmations de d\'8efinir ses propres types et de les nommer. Pour d\'8efinir son propre type (par exemple un type truc), il suffit d'assigner la valeur du type \'88 {\b `type/}truc{\b `} (attention aux accents graves).\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet `type/truc`:=integer:\line \bullet type(3,truc);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \qj \f20 Bien entendu cette possibilit\'8e trouve tout son int\'8er\'90t avec la possibilit\'8e de d\'8efinir des types structur\'8es. Un type structur\'8e est toute expression Maple autre qu'une cha\'94ne de caract\'8fre qui peut \'90 tre interpr\'8et\'8ee comme un type \'88 l'aide de la grammaire suivante les notation habituelles pour une grammaire sont\par \tab ::= signifie "est d\'8efini comme"\par \tab | signifie "ou"\par \tab *\tab signifie "zero, une ou plusieurs occurences de ..."\par \pard\plain \s4\qj\li1120 \f20\fs20 \par Syntaxe Correspond \'88\par \par type ::= \{ type* \} alternation; any of the types\par | [ type* ] concatenation; a list of the given types\par | numeric match a numerical constant exactly\par | string a system, procedural, or assigned type\par | type = type an equation of the corresponding types\par | type <> type an inequality of the corresponding types\par | type < type a relation of the corresponding types\par | type <= type a relation of the corresponding types\par | type > type a relation of the corresponding types\par | type >= type a relation of the corresponding types\par | type .. type a range of the corresponding types\par | type and type an and of the corresponding types\par | type or type an or of the corresponding types\par | not type a not of the corresponding type\par | type ^ type a power of the corresponding types\par | type.type a concatenation of the corresponding types\par | 'type' an unevaluated expression of the given type\par | fcntype a function or special type\par | name[type*] an indexed reference of the given types\par \par fcntype ::= set(type) a set of elements of the given type\par | list(type) a list of elements of the given type\par | `+`(type) a sum of terms of the given type\par | `*`(type) a product of factors of the given type\par | identical(expr) an expression identical to expr\par | specfunc(type,foo) the function foo with type arguments\par | anyfunc(type*) any function of the given types\par | foo(type*) type defined by a procedure `type/foo`\par | foo(type*) the function foo of the given types \par \pard\plain \qj \f20 \tab Les crochets sont utilis\'8es pour tester une suite fix\'8ee d'arguments. Le type {\b [name,set] }d\'8esigne une liste avec exactement deux arguments, un nom suivi d'un ensemble.\par \tab Par contre les accolades sont utilis\'8ees pour une alternative. Le type {\b \{set(name),list(integer)\}} correspond indiff\'8eremment \'88 un ensemble de symboles et \'88 une liste d'entiers.\par \tab Le type {\b anything} s'adapte \'88 n'importe quoi, sauf une s\'8equence. Le type {\b identical}(expr) ne s'adapte qu'\'88 une expression identique \'88 expr. Le type {\b anyfunc(t1,\'c9,tn)} s'adapte \'88 toute fonction avec n arguments de types t1, \'c9,tn. Le type {\b specfunc(f,t)} s'adapte uniquement \'88 la fonction f appel\'8ee avec des arguments de type t.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet `type/truc`:=\{list(name),set(numeric)\}:\par \bullet type(\{3,x\},truc);\par \pard\plain \s3 \f22\fs20 false\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type(\{x,y\},truc);\par \pard\plain \s3 \f22\fs20 false\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type([x,y],truc);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet type(\{3,5/3,1.2\},truc);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet `type/tsin`:=specfunc(anything,sin):\par \bullet hastype(3+sqrt(2*sin(x)),tsin);\par \pard\plain \s3 \f22\fs20 true\par \pard\plain \s254\qj\sb200\sa140 \b\f20\fs36\ul V. L'evaluation\par \pard\plain \qj \f20 \tab Nous avons d\'8ej\'88 vu que le mode normal de travail de Maple est celui de l'\'8evaluation au niveau le plus profond. Ceci signifie que l'expression est \'8evalu\'8ee jusqu'\'88 ce qu'une \'8evaluation suppl\'8e mentaire n'induise pas de changement dans l'expression. Bien entendu cette expression est en g\'8en\'8eral effectu\'8ee \'88 l'aide de l'arbre de l'expression, c'est \'88 dire qu'en premier lieu chacune des sous expressions est \'8evalu\'8ee (normalem ent de la gauche vers la droite) et qu'ensuite l'expression totale est \'8evalu\'8ee. Un certain nombre d'exceptions existent \'88 cette \'8evaluation au niveau le plus profond:\par - les termes de gauche des affectations ne sont pas \'8evalu\'8es (par contre les termes de droite le sont)\par - les expressions entre apostrophes ne sont pas \'8evalu\'8ees (ou plut\'99t l'\'8evaluation d'une telle expression consiste \'88 retirer un niveau d'apostrophes); on a vu comment cette possibilit\'8e permettait une affectation diff\'8er\'8e e au lieu d'une affectation imm\'8ediate (ou encore une affectation par r\'8ef\'8erence au lieu d'une affectation par valeur); elle \'8evite aussi des \'8evaluations intempestives de variables d'indice (emp\'90cher par exemple une \'8evaluation de {\b i} dans l'expression {\b seq(i*i,i=1..10)} dans le cas o\'9d la variable {\b i} aurait \'8et\'8e pr\'8ealablement affect\'8ee, on a plut\'99t int\'8er\'90t \'88 utiliser {\b seq(i*i,'i'=1..10)}); elle peut \'8egalement emp\'90cher des \'8e valuations intempestives dans la d\'8efinition de types structur\'8es (le type {\b diff(name,name)} \'8etant par exemple \'8evalu\'8e par Maple suivant les r\'8fgles habituelles de d\'8erivation pour donner 1, il faut pour d\'8e finir un tel type le mettre entre apostrophes pour emp\'90cher son \'8evaluation).\par - les tables et les proc\'8edures sont \'8evalu\'8ees non pas en leur valeur au niveau le plus profond, mais en le dernier nom rencontr\'8e dans la cha\'94ne d'\'8evaluation.\par \tab Cette derni\'8fre r\'8fgle a un certain nombre de cons\'8equences, dont la plus importante concerne les affectations. Si A est une table, une affectation du type B:=A n'affecte pas \'88 la variable B la valeur de A (c'est \'88 dire ne recopie pas dans B la table contenu de A), mais au contraire affecte \'88 B le nom A; ceci signifie qu'apr\'8fs l'affectation, les variables A et B d\'8esignent la m\'90me table (et non pas des tables \'8e gales). En particulier, toute modification de B se r\'8epercute automatiquement sur A et inversement. On peut comparer ce ph\'8enom\'8fne avec le syst\'8fme des tableaux en C o\'9d le nom du tableau d\'8esigne non pas le tableau lui m\'90 me, mais un pointeur sur ce tableau. Si l'on veut \'8echapper \'88 ce syt\'8fme, il faut affecter \'88 B une copie de A en \'8ecrivant B:=copy(A).\par \tab De m\'90me, si l'on veut afficher le contenu d'une table A, il ne suffit pas d'effectuer une \'8evaluation de A de la mani\'8fre habituelle car cette \'8evalaution donnera simplement le dernier nom recontr\'8e au cours de la cha\'94ne d'\'8e valuation (la plupart du temps A lui m\'90me, sauf si A provient d'une affectation). Il faut au contraire forcer une \'8evaluation compl\'90te \'88 l'aide de la fonction {\b eval}. Celle ci a d'autres utilisations (forcer un niveau donn\'8e d'\'8e valuation, forcer une \'8evaluation compl\'90te apr\'8fs une substitution, forcer une \'8evaluation compl\'90te des param\'8ftres ou des variables locales d'une proc\'8edure qui ne sont normalement \'8evalu\'8es qu'\'88 un seul niveau).\par \pard\plain \s4\qj\li1120 \f20\fs20 FUNCTION: eval - explicit evaluation\par CALLING SEQUENCE:\par eval(x) \par eval(x, n)\par PARAMETERS:\par x - an expression\par n - an integer\par SYNOPSIS: \par - The normal evaluation rules in Maple are full evaluation for global variables, and one-level evaluation for local variables and parameters. Sometimes the user requires full evaluation or one-level evaluation explicitly. The eval function is used for thi s purpose.\par - The call eval(x) means fully evaluate the expression x.\par - The call eval(x, 1) means evaluate the expression x one level. More generally, eval(x, n) yields n-level evaluation.\par - If x := y and y := 1 in a Maple session, what does the variable x evaluate to? In an interactive session where x and y are global variables, x would evaluate to 1. In this case, we say that x is ``fully evaluated''. For one-level evaluation, we would use the command eval(x, 1) which would in this case yield y. \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet a:=table([(x)=1,(1,2)=sin,(2,4)=Pi]):\par \bullet a;\par \pard\plain \s3 \f22\fs20 a\par \pard\plain \qj \f20 L'\'8evaluation a simplement renvoy\'8e le nom de a qui est le dernier recontr\'8e.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet eval(a);\par \pard\plain \s3 \f22\fs20 table([\par (1, 2) = sin\par (2, 4) = Pi\par x = 1\par ])\par \pard\plain \qj \f20 L'\'8evaluation compl\'90te a renvoy\'8e le contenu de la table.\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet b:=a;\par \pard\plain \s3 \f22\fs20 b := a\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet b;\par \pard\plain \s3 \f22\fs20 a\par \pard\plain \qj \f20 L'\'8evaluation a renvoy\'8e le dernier nom rencontr\'8e, c'est \'88 dire {\b a}. On va maintenant modifier b:\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet b[1,2]:=3:\line \bullet eval(a);\par \pard\plain \s3 \f22\fs20 table([\par (1, 2) = 3\par (2, 4) = Pi\par x = 1\par ])\par \pard\plain \qj \f20 La table point\'8ee par {\b a } a \'8et\'8e modifi\'8ee par la m\'90me occasion. Les noms {\b a} et {\b b} d\'8esignent bien la m\'90me table. Par contre, on va cr\'8eer une nouvelle table {\b c} dans laquelle on recopiera la valeur de la table {\b a}. Les noms {\b c} et {\b a} d\'8esigneront donc deux tables distinctes (bien qu'initialement \'8egales).\par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet c:=copy(a);\par \pard\plain \s3 \f22\fs20 c := table([\par (1, 2) = 3\par (2, 4) = Pi\par x = 1\par ])\par \pard\plain \qj \f20 \par \pard\plain \s2\sb120\keep\keepn \b\f22 \bullet c[y]:=E:\par \bullet eval(a);\par \pard\plain \s3 \f22\fs20 table([\-\par (1, 2) = 3\par (2, 4) = Pi\par x = 1\par ])\par \pard\plain \qj \f20 La table {\b a} n'a pas \'8et\'8e modifi\'8ee lors de la modification de {\b c}.\par }