Levi-Civita symbols in Lisp

The following function calculates

sgn(ai+1ai) sgn(ai+2ai) … sgn(anai)


(defun sgn-diff (lst)
  (do ((ls (cdr lst) (cdr ls))
       (res 1 (* res (signum (- (car ls) (car lst))))))
      ((null ls) res)))

Then, the Levi-Civita symbols εa1a2an are calculated as follows


(defun levi-civita (lst)
  (do ((ls lst (cdr ls))
       (res 1 (* res (sgn-diff ls))))
      ((null ls) res)))
Advertisements
Published in: on 22/02/2014 at 14:41  Leave a Comment  

The URI to TrackBack this entry is: https://burubaxair.wordpress.com/2014/02/22/levi-civita-symbols-in-lisp/trackback/

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: