Hello everybody,
After doing some side projects, I encountered the same kind of problematic multiple times and I wanted to discuss with the community the topic.
Let me start with use-cases which I hope will explain the topic:
- Imprecise geometry
For a graphical grammar project, I needed to unify coordinates as long as their difference is smaller than an epsilon.
I managed to do it using clpBNR by using the following formula:
abs(A - B) =< Eps.
But what I really would have liked to write is this: A = B.
Although in this case, we still need to deal with Eps, maybe as a global config or as an implicit state.
- unit with aliases
With my recent units pack, I needed to implement the concept of unit aliases.
So for example, kilogram is an alias of the unit kilo(gram).
Dealing with aliases adds a lot of complexity in the code since I can’t use unification anymore.
Basically, I would want this to work kilogram = kilo(gram).
- probabilistic logic programming ?
I have never actually used probabilistic logic programming, but I believe it could be a relevant use case.
When doing A=B, it would automatically associate a probability to that unification.
If that probability turns out to be 0, then the unification fails.
If the probability is 1, then it is a classic unification.
What solution can we imagine facilitating these patterns ?
- the current status quo
A pure Prolog solution is to stop using unification and make helper predicate that wrap the new type of unification.
For example, wrapping the earlier clpBNR formula in a predicate like eps(Eps, A, B) and use it everywhere it is needed.
The cons of this method are that we loose unification and all its benefits:
- syntactical clarity:
A=Bis a very clear and beautiful syntax - unification in the head of a clause
- Argument indexing in the head of a clause
- constrained variables
One could image using only variables, and attach constrains to these variables and never instantiate them.
This allows us to “overload” unification with the attr_unify_hook and redefine the unification there.
Although it could work for my geometry use case where I already use constraints with clpBNR, it would be very annoying with the aliases in my unit library.
- generalize
attr_unify_hookto any type of data
Imagine we could say that we want to customize unification for every term of the type unit(U).
Then, we could deal with aliases inside the hook.
Maybe even write a very fast unification function for optimization ?
Has anyone worked on something like this ?
What are your thought on this ?
This type of question was already discussed a bit in this thread