## Lisp Patterns Question W.R.T. Clifford AlgebrasMay 20th, 2009 Patrick Stein

Since I moved my website to WordPress, I have been watching what search-engine searches land people on my page.

Sadly, two of the things that get people to my page most often still have not been moved over to the new site from the old. One of those things is a C++ template library for Clifford algebras. I am going to move that stuff over this week, I promise. But, I thought I might also make a Lisp library for Clifford algebras, too.

An example Clifford algebra might be $C_{3,0}$. A generic element in this algebra is of the form:

$a_0 + a_1 e_1 + a_2 e_2 + a_3 e_3 + a_{1,2} e_{1,2} + a_{1,3} e_{1,3} + a_{2,3} e_{2,3} + a_{1,2,3} e_{1,2,3}$

where the $a_*$ are coefficients. For ease in dealing with these items, I will probably store that in a vector that looks something like this:
#($a_0$ #($a_1$ $a_2$ $a_3$) #($a_{1,2}$ $a_{1,3}$ $a_{2,3}$) $a_{1,2,3}$)

If you want a simple element though (where most of the coefficients are zero), you shouldn’t have to stare down all of that stuff or remember that $a_{1,3}$ comes before $a_{2,3}$. I want you to be able to make $3 + 4 e_1 + 5 e_{1,2,3}$ more simply. Something like one of the following:

(defvar *a* (ca-element '(3 (4 1) (5 1 2 3)) :p 3))
(defvar *a* (ca-element '(3 (4 . :e1) (5 . :e1-2-3)) :p 3))
(defvar *a* (ca-element :s 3 :e1 4 :e1-2-3 5 :p 3))

Similarly, I will define something akin to (aref …) so that one can check or change $a_{1,2}$ like one of the following:

(caref *a* 1 2)
(caref *a* :e1-2)

By analogy with the complex numbers, I should instead have:

(e1-2 *a*)

But, that just doesn’t scale very well.

I am leaning toward using a list of numbers to tell which $a_*$ is being referenced. This would allow greater flexibility in other functions. But, it’s also less mathy.

Does anyone have any suggestions? Should I really be supporting both? Through the same function names or through (caref …) and (caref* …) or something?

## Finding Better PolynomialsMay 12th, 2009 Patrick Stein

Some time ago, I wrote a small domain-specific language for finding polynomials given their value or the value of their derivatives at particular points.

It occurred to me shortly after writing that code that I could easily extend it to include the value of its integral over a certain range. I didn’t get to tackling that right away, and that was a Good Thing. In the intervening time, it occurred to me that I could extend it to moments as well.

So, are you looking for a polynomial that is zero at both zero and one, has a derivative of zero at one, has a second derivative of negative one at one, whose integral from zero to one is one, and whose mean (first moment centered at zero) on the interval zero to one is one fourth?

(polynomial-to-string
(calculate-polynomial-subject-to
(value :at 0 :equals 0)
(value :at 1 :equals 0)
(derivative :at 1 :equals 0)
(nth-derivative 2 :at 1 :equals -1)
(integral :from 0 :to 1 :equals 1)
(mean :from 0 :to 1 :equals 1/4)))

Well, that would be $f(x) = \frac{149}{4}x - 163x^2 + 265x^3 - 190x^4 + \frac{203}{4}x^5$. (For some reason though, gnuplot thinks $f(x) = -1$, so no graph for you…)

Here is the source file.

Edit: I realized that gnuplot was off by one because it was truncating the fractions. So, I just changed the 4’s in the denominators to 4.0’s and Bob’s your uncle.

## Find the Polynomial You’ve Been Looking ForApril 2nd, 2009 Patrick Stein

Often, I want to have a polynomial that meets certain criteria. For most applications in the past, I figured it all out by hand.

Today, I was having trouble getting the conditions specified enough to get the sort of polynomial that I was expecting. After finding the coefficients for several sixth degree polynomials in a row, I figured I should instead be able to do something like this with the proper lisp:

(calculate-polynomial-subject-to
(value :at 0 :equals 0)
(derivative :at 0 :equals 0)
(nth-derivative 2 :at 0 :equals 0)
(value :at 1 :equals 1)
(derivative :at 1 :equals 0)
(nth-derivative 2 :at 1 :equals 0)
(value :at 1/2 :equals 3/4))

That’s all done now (polynomials.lisp). So, for the record, the above is: $26x^3 - 63x^4 + 54x^5 - 16x^6$. That is still not quite the polynomial I want for this application, but it’s close. A few minutes of Lisp saved me hours of whiteboard work.