Maybe a Coursera course

I received an email from Coursera, whose MooCs on General Game Playing, Logic, Automata… originally drew me to Prolog. (None of the above courses are still provided by Coursera, which attracts me to creating a new one).

I was told in the email that I was so honored to be invited to pitch a course on account of how many courses I’ve already done (I’m a MooCaholic). Anyways, I thought it would be a fun thing to do, making a short course basically polishing two things I’ve done on Swish Zebra Puzzles and Puzzles and Games into a short course on logic programming and the basics of Prolog.

I don’t want to make my course too academic – anyone who needs reasons why, watch this Panel: Since logic languages are so good, why aren’t they pervasive? - YouTube shouting match. ie, I want it to be very “vocational”.

Any suggestions on how to do this welcome. Furthermore, people more qualified than I am (probably everyone in this group) can pitch to create their own course via Coursera Community Guided Project Author Interest Form

8 Likes

Hi Joe,

I agree, the course should indeed be vocational – that would fill a gap, and perhaps even entice people to experiment with Prolog for work tasks.

I would stay away from puzzles – lots of puzzles exist in books and online – and they give an impression of Prolog being a toy thing.

Here is one suggestion:

Use an example from another paradigm – e.g. domain driven development [e.g. 1] – and show how Prolog can offer greater value given its support for relational computation and and non-determinism.

It should be possible to show that when viewing (and digitizing) the world beyond a functional view, prolog program is more general, more succinct and has less code (and hence less potential for error).

Dan

[1] Domain Driven Design | F# for fun and profit

Daniel

What I’ve decided to do is translate into Prolog simple SQL examples used by Stanford’s database MooC, which I’ve just signed up again for again to refresh my memory, and recommend highly. (One snag is I see it’s now on Coursera’s competitor edx, so probably political problems in cross referencing).

I’ve started writing notes on Swish as I progress, and will post the link once I’m far enough. I personally found thinking of Prolog as a high-level query language akin to SQL educational.

What I like about Zebra-style puzzles is they are tables with holes in them, so make the concept of deductive databases simple.

1 Like

This sounds really great! Just a word of warning:

This is a rabbit hole, in a way. Imagine a simple question, like, “what is the longest line/record that you have”?

If your database is in a file, you can use a combination of GNU wc and awk to answer that:

$ wc -L /usr/share/dict/words
24 /usr/share/dict/words
$ awk '{ if (length($0) == 24) print }' /usr/share/dict/words
formaldehydesulphoxylate
pathologicopsychological
scientificophilosophical
tetraiodophenolphthalein
thyroparathyroidectomize

You could do the same with awk only, but it will be a bit more roundabout.

With SQL it is kinda straight-forward. Using SQLite (no need to setup anything):

$ sqlite3
SQLite version 3.32.3 2020-06-18 14:16:19
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> Create table words ( w text );
sqlite> .import /usr/share/dict/words words
sqlite> Select w from words where length(w) = ( Select max(length(w)) from words );
formaldehydesulphoxylate
pathologicopsychological
scientificophilosophical
tetraiodophenolphthalein
thyroparathyroidectomize

Now the question: how do you do this in Prolog? And the answer is, “it depends” :wink:

To set it up similar to how it’s done in the SQLite example above, you could use this:

?- setup_call_cleanup(open('/usr/share/dict/words', read, In),
       read_string(In, _, Str),
   close(In)),
   split_string(Str, "\n", "", Words),
   forall(member(W, Words), assertz(w(W))).

OK, now we have all the words in a table w/1. How do you query for the longest word(s)?

Like this:

?- w(W),
   string_length(W, N),
   \+ ( w(W0),
        string_length(W0, N0),
        N0 > N
      ).

or maybe like this:

?- aggregate_all(max(N), ( w(W), string_length(W, N) ), N),
   w(W),
   string_length(W, N).

or maybe like this:

?- aggregate_all(max(N), ( w(W), string_length(W, N) ), N),
   findall(W, ( w(W), string_length(W, N) ), Words).

Is there a more efficient way to do it? A more obvious way to do it? Did we have to insert all words to the database? Would there be a better way to read the file and assert the words? Did we choose the correct data type?

It depends, I guess.

One approach would be to aggressively limit the scope of the course, so that you don’t have to go into such questions altogether.

2 Likes

I think the key question is this:

What domain oriented knowledge reasoning (pattern based searching) is best served with Prolog rather than SQL …

1 Like

Yes, agreed. On the other hand, showing someone only the shiny bits of a technology is only setting them up for bitter disappointment in the near future :slight_smile: but that’s just, like, my opinion.

I think that the extra deduction and inference capabilities of Prolog would be a really nice showcase to show that while e.g. the core data might be stored anywhere (inside the prolog dynamic database, read from a file, a full-fledged relational database, etc), Prolog is able to build layers of rules/relations on top of this data in a way that would be very difficult to do correctly when using either raw SQL or some other non-logical language (because then you lose the ability of using the rules in more than one direction).

Hi. Please excuse me for posting here. I only joined this a minute ago.
A month ago someone posted me on Freelancer, asking me to do a job. It was a university assignment in Prolog - the task was to write an interpreter for a Haskell-like language called H2035. The requester wanted the work to be done the same day and I have not heard back from them.
I am looking for the uni course so I can enrol or at least study the material.
I contacted UQ, where I studied most recently, hoping they might have a lead for me, but I have not heard back from them.

Kind regards
Richard

Unfortunately Coursera canned the course. In any event, it only covered the very basics, and didn’t get as advanced as writing interpreters.

I’ve dabbled with this a bit, rewriting an example from a textbook which I saved at

https://swish.swi-prolog.org/p/Compiler1.swinb

Hi, thanks for your reply!
I am hoping to be inspired to run your example. I tested out the examples in Slonneger’s book a while back.
Kind regards,
Richard

You can study lisprolog.
I think it’s been developed in SWI-Prolog, now uses Scryer Prolog…
HTH

Thanks. It is definitely worth looking at.