All commands, alphabetic order; letter I

This page contains the description of the following commands ibase, if, ifactor, ifn, imagpart, implode, inbuf, in, incr, incr1, increment, index, indexed, infinite_single_seq, Infinity, inchan, inmax, inpos, in-read-flag, integerp, intern, inv, irem, iroot, isodate, isprime, isqrt, #:sys-package:itsoft, itsoft,


ibase (Lisp variable/function)

This is the current input base. It must be a number between 2 and 36. If the base is greater than ten, then A represents ten, B represents eleven, etc. When the base is greater than 28, ibase is considered as a number (13008573, in base 29), see example below. An expression like #10R11 is read as eleven, becase the sharp macro read a number in base ten and sharp-R uses this value as current input base.

[Endymion] (let ((ibase 35))(list (read) (read))) 10 abcdez
(35 abcdez)
[Endymion] (let ((ibase 36))(list (read) (read))) 10 abcdez
(36 623714795)
[Endymion] (let ((ibase 36))(read)) (ibase |ibase| ibas\e #10R10)
(30760286 ibase ibase 10)

(if test tv fv1 ... fvn) (Lisp special form)

if test then action else other-action (Symbolic special form)

See the compiler for how to use conditionals in symbolic macros.

The if special form takes at least two arguments. The first argument is evaluated. It it is true (i.e., anything but nil), the second argument is evaluated and this is the result of the call. Otherwise, argument starting with the third are evaluated, the result of if is the last evaluation (or nil, in case two arguments are given).

[Endymion] (if true 1 2)
1
[Endymion] (if false 1 2)
2
[Endymion] (if true 1)
1
[Endymion] (if false 1)
()
[Endymion] (if true 'ok (car 0))
ok
[Endymion] (if false 'ok (car 0))
car : not a list : 0
[Endymion] (if false 'ok 1 2 3)
3
[Endymion] (ifn true 1 2)
2
[Endymion] (ifn false 1 2)
1
[Endymion] (ifn true 1)
()
[Endymion] (ifn false 1)
1
[Endymion] (ifn false 'ok 1 2 (car 0))
ok
[Endymion] (ifn true 'ok 1 2 (car 0))
car : not a list : 0
[Endymion] (setq x '(ifn true 'ok 1 2 (car 0)))
(ifn true 'ok 1 2 (car 0))
[Endymion] (eval x)
car : not a list : 0
[Endymion] x
(if (not true) 'ok 1 2 (car 0))

In symbolic mode, you say if a then b else c, where the else part is optional. In the case where x and y are symbolic variables a test of the form x>y is undefined, and an error is signaled. If you use If instead of if, then the standard comparision function is called, and the result of the comparison is false if one of the arguments is not a real number.

(1) x<y;

(1)                                 x < y

(2) if x<y then ok;
if : Cannot compute : x < y
(3) If x<y then ok;

(3)                                 false

(ifn test tv fv1 ... fvn) (Lisp macro)

The ifn macro takes at leat two arguments. Its expansion is the form, where the first element is replaced by if, the second by (not tv). Said otherwise (ifn foo bar gee) is replaced by (if (not foo) bar gee). See if for examples.

(ifactor n) (Lisp function)

The ifactor function takes as argument an integer and returns the factorisation of it. The partial_ifactor function does the same, however, it does not try complicated algorithms; in case of failure, it stores in errexp the factorised part, in errexp1 the not-yet-factorised number, and returns nil. Otherwise, the result is a list of pairs, factor and exponent, in increasing order. The Nfactor function is used to debug the software; it prints the runtime on the screen, it tests that the factorisation is OK; it removes exponents in case they are one.

[Endymion] (partial_ifactor (fib 80))
()
[Endymion] errexp
((3 1) (5 1) (7 1) (11 1) (41 1) (47 1) (1601 1))
[Endymion] errexp1
6571601
[Endymion] (ifactor (fib 80))
((3 1) (5 1) (7 1) (11 1) (41 1) (47 1) (1601 1) (2161 1) (3041 1))
[Endymion] (partial_ifactor (fact 500))
((2 494) (3 247) (5 124) (7 82) (11 49) (13 40) (17 30) (19 27) (23 21) (29 
17) (31 16) (37 13) (41 12) (43 11) (47 10) (53 9) (59 8) (61 8) (67 7) (71 7
) (73 6) (79 6) (83 6) (89 5) (97 5) (101 4) (103 4) (107 4) (109 4) (113 4) 
(127 3) (131 3) (137 3) (139 3) (149 3) (151 3) (157 3) (163 3) (167 2) (173 
2) (179 2) (181 2) (191 2) (193 2) (197 2) (199 2) (211 2) (223 2) (227 2) (
229 2) (233 2) (239 2) (241 2) (251 1) (257 1) (263 1) (269 1) (271 1) (277 1
) (281 1) (283 1) (293 1) (307 1) (311 1) (313 1) (317 1) (331 1) (337 1) (
347 1) (349 1) (353 1) (359 1) (367 1) (373 1) (379 1) (383 1) (389 1) (397 1
) (401 1) (409 1) (419 1) (421 1) (431 1) (433 1) (439 1) (443 1) (449 1) (
457 1) (461 1) (463 1) (467 1) (479 1) (487 1) (491 1) (499 1))
[Endymion] (ifactor -10)
((2 1) (5 1) (-1 1))
[Endymion] (Nfactor (fact 300))
runtime :0.01
((2 296) (3 148) (5 74) (7 48) (11 29) (13 24) (17 18) (19 15) (23 13) (29 10
) (31 9) (37 8) (41 7) (43 6) (47 6) (53 5) (59 5) (61 4) (67 4) (71 4) (73 4
) (79 3) (83 3) (89 3) (97 3) (101 2) (103 2) (107 2) (109 2) (113 2) (127 2)
(131 2) (137 2) (139 2) (149 2) 151 157 163 167 173 179 181 191 193 197 199 
211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293)

(imagpart n) (Lisp function)

This function returns zero if its argument is not a complex number, and the imaginary part otherwise. See realpart for an exemple.

(implode L) (Lisp function)

This function takes a list of characters, and reads an expression out of it. In the case of (implode (explode "foo")), there are three characters, and F and two Os, so that the result is the symbol foo. See also read-from-string.

(inbuf p c) (Lisp function)

The (inbuf) function acts on the current input buffer (there is one buffer per input channel, and the current channel is selected). The function takes 0, 1 or 2 arguments. The call (inbuf) returns a copy of the output buffer. This is a string of size 4K (since there is a final null character, its effective size is 4095. The command (inbuf 10) returns the character at position 10 in the buffer. The command (inbuf 10 48) puts a zero (ASCII code 48) in the buffer at position 10 (the return value is 48; any integer between 1 and 255 is valid). The reader reads only characters between 0 and (inmax). In the example that follows, the function we read from a string. This contains an opening parenthesis, followed by #.(f) and other characters. Reading #.(f) has as side effect to evaluate (f) (evaluation is 41, the ASCII code of the parenthesis). But evaluating the function modifies the buffer: it is now (#.(f)1224). It modifies the size of the buffer, but not the current position.

[Endymion] (defun f ()(inmax 11) (inbuf 6 #/1)(inbuf 7 #/2)(inbuf 8 (inbuf 6))
[Endymion] (inbuf 9 #/4) (inpos 7) (inbuf 10 #/)))
f
[Endymion] (read-from-string "(#.(f)") 
(41 214)

inchan (Lisp variable/function)

This variable holds the current input channel, either nil for the terminal, or an integer corresponding to a channel opened by openi or similar functions. The implode (and friends) function uses a special channel that prints as nil, it is unwise to change the value in this case. The example that follows shows some error messages in case of bad argument. We print ok on the file foo, and read it; after that there will be one unread character (new line character). End of file will be signaled if we try to read again from the file. This means that the channel will be closed and (eof 19) will be called. This function throws (and signals an error because there is no catch).

[Endymion] (inchan)
()
[Endymion]  (inchan "foo")
inchan : not a fixnum : foo
[Endymion] (inchan 10)
inchan : stream not open for reading : 10
[Endymion] (setq inchan 10)
inchan : stream not open for reading : 10
[Endymion] (let ((outchan (openo "foo")))
[Endymion] (print "ok")(close (outchan)))
()
[Endymion] (openi "foo")
19
[Endymion] (let((inchan 19))(read))
ok
[Endymion] (let((inchan 19))(read))
eof : undefined escape : eof

a in b (Symbolic macro)

In a case like if a in b then c else d, the in operator is expanded, and this is the same as if member(a,b) then c else d. You can say case a in b then c else d, see case. You can say for a in b do c , see do. In other contexts, an error is signaled.

(incr var val) (Lisp macro)

The incr macro takes at least one argument. In the case of one argument, the expansion is (setq var (+ var 1)). In the case of two arguments, it is (setq var (+ var val)). Note that both incr and + accept more than two arguments.

[Endymion] (setq a '(incr z) b '(incr z 2) c '(incr z 3 4 5))
(incr z 3 4 5)
[Endymion] (eval a)
eval : undefined variable : z
[Endymion] (eval b)
eval : undefined variable : z
[Endymion] (eval c)
eval : undefined variable : z
[Endymion] a
(setq z (+ z 1))
[Endymion] b
(setq z (+ z 2))
[Endymion] c
(setq z (+ z 3 4 5))
[Endymion] (setq x 10)
10
[Endymion] (incr x) (incr x 3)
11
14
[Endymion] x
14

incr1(var) (Symbolic macro)

The macro can be defined as incr1(x)::=buildq(x:=x+1);. Since x++ is read as incr1(x), it is the same as x:=x+1. Never say f(x)++: this constructs a function that calls itself, without end.

increment(var, val) (Symbolic macro)

The macro is defined as increment(x,y)::=buildq(x:=x+y);.

(index str1 str2 n) (Lisp function)

a index b (symbolic function)

The symbolic function is described below, under indexed.

The index function takes two or three arguments; the default value of the third argument is zero. The function returns the smallest integer i, at least n, such that the substring of str2 starting at i coincides with str1. If such a string does not exist, the return value is nil. The function could be defined as follows

(defun index (a b . c)
  (if c (setq c (car c)) (setq c 0))
  (tag found  
    (let (a1 a2 n1 n2 ok)
       (setq s1 (string-to-list a))
       (setq s2 (string-to-list b))
       (setq s2 (nthcdr c s2))
       (setq n1 (length s1))
       (setq n2 (length s2))
       (for (i 0 1 (- n2 n1))
            (when (every 'equal s1 s2) (exit found (+ c i)))
            (setq s2 (cdr s2)))
       ())))

Example

[Endymion] (index #"bar" "foobar")
3
[Endymion] (index #"foo" "foobar")
0
[Endymion] (index #"foo" "xfoobar")
1
[Endymion] (index #"foo" "xfoobar" 2)
()
[Endymion] (index #"foo" "xfoobar" 1)
1
[Endymion] (index #"foo" "" 0)
()
[Endymion] (index #"" "foo" 1)
1
[Endymion] (index 'foo 'foobar)
0
[Endymion] (index 1.2 "01.234")
1
[Endymion] (index 1.2 11/22)
index : non string argument : 1/2
[Endymion] (index 1.2 1.3 1.4)
index : not a fixnum : 1.4

indexed(x, i1, ..., in) (Symbolic function)

This function does nothing; however the result is nicely printed. With two arguments you can say a index b, using the prefix operator index.

(2) a index b;

(2)                                   a
                                       b

(3) indexed(a,b,c);

(3)                                 a
                                     b, c

infinite_single_seq(v) (Symbolic function)

The effect of this command is an infinite sequence, the value of any term being always v

(1) a:=infinite_single_seq(x);

(1)                 <UninitializedSequence: infinite, x>

(2) b:=makeseq(a);

(2)                   <InitializedSequence: infinite, x>

(3) popseq(b);

(3)                                   x

Infinity (Symblic constant)

A construction like 1...Infinity step 2 returns the sequence of all odd integers.

(inmax p) (Lisp function)

The function call (inmax) returns the current size of the input buffer. The function call (inmax 20) sets the size to 20, and returns 20. See inbuf for an example, and inpos for futher comments.

(inpos p) (Lisp function)

The function call (inpos) returns the current position in the input buffer. The function call (inpos 20) sets the position to 20, and returns 20. See inbuf for a non-trivial example. The reader reads character (inbuf(inpos)) and increments the current position unless the position is greater or equal than (inmax), case where the bol itsoft is called. The effect of the itsoft is normally to read N characters, and put them in the input buffer (normally is full line is read, but if the line is too long, more than one call to the itsoft is needed). End-of-line markers are replaced by carriage return plus new line. After that (inpos) is 0 and (inmax) is N. You can set (inpos) and (inmax) to any value between 0 and M (the actual size of the buffer, 4095).

(in-read-flag) (Lisp function)

This function return true while reading and false otherwise. In fact, the reader sets the variable after having read the first non-white space character. This means that an end-of-file is an error if the variable is true, not an error otherwise.

[Endymion] (in-read-flag)
()
[Endymion] #.(in-read-flag)
true

(integerp n) (Lisp function)

This function returns its argument if it is an integer, and false otherwise. For an example see numberp.

(intern s) (Lisp function)

Some commands like gensym produce symbols that are not in the hash table. The intern command takes as argument such a symbol, and puts it in the hash table. It returns the symbol. It is an error if the symbol already exists (the reader produces only interned symbols). Example.

[Endymion] (setq x (gensym))
g1
[Endymion] (setq y (gensym))
g2
[Endymion] (intern y)
g2
[Endymion] (eq y 'g2)
true
[Endymion] (eq x 'g1)
()
[Endymion] (intern x)
intern : Symbol exists already : g1
[Endymion] (intern "foo")
intern : not a symbol : foo

inv(x) (Symbolic function)

This returns the inverse of the argument. inv(x) is the same as 1/x, evaluates as x**(-1). Note that inv(x*y) reduces to inv(x)*inv(y) only if expon is positive;

(1) [u+inv(2/3), u+inv(a/b), u+let(expon=1,inv(a/b)) ];

                            [3          1      b]
(1)                         [- + u, u + -, u + -]
                            [2          a      a]
                            [           -       ]
                            [           b       ]

(2) inv("foo");
inv : Cannot compute : **(foo, - 1)

irem(x n) (Symbolic function)

This is the symbolic version of the Lisp function remainder.

(iroot x n) (Lisp function)

Both iroot and jroot functions take two arguments x and n and compute the integer part of the n-th root of x. The code that follows does no check. For details about the algorithm see this pdf file.

(defun iroot (x n)
  (let (n1 l a f s a0 y cp OK)
    (setq n1 (- n 1))
    (setq l (haulong x))
    (setq s (quomod l n))
    (setq f (+ n 1 (remainder l n)))
    (setq a (quomod (* f (** 2 s)) n))
    (setq a0 x)
    (setq a (- a (quomod (- a (quomod x (** a n1))) n)))
    (while (< a a0)
      (setq a0 a)
      (setq a (- a (quomod (- a (quomod x (** a n1))) n))))
    (setq y a)
    (setq cp (<?> (** y n) x))
    (if (= cp 1)
	(until OK
	       (if (<= cp 0) (setq OK true)
		 (setq y (- y 1) cp (<?> (** y n) x))))
      (if (= cp -1)
	  (until OK
		 (setq cp (<?> (** (+ y 1) n) x))
		 (if (= cp 1)
		     (setq OK true)
		   (setq y (+ y 1))
		   (if (= cp 0)
		       (setq OK true))))))
    y))

(defun jroot(x n)
  (let (l eps (d 0)) 
    (setq l (- (haulong x) 1)
	  eps (quomod (- (haulong n) 1) 2)
	  res (jroot1 x n l eps (- n 1)))
    (while (> (** res n) x) (setq res (- res 1) d (+ d 1)))
    res))


(defun jroot1(x n l xs n1)
  (let (s y f u ok l1 T)
    (setq s (quomod l n)
	  y (- (quomod s 2) eps))
    (if (<= y 16)
	(progn
	  (setq f (+ n 1 (remainder l n)))
	  (setq u (quomod (* f (** 2 s)) n))
	  (until ok
		 (setq y u)
		 (setq f (quomod x (** u n1)))
		 (setq u (+ u (quomod (- f u) n)))
		 (if (>= u y) (setq ok true)))
	  y)
      (setq l1 (- l (* n y)))
      (setq T (quomod x (** 2 (* n y))))
      (setq u (jroot1 T n l1 xs n1))
      (setq u (* u (** 2 y)))
      (setq T (** u n1))
      (quomod (+ x (* u T n1)) (* n T)))))

Example

[Endymion] (iroot -2 2)
iroot : argument out of bounds : -2
[Endymion] (iroot 2 -2)
iroot : argument out of bounds : -2
[Endymion] (** 100000 1/4)
17.7827941003892
[Endymion] (iroot 100000 4)
17
[Endymion] (iroot 1/100000 4)
iroot : not a fixnum : 1/100000
[Endymion] (iroot 100000 1/4)
iroot : not a fixnum : 1/4
[Endymion] (defun f (x n)
[Endymion]   (let (y1 y2 t1 t2)
[Endymion]        (setq t1 (time (setq y1 (iroot x n))))
[Endymion]        (setq t2 (time (setq y2 (jroot x n))))
[Endymion]        (when (and (= y1 y2) (<= (** y1 n) x) (< x (** (+ y1 1) n)))
[Endymion]              (list t1 t2))))
f
[Endymion] (f (** 10 2000) 3)
(0.00999999999999801 0)
[Endymion] (f (** 10 2000) 3)
(0.0100000000000016 0)
[Endymion] (f (** 10 3000) 3)
(0.0199999999999996 0)
[Endymion] (f (** 10 10000) 3)
(0.32 0.0300000000000011)
[Endymion] (f (** 10 20000) 3)
(1.26 0.210000000000001)
[Endymion] (f (** 10 30000) 3)
(2.62 0.199999999999999)
[Endymion] (f (** 10 30000) 4)
(2.63 0.189999999999998)
[Endymion] (f (** 10 30000) 5)
(2.69 0.189999999999998)
[Endymion] (f (** 10 30000) 6)
(2.89 0.190000000000005)
[Endymion] (f (** 10 30000) 7)
(3.12 0.309999999999995)
[Endymion] (f (** 10 30000) 8)
(2.84999999999999 0.18)
[Endymion] (f (** 10 30000) 9)
(3.08 0.280000000000001)

(isodate date) (Lisp function)

The isodate function converts a date into a string using another format that the default.

[Endymion] (setq x #:date:#[2005 01 02 03 04 05])
Sun Jan 02 2005 03:04:05
[Endymion] (isodate x)
Sun 2005/01/02 03:04:05

(isprime x) (Lisp function)

The isprime function returns true if its argument is prime. The function uses essentially the Fermat criterion, that can defined as follows. Here we have a test: is p greater than 10000; in Endymion, the number of times the inner function is called can be changed to 17 via(set_max_iter_in_is_prime 17), the default value being 5. This fails to test that 21569059132741 is composite. Details about the algorithm can be found in here.

(defun Fermat(n)
  (let ((k 0) (x (- n 1)) (p 1))
    (while (even? x) (setq x (/ x 2) k (+ k 1)))
    (tag ok
       (while true
	 (setq p (nextprime p))
         (unless (Fermat1 x n k p) 
                 (print "Not prime via " p)
		 (exit ok ()))
         (when (> p 10000) (exit ok true))))))

(defun Fermat1 (x n k p)
  (let ((a (powermod p x n)))
    (tag ok
	 (if (eq a 1) (exit ok true))
         (while true
	   (when (= a (- n 1)) (exit ok true))
	   (when (<= k 1) (exit ok ()))
           (setq a (powermod a 2 n))
	   (when (= a 1) (exit ok ()))))))

Example

[Endymion] (nextprime 1000000000)
1000000007
[Endymion] (isprime 1000000007)
true

(isqrt x) (Lisp function)

The isqrt function returns the integer part of the square root of its argument, which must be an integer. For details about the algorithm see this pdf file.

[Endymion] (let ((x (** 123 3))) (list (sqrt x) (isqrt x)))
(1364.13599028836 1364)
[Endymion] (let ((x (** 1234567 3))) (list (sqrt x) (isqrt x)))
(1371740610.42551 1371740610)
[Endymion] (let ((x (** 1234567 17))) (list (sqrt x) (isqrt x)))
(5.99617976841362e+51 5996179768413624004571225816726884536461150352649926)
[Endymion] (let ((x (** 1234567 19))) (list (sqrt x) (isqrt x)))
(7.40268566815112e+57 7402685668151102546451484542879059661525233007419962120
066)
[Endymion] (let ((x (** 1234567 21))) (list (sqrt x) (isqrt x)))
(9.13911143727223e+63 9139111437272302217464969917648572049150222338271440374
684653713)
[Endymion] (let ((x (** 1234567 25))) (list (sqrt x) (isqrt x)))
(1.39294285843232e+76 1392942858432323431243507823295866386938598613472308893
7457356384855905999639)
[Endymion] (let ((x (** 1234567 33))) (list (sqrt x) (isqrt x)))
(3.23587664445711e+100 323587664445714832074463160835939542947943033424137305
65772723895544015025476822955482484517077299510)
[Endymion] (let ((x (** 1234567 45))) (list (sqrt x) (isqrt x)))
(1.14572381899616e+137 114572381899617608827025841569057603653974530807109847
45517026944485882366242118466194255129796993636273103590386861508133927300373
6909382)
[Endymion] (let ((x (** 1234567 61))) (list (sqrt x) (isqrt x)))
(inf 618297164207407882398521659040119535311381463803182150674056260749321534
47100177186507598158478236226241852243930998338692363525343521560434396060618
1405445172063630894835188534223561402)

(itsoft f a) (Lisp function)

The itsoft function takes two arguments, f and a. Its effect is to apply a function to a. This function is computed by considering the list #:sys-package:itsoft (see also the add-to-it-list function), in a manner similar to send. For each element x in this list, the symbol with name f in the package x is considered. The first such symbol that is a function is applied. If nothing is found, the cdr of the tail of the list is also considered; said otherwise if the list is (a b . c), then packages a, b and c are considered; if the list is (a b), then packages a, b and nil are considered. Thus, generally, the function f in the empty package is considered last.

The itsoft function is used internally by functions like eol, flush, bol, syserror. In the case where the itsoft list is (a b . c), then the default error handler cannot be used; if itsoft does not find a function or finds a function of the wrong type, it is unable to signal an error! For this reason, the error handling mechanism will reset the list to nil.

In the case where itsoft found a function, say F, it calls apply to apply it to a, so that, if F expects three arguments, then a should be a list of length three. The super-itsoft function behaves exactly like itsoft, but some initial elements of the itsoft list are discaded.

[Endymion] (defun #:a:foo (x) (cons 'a x))
#:a:foo
[Endymion] (defun #:b:foo (x) (cons 'b x))
#:b:foo
[Endymion] (defun #:c:foo (x) (cons 'c x))
#:c:foo
[Endymion] (setq #:sys-package:itsoft '(a A b B c C))
(a A b B c C)
[Endymion] (itsoft 'foo '(12))
(a . 12)
[Endymion] (itsoft 'ncons '(12))
(12)
[Endymion] (itsoft 'foo '(1 2))
#:a:foo : wrong number of arguments : 2 this should be 1
[Endymion] (super-itsoft 'a 'foo  '(12))
(b . 12)
[Endymion] (super-itsoft 'A 'foo  '(12))
(b . 12)
[Endymion] (super-itsoft 'b 'foo  '(12))
(c . 12)

#:sys-package:itsoft (Lisp special variable)

The itsoft mechanism works by using a variable #:sys-package:itsoft which is either a symbol, or a list of symbols (the tail of the list can be a symbol). In order to check the validity, a function is associated to the variable. Example

[Endymion] (setq #:sys-package:itsoft '(foo bar))
(foo bar)
[Endymion] (setq #:sys-package:itsoft '(foo bar . gee))
(foo bar . gee)
[Endymion] (#:sys-package:itsoft '(foo bar))
(foo bar)
[Endymion] #:sys-package:itsoft
(foo bar)
[Endymion] (#:sys-package:itsoft)
(foo bar)
[Endymion] (setq #:sys-package:itsoft 1)
#:sys-package:itsoft : not a variable : 1
[Endymion] (setq #:sys-package:itsoft '(foo 2))
#:sys-package:itsoft : not a variable : 2
[Endymion] (#:sys-package:itsoft)
(foo bar)

Valid XHTML 1.0 Strict back to home page © INRIA 2005, 2006 Last modified $Date: 2009/01/08 17:43:30 $