In my last article, I showed how we can use Prolog to generate univariate Polynomials. After I finished that article, I wanted to try Lisp for the same task. Prolog is “declarative”, whereas Lisp is primarily “functional” (it supports OOP as well), so the implementation will exhibit that difference.
Here is the primary function generate-polynomial along with the tester function (main):
Here is sample output (polynomials of degree 4):
Generate-polynomial uses the following functions to generate a polynomial of given degree:
A few utility functions are also used along the way. These are:
Here is another sample output:
As you can see, the output is quite random. Let us try to generate polynomials of degree 3:
Nothing fancy or surprising here. The program works as expected.
Between the Prolog and Lisp implementations, I think had to write some extra code to get the Lisp implementation working. Maybe if I had used some external utility libraries, I could have saved some code, but that is no big deal. Anyway, it was a nice exercise for me!
The code is implemented in LispWorks Lisp 8.0.1 Enterprise Edition for Windows 64 bit. You can download the code here.
Have a nice weekend!
Recent Comments