close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 1230


Ignore:
Timestamp:
2015-06-11T14:22:24-07:00 (10 years ago)
Author:
Marek Rychlik
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/f4grobner/utils.lisp

    r1229 r1230  
    2222(defpackage "UTILS"
    2323  (:use :cl)
    24   (:export "MAKELIST-1" "MAKELIST" "SUMMATION"))
     24  (:export "MAKELIST-1" "MAKELIST" "SUMMATION" "INNER-PRODUCT"))
    2525
    2626(in-package :utils)
     
    6464         (declare (fixnum ,var))))))
    6565
    66 (defmacro summation (expr (var lo hi &optional (step 1)) &optional (addition '+) (initval 0))
     66(defmacro summation (expr (var lo hi &optional (step 1)) &optional (add '+) (init-val 0))
    6767  (let ((r (gensym)))
    68     `(do ((,r ,initval)
     68    `(do ((,r ,init-val)
    6969          (,var ,lo (+ ,var ,step)))
    7070         ((> ,var ,hi) ,r)
    71        (setf ,r (,addition ,r ,expr)))))
     71       (setf ,r (,add ,r ,expr)))))
     72
     73(defmacro inner-product (x y &optional (add '+) (mult '*))
     74  (let ((i (gensym)))
     75    `(summation (,mult (elt ,x ,i) (elt ,y ,i)) (,i 0 (1- (length ,x))))))
    7276                                       
    7377                               
Note: See TracChangeset for help on using the changeset viewer.