Diagramming algorithms implemented in prolog

Hi,

I am trying to document the overall design of my code. My first attempt is to create flow charts of broad steps performed and related static and dynamic data structures.

However, I now noticed that once one looks into backtracking – this can become quite tricky.

For example, one flow chart step could be a generator – generating examples to test – while in another location quite further down of multiple recursive calls, there could be a fail, to initiate a backtracking.

The fail causes backtracking across many calls, untraveling various computations until the generator gets to redo and call to test another example.

are there any good visual techniques to visualize that …

Dan

Take a look e.g. to SWI-Prolog graphical profiler and Logtalk ports profiler.

1 Like

Yes,

Use the box model.

This is one of those cases where using Google Image search leads to better pages than Google text search.

https://www.cs.nmsu.edu/~ipivkina/ECLIPSE/doc/userman/node76.html

Another variation that can be used is based on derivation tree.

1 Like

Thank you

This the box model with the ports looks very useful. I really like to back “redo” arrow – that what i was missing …

I will need to work out how to do this legible on a page …

thank you,

Dan

If you have Visio or other similar application that helps.

Another way to make them presentable on paper is to use graphviz dot

Visio is faster, but proprietary, however you can save in many formats including SVG.

Dot is widely known an used and is what I used here. The dot output was saved as SVG which is nice because Internet browsers can read them and they scale nicely.

Both have a learning curve, but once you do it for a while it becomes old hat

You might want to search the SWI-Prolog packages, several of them make use of GraphViz, e.g.

http://www.swi-prolog.org/pack/list?p=gvterm

and might actually do what you are planing or at least have code that use to work but is no longer maintained, but is useful for studying.

thanks,

I am drawing them in power point – and more abstractly than the code.

I also notice that having two lines in parallel for call and redo, seems reducant – every call implies a redo – so i can simplify that – i think.

its the nested boxes and llines across boxes on the page that seem to hold the essentials

The diagram with the circular recursions i am getting is interesting – almost Escher like :slight_smile:

1 Like

A nice alternative to using a Thank You response with discourse is to just click on the heart

Capture

This not only saves the time of saying thank you, it also helps those you thank get a higher trust level and reflects in the users profile, e.g. EricGT.

Additionally it saves on the amount of reading others have to do and notifies others that this is a reply worth reading or noting for future use.

However if it is a Thank You and some added info, then by all means use a response, and give the heart a click.

The way the accounts are set up by default is that if a response is created with a quote or @<user tag> then they get an instant messages on their computer.

If a heart is clicked on a topic they made then it doesn’t disturb the OP of the response; instead it shows up in their notification queue.

Capture

That does not sound correct. Can you give an example image that has a few boxes working together and the corresponding Prolog source code so that we can check it. You don’t want to pick up a bad or invalid habit at first then have to re-learn which is harder than just learning.

Curious how far is a predicate cross-reference diagram (e.g. html_basics_module) from what you want for documenting your code. These diagrams can show recursive calls (a calls edge linking a predicate to itself), predicates updating (i.e. asserting or retracting) dynamic predicates (updates edges), and links to your source code (as in that example). They will no show the exact sequence of calls, however (only edges to called predicates). Still, it should be possible to automatically generate a diagram with at least some of the extra information you mention. Doing it manually means that diagrams and code can easily get out of sync, diminishing the diagrams values as documentation. Can you share one of those diagrams that you’re making for comparison and clarification?