This page contains the description of the following commands radexpand, rat_arith_mixed_flag, radexpand, random, random32, random33, rassoc, rassq, rationalp, ratsimpargs, read, read-from-string, read_data, read_fourier, realp, realpart, refcount, remainder, remfn, remob, remove, remprop, remq, renamefile, repeat, RETURN, return, return-from, return-from-llink, reverse, ring, ring_list, rmargin, round, rplaca, rplacd, runtime,
The radexpand variable can be false all or true (all other values are converted to true). If the variable is all, then (a^b)^c is transformed into a^(b*c), whatever the arguments. The rule is applied if c is an integer. If the variable true, the same rule is applied in case one of c is not a rational number. See documentation of the power function.
This function returns its argument if it is a rational number like 2 or 3/4, and false otherwise. For an example see numberp.
This variable is used by the simplifier. If set, some action is done for Rats inside general expressions. What happens exactly needs to be explained.
This variable is used when Rats and non-Rats are mixed. The value can be rat, mixed, general and default (everything else means `default'). If the variable is general then Rats are converted to general expressions. If it is rat, then general expressions are converted to Rats. If it is mixed, then Rats and general expressions can be mixed. See documentation on rats for details.
The three lisp functions random, random32 and random33 return a random number. For the first function, a number between x (included) and y (excluded) is returned. Otherwise x=0 and y = 2^31 (for random32) or y = 2^32 (for random33). Note: if you say (random 0 2), the internal random generator will be called until a number between 0 and 1 is found. This may take a long time. The random function can be defined as
(defun random (x y) (cond ((neq (type-of x) 'fix) x) ((neq (type-of y) 'fix) y) ((>= x y) 0) (true (let ((d (- y x)) c) (while (>= (setq c (random32)) d) ()) (+ x c)))))
Example
[Endymion] (random32) 0 [Endymion] (random32) 2116118 [Endymion] (random32) 89401895 [Endymion] (random32) 379337186 [Endymion] (random32) 782977366 [Endymion] (random32) 196130996 [Endymion] (random32) 198207689 [Endymion] (random 10 100) 30 [Endymion] (random 10 100) 36 [Endymion] (random 10 100) 56
The symbolic function random(a,b) returns a random generator, with values between a and b. The idea is the following. Let P and Q be two numbers. The generic random generator is s = s*Q mod P. The function returns a+ s + s*P +s*P2 +...+s*Pk mod b-a+1, where s is a random number as above, Pk is some power of P, large enough for the interval.
random(a,b):= let([L=b-a+1,i=0,x=1,P=184467440737095515579,Q=427419669081], while x<L do {i++,x:=P*x} if i=1 then lambda([], dynamic(_seed):=irem(Q*dynamic(_seed),P), a+irem(dynamic(_seed),L)) else lambda([],let(t=0, repeat(i+1,dynamic(_seed):=irem(Q*dynamic(_seed), P), t:=t*P+dynamic(_seed)), a+irem(t,L))));
(1) g:=random(1,1000000000000000000000000000000000000000000000); (1) <FUNCTION: u> (2) g(); (2) 616883120019133566604605954151685714323312529 (3) g(); (3) 71649796732388700521381297836946258283885345
Both functions rassq and rassoc search an item in an association list. The rassoc function uses equal, the rassq function uses eq as predicate. For an example see assq, which is a similar function. The functions could be defined as:
(defun rassq (x al) (cond ((atom al) ()) ((and (consp (car al)) (eq (cdar al) x)) (car al)) (true (assq x (cdr al))))) (defun rassoc (x al) (cond ((atom al) ()) ((and (consp (car al)) (equal (cdar al) x)) (car al)) (true (assq x (cdr al)))))
This function reads something.
The two functions (explode L) and (read-from-string S) put their input in a special buffer, and read an expression from it. See typecn for an example where reading the expression modifies the content of the buffer. An error is signaled if the reader attempts to access beyond the end of the buffer (case of missing closing bracket, parenthesis, quote, etc). The arguments should be a character string or a vector of character codes in the case of read-from-string, and a list of character codes in the case of implode.
[Endymion] (implode '(102 111 111)) foo [Endymion] (implode '(102 111 111 32 110)) foo [Endymion] (implode '(102 111 111 32 310)) implode : syntax error : bad list of ASCII codes [Endymion] (implode '( #/( )) read : syntax error : list or string too short [Endymion] (read-from-string "(1 2 3)") (1 2 3) [Endymion] (read-from-string "\"(1 2 3)\"") (1 2 3) [Endymion] (read-from-string #[102 111 111]) foo
This function reads a data file, formed of a header, an integer N, a sequence of 3N real numbers, and returns a pwfunction. Consider a file with the following content:
! comment # GHZ S RI R 50 5 11.1,2,3 11.2,4,5 11.3, -6, -0.7 11.4 xx 6e-1 xx -1.5e+01 11.5 10 11
The header is formed by lines that start with an exclamation point (ignored) and lines that start with with a sharp sign (containing keywords). The header is optionally followed by an unsigned integer (here 5), that must match the number of points that follows. Between the numbers, we can have spaces or commas (additional junk is silently removed). There are two keywords, the first can be HZ, GHZ or MHZ, indicating the frequency unit (output is MHZ, so that HZ says divide by 10e6 and GHZ multiply by 1000). Lower case letter Z is also allowed. The second keyword indicates that type of the data: if RI, then the file contain the real part and the imaginary part of the data; if MA the file contain the module r and angle theta (in degrees), and DB says that the file contains d and theta, where d=20*log10(r). We show here how Endymion scans the file, with RI, MA and DB. If the header is missing, MHz and RI are assumed.
(1) read_data(ex_data); (1) <pw function: 11100 = 2 + 3 %i, 11200 = 4 + 5 %i, 11300 = - 6 - 0.7 %i, 11400 = 0.6 - 15 %i, 11500 = 10 + 11 %i> (2) read_data(ex_data_ma); (2) <pw function: 11100 = 1.99725906950915 + 0.104671912485888 %i, 11200 = 3.98477879236698 + 0.348622970990633 %i, 11300 = - 5.99955221796271 + 0.073302005011483 %i, 11400 = 0.579555495773441 - 0.155291427061512 %i, 11500 = 9.81627183447664 + 1.90808995376545 %i> (3) read_data(ex_data_db); (3) <pw function: 11100 = 1.25720009827072 + 0.0658870652647896 %i, 11200 = 1.57886219537146 + 0.138132543364655 %i, 11300 = 0.501149829853849 - 0.0061230048518396 %i, 11400 = 1.03500817029632 - 0.277329603390514 %i, 11500 = 3.10417771283056 + 0.603391023438419 %i>
This function reads a file f containing Fourier coefficients. The file may contain an optional integer N followed by 2N real numbers, say ak, bk, for k between 0 and N-1. The result is the sum of the (ak+i*bk)*z^k. The second argument, when integer, is interpreted as follows. If s is odd, then the file contains N real numbers ak, the result is sum ak*z^k. If the number is 2 modulo 4, the file contains ak, bk, for k between 1 and N, the result is the sum of the (ak-i*bk)*z^k. Finally, if the number is 3 modulo 4, the file contains ak, for k between 1 and N, the result is the sum of the ak*z^k.
This function returns its argument if it is a real number (integer, rational, floating point, or BigFloat), and false otherwise. For an example see numberp.
In the case of a complex number realpart and imagpart return the real and the imaginary part of the number. Otherwise they return the number and zero.
[Endymion] (realpart 'x) x [Endymion] (imagpart 'x) 0 [Endymion] (imagpart 3/4) 0 [Endymion] (realpart 3/4) 3/4 [Endymion] (realpart #C(2 3/4)) 2 [Endymion] (imagpart #C(2 3/4)) 3/4 [Endymion] (conjugate 'x) x [Endymion] (conjugate 3/4) 3/4 [Endymion] (conjugate #C(2 3/4)) [-3/4i+2] [Endymion] (conjugate #PC_d 2 1 2 3 4 5 6) #PC_s (1-2*I) + (3-4*I)*z + (5-6*I)*z^2; [Endymion] (conjugate #PFC 0 2 1 2 3 4 5 6) #PFC_s (1-2*I) + (3-4*I)*z + (5-6*I)*z^2;
The refcount function takes one argument. It returns the reference count of the object. This can be minus one, or the number of references to the object.
[Endymion] (setq x '(1)) (1) [Endymion] (refcount x) 3 [Endymion] (let ((y x)) (refcount x)) 4 [Endymion] (refcount 'foo) -1
Return the remainder in the division of a by b. See quomod.
The remfn function takes one argument. If this is a symbol, it removes its functional value. The function returns (). You can remove system functions, if you feel that they are useless. However, there is no undo in Endymion! In some cases, there are alternate ways of defining a feature, see example.
[Endymion] (defun foo (x) (remfn x)) foo [Endymion] (foo 123) () [Endymion] (foo 'cons) () [Endymion] (foo 'foo) () [Endymion] (cons 1 2) eval : undefined function : cons [Endymion] (foo 'foo) eval : undefined function : foo [Endymion] (defun cons (a b) [Endymion] (let ((x (ncons a))) (rplacd x b) x)) cons [Endymion] (cons 1 2) (1 . 2)
The remob function takes one argument. If this is a symbol, it removes its property list and cell value. The function returns (). Some symbols are variable-functions. This means that a function is associated to the symbol, and the value is stored somewhere; in the case of ibase, a special stack is used, in some other cases, the cell value of the symbol is used. In such a case, using remob is not recommended.
[Endymion] (setq foo 'bar) bar [Endymion] (putprop 'foo 'bar 'gee) bar [Endymion] (plist 'foo) (gee bar) [Endymion] (remob 'foo) () [Endymion] (plist 'foo) () [Endymion] foo eval : undefined variable : foo [Endymion] (remob 'ibase) () [Endymion] ibase 10 [Endymion] (remob 123) ()
The remove function takes two argument, an item and a list. It removes the item from a copy of the list. For an example, see delete. See below under remq.
The remprop function takes two arguments, a symbol and a property name. Remember that the plist of a symbol is a list of pairs (prop, val). The function removes from the plist of the first argument the first pair (if any) that matches the second argument. It returns a copy of the new plist. For an example, see putprop.
The remq function takes two argument, an item and a list. It removes the item from a copy of the list. The remq uses eq for comparing, while remove uses equal, otherwise the functions are the same. For an example see delete. The function could be defined as
(defun remq (x l) (cond ((atom l) l) ((eq x (car l)) (remq x (cdr l))) (true (cons (car l) (remq x (cdr l)))))) (defun remove (x l) (cond ((atom l) l) ((equal x (car l)) (remove x (cdr l))) (true (cons (car l) (remove x (cdr l))))))
The renamefile function takes two arguments that can be converted to strings. It changes the name of the file x to be y. The function returns true if this is possible, false otherwise.
[Endymion] (renamefile #"foo" #"bar") () [Endymion] (renamefile 1/2 3/4) renamefile : non string argument : 1/2 [Endymion] (renamefile "1/2" "3/4") () [Endymion] (renamefile "1/2" #"Ϩ") renamefile : argument out of bounds : 1000
This repeats n times the code x1 ... xm. The lisp macro expands to (for (g 1 1 a) x1 ...xm), where g is a new symbol, see for. The symbolic macro has 4 variants. It is of the form: put n in a, while a positive, decrement and execute the body. In the case where a is not a real number, the test fails, and the body is not executed. In the case of the macro repeat_fix, the quantity a is repeat_counter, in all other cases, a is an internal counter. In the case of RepeatX(n,v,i,X,...) and Repeat(n,v,X,...) the variable v is incremented whenever a is decremented. Its initial value is i or zero. We show here the definition of one of these macros, and the common macro.
repeat(n,[c])::= buildq(a=gensym,repeat\-internal(a,a=n,a--,c)); repeat\-internal(a,i,n,c)::= buildq(let(i, tagbody( label(L_begin_repeat), If a>0 then n else goto(L_end_repeat), {splice(c)}, goto(L_begin_repeat), label(L_end_repeat)), done));
You cannot use break or continue, but you can goto() one of the two labels. Example.
(1) x:=0?; (9) repeat(10, (9) x++, (9) if(x==3) then goto(L_begin_repeat), (9) print (x), (9) if(x==7) then goto(L_end_repeat), (9) print(x)); 1 1 2 2 4 4 5 5 6 6 7 (9) done (10) RepeatX(3,i,1,print(i)); 1 2 3 (10) done
The Lisp code executed in the previous example is the following
(let ((#:gensym:g4 10)) (tagbody L_begin_repeat (if (> #:gensym:g4 0) (setq #:gensym:g4 (:- #:gensym:g4 1)) (go L_end_repeat) ) (#:ed:symbs:set 'x (:+ (#:ed:symbs:symeval 'x) 1)) (if (:equal (#:ed:symbs:symeval 'x) 3) (go L_begin_repeat) false) (:print (#:ed:symbs:symeval 'x)) (if (:equal (#:ed:symbs:symeval 'x) 7) (go L_end_repeat) false) (:print (#:ed:symbs:symeval 'x)) (go L_begin_repeat) L_end_repeat ) 'done )
The expansion of RETURN(x) is return(":=",x) As a result, this evaluates the argument, then jumps to a block named :=. Such a block is added by the compiler to the body of every fucntion, so that, by default, this returns from the current function. See description of return below.
This is the symbolic version of the Lisp special form return-from defined below. See the compiler for details.
The return-from special form form takes at least two arguments. If the first argument is not the name of an active block, an error is signaled. Otherwise, remaining arguments are evaluated, in order. The evaluation of the last argument will be the value of the block. We give here a simple example, others can be found under block.
[Endymion] (block a (return-from a (print 1) 2)) 1 2 [Endymion] (return-from) return-from : wrong number of arguments : 0 this should be at least 2 [Endymion] (return-from 1 2) return-from : not a symbol : 1 [Endymion] (return-from-llink a 'b 2) return-from-llink : no lexical scope : a [Endymion] (return-from-llink) return-from-llink : wrong number of arguments : 0 this should be at least 3 [Endymion] (block a (return-from-llink a 0 (print 1) 2)) 1 2 [Endymion] (block a (return-from-llink a 1 (print 1) 2)) return-from-llink : no lexical scope : a
The return-from-llink special form form takes at least three arguments. It behaves like return-from described above, but it has an additional argument, ll. This argument should be the identifier of a lexical link, obtained from block-with-llink (it can also be zero, case where it is ignored). In the current version, it is ignored if not an integer (in a future version, it could signal an error). Using this argument, you can chose one of the different blocks with the same tag name (otherwise, the first one is selected). See above for examples.
The reverse function takes one argument. It returns it in reverse order (provided that the argument is a list; nil is returned in the case of a non-list argument. The function can be defined as
(defun reverse (x) (let ((y ())) (while (consp x) (setq y (cons (car x) y) x (cdr x))) y))
Example
[Endymion] (setq l1 '(a b c d e) l2 (last l1)) (e) [Endymion] (reverse l1) (e d c b a) [Endymion] l1 (a b c d e) [Endymion] l2 (e) [Endymion] (reverse '(1 2 . 3)) (2 1) [Endymion] (reverse 4) ()
A ring is a data structure used to represent symbolic polynomials and rational functions. There are two bases rings, Z and Q, and you can construct Z/nZ for any integer n (a polynomial P on Z/-17Z[x] is a polynomial modulo 17, like polynomials Q on Z/17Z[x], but coefficients are printed in the range [-8,+8] for P, and [0,16] for Q; zero, one, minus one are forbidden). Given a ring K, you can construct K[x], K[x,y], K(x), K(x,y), etc. The list of all rings is kept in a global variables. As the example shows, the Lisp printer prints something complicated (in fact, the application of the format method), and it is perhaps easier to use the display function.
[Endymion] (setq a (#:feval:make_zp 17) b (#:feval:make_zp -17) c()) () [Endymion] (type-of a) ring [Endymion] (#:feval:ring_list) [(ring -17) (ring 17) (ring Q) (ring Z)] [Endymion] (display(#:feval:ring_list)) [%Z/-17Z, %Z/17Z, %Q, %Z] ()
This function returns the list of all rings maintained by Endymion.
This variable controls the rigght margin. You can say (setq rmargin (+ rmargin 1)) or (rmargin (+ (rmargin) 1)), these calls increment the right margin by one. See lmargin for further information.
This function takes one or two arguments. The second argument defaults to 1. It computes Q and R such that a=bQ+R, it returns Q and puts R in #:ex:mod. If a and b are integers, b positive, R is chosen so that -b<2R<b. If a/b is an integer plus one half, this equation cannot be satisfied, and R=b/2 or R=-b/2 is chosen, whithe the same sign as a. If b<0 the result is the same as (- (round a (- b))). Quantities a and b can be rational numbers. It is possible to call the function with one argument, a floating point number. In this case, #:ex:mod is not computed.
[Endymion] (list (round 100 4) (round 101 4) (round 102 4) (round 103 4)) (25 25 25 26) [Endymion] (list (round -100 4) (round -101 4) (round -102 4) (round -103 4)) (-25 -25 -25 -26) [Endymion] (list (round 100 -4) (round 101 -4) (round 102 -4) (round 103 -4)) (-25 -25 -25 -26) [Endymion] (list (round -100 -4) (round -101 -4) (round -102 -4) (round -103 -4)) (25 25 25 26) [Endymion] (round 4/3) 1 [Endymion] #:ex:mod 1/3 [Endymion] (list (quomod (+ 1/5 5/3) 2/5) #:ex:mod) (4 4/15) [Endymion] (list (round (+ 1/5 5/3) 2/5) #:ex:mod) (5 -2/15) [Endymion] (round 2.5) 3
The rplaca function takes two arguments. The first argument must be a list. The function replaces the CAR of the list by the second argument, then returns the list.
[Endymion] (rplaca #[1] 2) rplaca : not a list : #[1] [Endymion] (setq x '(1 . 2)) (1 . 2) [Endymion] (rplaca x 3) (3 . 2) [Endymion] x (3 . 2)
The rplacd function takes two arguments. The first argument must be a list. The function replaces the CDR of the list by the second argument, then returns the list.
[Endymion] (rplacd #[1] 2) rplacd : not a list : #[1] [Endymion] (setq x '(1 . 2)) (1 . 2) [Endymion] (rplacd x 3) (1 . 3) [Endymion] x (1 . 3)
The runtime function takes no argument; it returns the CPU time spent so far as a float. Example
[Endymion] (runtime) 0.02 [Endymion] (type-of (runtime)) float
back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $