Multiobjective Optimization (MOO) in Lisp and Prolog

Written by on November 22, 2024 in C++, LISP, Programming, Prolog with 0 Comments

Recently I came across a nice article by Jose Crespo, where the author stresses that the future of programming revolves around the application of math concepts such as Functor, Monads, Folds, etc. In addition, he argues that familiarity with C/C++ is essential in this modern AI age.

The author goes through a toy example that uses time and energy to show how Multiobjective Optimization (MOO) framework can be quite useful in the real world.

I strongly urge readers to go through that article before continuing, since what follows is based on that article.

What impressed me most about the article was the elegant and compact C++ code (using the latest language features) that shows how to use Pareto Front approach to consider both time and energy for arriving at an optimal solution.

Readers may know that my favourite top three programming languages are C++, Common Lisp and Prolog. So when I finished reading that article, I wanted to rewrite the solution in Lisp and Prolog.

Here is the Lisp code:

Lisp Code for Pareto Front

Lisp Code for Pareto Front

Here is the program output:

Program Output

Program Output

The Lisp program is no less elegant in my opinion! Of course Lisp is a dynamically typed language and hence the performance (space and time) is likely to be marginally inferior to C++ (by the way, LispWorks has a great compiler that can generate optimized native code for the Lisp program). Keeping efficiency aside, the remarkable thing about Common Lisp is its support for Multimethods and Meta Object Protocol (MOP).

Now, let us look at the equivalent Prolog program:

Prolog Code

Prolog Code

The main predicate follows:

Prolog "main" Predicate

Prolog “main” Predicate

When you run the program, this is the output:

Prolog Output

Prolog Output

In both Lisp and Prolog, the result matches the C++ output (as described in the article).

I chose Prolog to show that the logic can be implemented in this language too, but it would not be my natural choice for this implementation.

The point is that while C++ is arguably the best language to implement most algorithms, especially with the features available in the recent language specifications, if not running on embedded systems or on resource-critical systems, then languages such as Lisp are equally good choices for implementing such algorithms.

You can download the Lisp and Prolog code here.

Have a nice weekend!

Tags: , , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top