## [Maxima-commits] CVS: maxima/share/contrib integer_sequence.lisp, 1.1, 1.2

 [Maxima-commits] CVS: maxima/share/contrib integer_sequence.lisp, 1.1, 1.2 From: Barton Willis - 2008-06-23 01:37:48 ```Update of /cvsroot/maxima/maxima/share/contrib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9493/share/contrib Modified Files: integer_sequence.lisp Log Message: o new specification Index: integer_sequence.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/integer_sequence.lisp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- integer_sequence.lisp 18 Jun 2008 11:24:40 -0000 1.1 +++ integer_sequence.lisp 23 Jun 2008 01:37:44 -0000 1.2 @@ -1,43 +1,56 @@ -;; These binding powers make a .. b + 1 == a .. (b+1). +#| -(\$infix ".." 80 80) +The dot-dot operator generates terms of an arithmetic sequence. The +two argument dot-dot operator is defined by (Z is the set of integers). -(setf (get '\$.. 'operators) 'simp-integer-sequence) + a .. b = [a + k | k in Z, 0 <= k <= (b - a)]. -#| +Thus a .. b = [a, a + 1, a + 2, ..., a + n], where n = floor(b - a). The three +argument dot-dot operator is defined by -For integers a,b, and n define a .. b = [a,a+1, ..., a+n]. + a .. h .. b = [a + h * k | k in 0 .. (b - a) / h]. + +a .. b expands to a list when either floor(b - a) is an integer (not a +declared integer) or sign(b - a) is negative or zero; otherwise, the dot-dot +operator returns a noun form. + +a .. h .. b expands to a list when floor((b-a) / h) is an integer (not a +declared integer) or sign(b - a) is negative or zero and h is nonzero. -a .. b expands to a list of integers when either (1) ceiling(a) and -floor(b) are integers or (2) both a and b are declared integers and -b - a is an integer. Also a .. b expands to the empty list when csign -determines that a > b and that a and b are real-valued. Thus a + 1 -.. a --> [], but %i + 1 .. %i --> noun form. |# +;; These binding powers make a .. b op c == a .. (b op c), where op = +, -, *, /, or ^. + +(\$nary ".." 80) +(setf (get '\$.. 'operators) 'simp-integer-sequence) + (defun simp-integer-sequence (e yy z) (declare (ignore yy)) - (twoargcheck e) - (let ((i) (ii) (j) (jj) (acc nil)) - (setq i (simplifya (second e) z)) - (setq j (simplifya (third e) z)) - (cond ((and (integerp i) (integerp j)) - (while (>= j i) - (push j acc) - (decf j)) + + (let ((i) (j) (k) (lo) (hi) (h) (n) (sgn) (sgn-h) (acc nil)) + (pop e) + (setq i (if e (simpcheck (pop e) z) (merror "The '..' operator needs 2 or 3 arguments, not 0"))) + (setq j (if e (simpcheck (pop e) z) (merror "The '..' operator needs 2 or 3 arguments, not 1"))) + (setq k (if e (simpcheck (pop e) z) nil)) + (if e (merror "The '..' operator needs 3 or fewer arguments")) + (if k (setq lo i hi k h j) (setq lo i h 1 hi j)) + (if (zerop1 h) (merror "The step argument to '..' must be nonzero")) + + (setq sgn (csign (sub hi lo))) + (setq sgn-h (csign h)) + (setq n (if (eq sgn '\$zero) 0 (take '(\$floor) (div (sub hi lo) h)))) + (cond ((and (integerp n) (memq sgn-h '(\$neg \$pos \$pn))) + (while (>= n 0) + (push (add lo (mul n h)) acc) + (decf n)) (simplify (cons '(mlist) acc))) - ((and (\$featurep i '\$integer) (\$featurep j '\$integer) (integerp (sub j i))) - (simplify (cons '(mlist) (mapcar #'(lambda (s) (add i s)) (margs (take '(\$..) 0 (sub j i))))))) - - ((and (eq '\$neg (csign (sub j i))) (not (eq t (csign i))) (not (eq t (csign j)))) + ((or (and (eq '\$neg sgn) (eq '\$pos sgn-h)) + (and (eq '\$pos sgn) (eq '\$neg sgn-h))) (simplify `((mlist)))) - - (t - (setq ii (take '(\$ceiling) i)) - (setq jj (take '(\$floor) j)) - (if (and (integerp ii) (integerp jj)) (take '(\$..) ii jj) `((\$.. simp) ,i ,j)))))) - - - \ No newline at end of file + ((not k) `((\$.. simp) ,i ,j)) + ((eq 1 j) `((\$.. simp) ,i ,k)) ; a .. 1 .. b == a .. b + (t `((\$.. simp) ,i ,j ,k))))) + + \ No newline at end of file ```

 [Maxima-commits] CVS: maxima/share/contrib integer_sequence.lisp, 1.1, 1.2 From: Barton Willis - 2008-06-23 01:37:48 ```Update of /cvsroot/maxima/maxima/share/contrib In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9493/share/contrib Modified Files: integer_sequence.lisp Log Message: o new specification Index: integer_sequence.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/integer_sequence.lisp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- integer_sequence.lisp 18 Jun 2008 11:24:40 -0000 1.1 +++ integer_sequence.lisp 23 Jun 2008 01:37:44 -0000 1.2 @@ -1,43 +1,56 @@ -;; These binding powers make a .. b + 1 == a .. (b+1). +#| -(\$infix ".." 80 80) +The dot-dot operator generates terms of an arithmetic sequence. The +two argument dot-dot operator is defined by (Z is the set of integers). -(setf (get '\$.. 'operators) 'simp-integer-sequence) + a .. b = [a + k | k in Z, 0 <= k <= (b - a)]. -#| +Thus a .. b = [a, a + 1, a + 2, ..., a + n], where n = floor(b - a). The three +argument dot-dot operator is defined by -For integers a,b, and n define a .. b = [a,a+1, ..., a+n]. + a .. h .. b = [a + h * k | k in 0 .. (b - a) / h]. + +a .. b expands to a list when either floor(b - a) is an integer (not a +declared integer) or sign(b - a) is negative or zero; otherwise, the dot-dot +operator returns a noun form. + +a .. h .. b expands to a list when floor((b-a) / h) is an integer (not a +declared integer) or sign(b - a) is negative or zero and h is nonzero. -a .. b expands to a list of integers when either (1) ceiling(a) and -floor(b) are integers or (2) both a and b are declared integers and -b - a is an integer. Also a .. b expands to the empty list when csign -determines that a > b and that a and b are real-valued. Thus a + 1 -.. a --> [], but %i + 1 .. %i --> noun form. |# +;; These binding powers make a .. b op c == a .. (b op c), where op = +, -, *, /, or ^. + +(\$nary ".." 80) +(setf (get '\$.. 'operators) 'simp-integer-sequence) + (defun simp-integer-sequence (e yy z) (declare (ignore yy)) - (twoargcheck e) - (let ((i) (ii) (j) (jj) (acc nil)) - (setq i (simplifya (second e) z)) - (setq j (simplifya (third e) z)) - (cond ((and (integerp i) (integerp j)) - (while (>= j i) - (push j acc) - (decf j)) + + (let ((i) (j) (k) (lo) (hi) (h) (n) (sgn) (sgn-h) (acc nil)) + (pop e) + (setq i (if e (simpcheck (pop e) z) (merror "The '..' operator needs 2 or 3 arguments, not 0"))) + (setq j (if e (simpcheck (pop e) z) (merror "The '..' operator needs 2 or 3 arguments, not 1"))) + (setq k (if e (simpcheck (pop e) z) nil)) + (if e (merror "The '..' operator needs 3 or fewer arguments")) + (if k (setq lo i hi k h j) (setq lo i h 1 hi j)) + (if (zerop1 h) (merror "The step argument to '..' must be nonzero")) + + (setq sgn (csign (sub hi lo))) + (setq sgn-h (csign h)) + (setq n (if (eq sgn '\$zero) 0 (take '(\$floor) (div (sub hi lo) h)))) + (cond ((and (integerp n) (memq sgn-h '(\$neg \$pos \$pn))) + (while (>= n 0) + (push (add lo (mul n h)) acc) + (decf n)) (simplify (cons '(mlist) acc))) - ((and (\$featurep i '\$integer) (\$featurep j '\$integer) (integerp (sub j i))) - (simplify (cons '(mlist) (mapcar #'(lambda (s) (add i s)) (margs (take '(\$..) 0 (sub j i))))))) - - ((and (eq '\$neg (csign (sub j i))) (not (eq t (csign i))) (not (eq t (csign j)))) + ((or (and (eq '\$neg sgn) (eq '\$pos sgn-h)) + (and (eq '\$pos sgn) (eq '\$neg sgn-h))) (simplify `((mlist)))) - - (t - (setq ii (take '(\$ceiling) i)) - (setq jj (take '(\$floor) j)) - (if (and (integerp ii) (integerp jj)) (take '(\$..) ii jj) `((\$.. simp) ,i ,j)))))) - - - \ No newline at end of file + ((not k) `((\$.. simp) ,i ,j)) + ((eq 1 j) `((\$.. simp) ,i ,k)) ; a .. 1 .. b == a .. b + (t `((\$.. simp) ,i ,j ,k))))) + + \ No newline at end of file ```