Wiki Discussion: Unification

Found out that HTML can use SVG as an island grammar. See: Inline SVG example

Need to add part about Prolog flag for occurs check and allow_variable_name_as_functor

1 Like

This is unrelated to unification. It is a mere syntax extension that was once added to deal with some domain specific language project. The var_prefix flag is more promising for such cases while we also have quasi quotations.



I didn’t think you were reading these as I wrote them, but glad you are.

Warren’s Abstract Machine - A TUTORIAL RECONSTRUCTION
See: Chapter 2 - Unification—Pure and Simple

One thing is lacking there: unification of cyclic terms (or infinite trees). This works (not in all Prolog systems though):

?- X = f(X), Y = f(Y), X = Y.
X = Y, Y = f(Y).
1 Like

I didn’t know that was possible. Something more for me to learn about. Thanks.

You may also want to do a web search for “rational trees” (I think this terminology is from Prolog II).

More specifically:

I knew that X=Y was possible.
I knew that X=f(X) and Y=f(Y) was possible if the occurs check was not being applied.
But when I look at X = f(X), Y = f(Y), X = Y.
I think X is unified with f(X) and Y is unified with f(Y) by lack of occurs check, but then I stop the unification process in my head because I don’t think there is more, but obviously there is because the MGU does not include X = f(X) which if this were a test I would have answered wrong or been very confused and probably not have given a correct answer unless it was multiple choice upon which I could have reasoned that there was an answer I wasn’t expecting and it would have been a correct answer.

After X=f(X) and Y=f(Y) you end up with two identical cyclic terms. You want unification to succeed, but if you do the good old naive unification you go into infinite recursion (or loop if you apply last argument optimization). I learned how to deal with this from Bart Demoen. It is described in the sources.

1 Like

See: GitHub SWI-Prolog/swipl-devel - Cyclic Terms

I don’t know how I forgot to add this earlier.

Unification theory - Chapter 8 of Handbook of Automated Reasoning (WorldCat)

There’s also one-way unification, otherwise known as pattern-matching. (Erlang, ML, Python use various flavors of pattern-matching)

This might help a bit (I haven’t read through it all … there’s some discussion about linear and non-linear pattern matching, which is terminology I’m not familiar with):

And don’t forget subsumption, which is important for tabling. :wink: [Do a web search for subsumption unification and have fun …]

1 Like

On the topic of subsumption, it’s useful to know that subsumes_term/2 was added to ISO Prolog in Corrigendum 2 in 2012. The draft can be found here.

Subsumption is also very important in inductive logic programming. A clause A implies a clause B if (but not only if) A subsumes B. Subsumption is much easier to “invert” than general implication.

1 Like

As much as I want to work on adding to the Wiki topics here, my main hold back is that using links in HTML to other files such as SVG is still a problem because of Discourse.

In using SWISH it seems that I can at least enter an HTML cell and use inline SVG (example).

Also it seems that I can create an HTML iframe bringing the SWISH page right into a Discourse topic.

So this is a test.

First a Google map to the Eiffel Tower in an iframe

Note: IFrame HTML deleted because the iframe updates every few seconds and causes a scroll of the post. Use history to see the IFrame HTML if desired.

second a use of CodePen without any HTML attributes

Note: IFrame HTML deleted because the iframe updates every few seconds and causes a scroll of the post. Use history to see the IFrame HTML if desired.

and now an iframe for the SWISH page.

Note: IFrame HTML deleted because the iframe updates every few seconds and causes a scroll of the post. Use history to see the IFrame HTML if desired.

Not the greatest, but at least it worked.

Don’t count on the feature staying around as this was only a test and while it did work, it doesn’t seem to be practical. Will work on it some more, but don’t count on this as a permanent option just yet.

Using the iframe attributes width="600" height="450" frameborder="0" style="border:0" allowfullscreen

Played with this some here but then switched to use Discourse demo.

In trying to get the iframe for SWISH to be wider, (full width) ran into more issues with Discourse.
Instead of creating multiple replies, I am just adding any links that may be of value in trying to solve this problem into this one reply.

How to increase width of topic
Css to hide topic timeline per topic
Shadowboxes for IFRAMEs (SOLVED)
Iframe Lightboxes
Bind iframe height to its content height with jQuery
Custom Layouts Plugin
Jsfiddle-like embeds?
Support for Jupyter notebooks
A Quiet Desert Sunset - Themes can be specific to a category

Now I know why people are making a full time living as Discourse consultants.

At this point just doing the fancy stuff in SWISH looks more promising and just posting a link from the Wiki page to SWISH.

So if you saw the SWISH iframe working here for a few minutes and now it fails, it was because I first enabled the feature then disabled it. :shushing_face:

It would be nice if we could do something like for lpn. I understood as a hosted discourse site we are limited to (a subset of) the official Discourse plugins though :frowning: Another nice-to-have would be if name/arity for a known SWI-Prolog predicate would directly link to the docs.

1 Like

Can you elaborate on this a bit more or point me to what can an can not be done with the Discourse for SWI-Prolog. While I am aware that plugins can be made, (Ruby on Rails ?) I would prefer not to go that route if possible.

Gets my vote. :heart:

AFAIK we can only use plugins that can simply be activated through the admin interface. We cannot write and upload plugins. If we want that we must self-host the Discourse server, but I’m glad that is all taken care of. I can imagine they do not want user plugins for security and maintenance reasons.


Is there a way we can inject javascript though? The predicate links at least should be doable without having to do anything on the server-side here.