Pfc pack (forward chaining) -- can't get to work

I have SWI-Prolog running and upgraded on Ubuntu 18.04 but JPL is a package and needs to be added separately. Currently reading Deploying for users - on Linux

Details of error
?- use_module(library(jpl)).
ERROR: source_sink `library(jpl)' does not exist
ERROR: In:
ERROR:   [19] throw(error(existence_error(source_sink,...),_11038))
ERROR:   [15] '$resolve_source_path'(library(jpl),_11070,[if(not_loaded),...]) at /usr/lib/swi-prolog/boot/init.pl:2265
ERROR:   [14] '$load_file'(library(jpl),user,[if(not_loaded),...]) at /usr/lib/swi-prolog/boot/init.pl:2239
ERROR:    [9] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

Please try this first before reading further.

It does not get pfc working but doesn’t report the jpl error.

?- halt.

Restart SWI-Prolog

?- use_module(library(jpl)).
?- use_module(library(pfc)).

There should be no errors. If that works let me know so I can undo a step.

If that does not work or you get an error read further.


In looking for a Linux solution found that adding C:\Program Files\swipl\bin to the Windows environment variable PATH might help

but then tried

?- use_module(library(jpl)).

which failed.

Then tried

?- halt.

Restart SWI-Prolog

?- use_module(library(jpl)).
% Extended DLL search path with
%   'c:/Program Files/Java/jdk-12/bin/server'
%   'c:/Program Files/Java/jdk-12/bin'
true.

?- use_module(library(pfc)).
% Disabled autoloading (loaded 107 files)
% Disabled autoloading (loaded 19 files)
% Disabled autoloading (loaded 0 files)
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_base.pfc.pl:152 
% loading_system_base.
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl:38 
% nop(mpred_unload_file('c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl')).
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl:40 
% debugm(baseKB, show_success(baseKB, set_fileAssertMt(baseKB))).
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfc.pl:16 
% warn(mtHybrid(user)).
% debugm(not_is_pfc_file, show_success(not_is_pfc_file, ensure_abox(user))).
true.

?- not(P),P => contrradiction.
ERROR: Unknown procedure: (=>)/2 (DWIM could not correct goal)

So the pfc code seems to run, but I don’t know if I am getting the correct answers.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.4-11-g1db629e24)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- use_module(library(jpl)).
% Extended DLL search path with
%   'c:/Program Files/Java/jdk-12/bin/server'
%   'c:/Program Files/Java/jdk-12/bin'
true.

?- use_module(library(pfc)).
% Disabled autoloading (loaded 107 files)
% Disabled autoloading (loaded 19 files)
% Disabled autoloading (loaded 0 files)
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_base.pfc.pl:152 
% loading_system_base.
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl:38 
% nop(mpred_unload_file('c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl')).
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfclib/system_mdefault.pfc.pl:40 
% debugm(baseKB, show_success(baseKB, set_fileAssertMt(baseKB))).
% c:/users/eric/appdata/local/swi-prolog/pack/pfc/prolog/pfc.pl:16 
% warn(mtHybrid(user)).
% debugm(not_is_pfc_file, show_success(not_is_pfc_file, ensure_abox(user))).
true.

?- not(P),P ==> contradiction.
false.

The problem with the examples is they have not been updated.

As noted at the GitHub page

Notable changes are:

  • Forward chaining => is renamed to ==> to avoid conflict with extensive downstream use of =>/2 to mean logical implication.
  • Bidirectional Forward chaining <=> renamed to <==> to avoid conflict with logical equivance <=>
  • Memoized backchain <= is renamed to <- to avoid conflict with extensive downstream use of <=/2 to mean reverse implication… Historically ‘<-’ had meant what is now know as “:-” being unused it was borrowed as it means “Backchaining”
  • Added Macro Transform =@=> so instead of asserting the Anteceedant to assert the Consequent

EDIT

This works as expected

?- ain(gender(P,male) ==> male(P)).
true.

?- ain(gender(joe,male)).
true.

?- male(X).
X = joe.

So thanks goes to my friend of the clan German Shepard. :smiley:

1 Like

This might be of interest

Seventy-Five Problems for Testing Automatic Theorem Provers by Francis Jeffry Pelletier

This is great!

Thank you so much for your effort.

Let me replicate this.

Dan

It works …

Although, upon use_module(library(pfc)), i get an error:

?- use_module(library(pfc)).
ERROR: c:/programdata/swi-prolog/pack/pfc/prolog/pfc2.0/mpred_loader.pl:199:
ERROR:    source_sink `library(dictoo_lib)' does not exist
Warning: c:/programdata/swi-prolog/pack/pfc/prolog/pfc2.0/mpred_loader.pl:199:
Warning:    Goal (directive) failed: pfc_lib:use_module(library(dictoo_lib))

but installing the dictoo pack (luckily its there), removes the error …

that’s great.

Curious what ain stands for – there is no aout … i guess, there needs to be a way to remove an asserted fact so that the machinery can retract male(joe) as well.

Dan

found it …

ain(\+ gender(joe, male)).

would remove male(joe) …

1 Like

Hi,

Sorry I did not notice the messages until late. Will work to make sure it’s working correctly with the right dependencies for the next hours.

ain = “add if new”

Tim’s “add/1” predicate was too conflicting

Removing male(joe)

Is accomplished by
ain( + gender(joe, male)).

the + means not present

1 Like

Many thanks for the response and the explanation.

I am very glad that you are still looking into this. If you could remove the dependency on the java interface that would be great.

Also, i am very curious which version of code is the one installed with the pack – the git and pack description list several versions.

Dan

Perhaps, another comment …

I noticed that once i installed pfc the prolog window generates a lot of messages during visual debug – and the few messages that my application generates (via writeln) essentially scroll away.

Is there a way to remove all the messages – i assume these are messages generated by the internal pfc mechanisms.

thanks,

Dan

Can you paste an example with the messages. I am curious as to exactly how you are initiating this and also what the messages are. I am thinking debug/1 but that does not seem correct in this case.

Pack version should be 1.5.665

When i get done tonight it will be 1.5.666

Well 1.2 was Tim’s original version and did not work with modules (using independent forward chain rules “per module”).

So I created 2.0 which is module aware… But the code over time got messy but lots of new features:

  • Module inheritance of rules.
  • Forward chaining rules that could edit existing prolog “:-” code. (Not just facts)
  • Support for 2 types of Negation:
  • By failure +
  • By explicit ~
  • … a few more i’ll document…

But a few years ago since the code was getting messy I decided to restart it as 2.2 But it never worked out well.

Then this last week I was starting 3.0 which was supposed to be simpler/faster with the features.
But now I am abandoning 3.0 (for a while for awhile) and just fixing 2.0 to run faster since it is still the best.

So for now the 2.0 version is going to continue to be improved.

1 Like

And yes I’ll fix the issue with JPL in the next couple hours … I think this might be a windows specific issue and its been a while since i tested this on windows

As some other suggestions to improve this for others that may follow. I personally have no pressing need for these at the moment.

  1. Convert the examples in to SWI-Prolog unit test, or at least duplicate them as test when running with SWI-Prolog. I can do that if you prefer and send a pull request, but it would not be for quite some time.

  2. While @grossdan and I use Windows 10, it would also be nice to know how to install this with the PPA build on Ubuntu. I ran into the problem of trying to install JPL but my Linux troubleshooting knowledge base is not as extensive as my Windows troubleshooting knowledge base.

  3. Can the JPL usage be converted to library(persistency)? Finding out how to use library(persistency) is a bit of a challenge so I can help here if you seek this.

  4. While I know the code is meant for Prolog in general, this site is indexed by many search engines and if a Wiki topic is added it would also get indexed and bring more attention to pfc. Again I can help you here if needed.

The reason for these suggestions is that from the little I have seen you have a great tool with pfc but others are

  1. not aware of it
  2. don’t know how to install it
  3. don’t know the benefits it can bring to solving certain problems
  4. will not use it if it is not easy to get started with, e.g. having to convert the examples and know the code works with test cases.

Hi,

Thank you for your comments.

I am hoping to make extensive use of Pfc – it seems to fit very well with what i need – and performance will indeed become a key issue in the future.

I would be happy to also contribute example uses, and if time permits, intro tutorials, as i myself learn how to use it well – and note down my own lessons learned.

thank you for this great work,

Daniel

1 Like

Here is a small sample:

 [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process] New GUI for thread 'pdt_console_client_0_Default Process', break level 0
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process]  ---> 8218: send_pce: result = true([@314569800228/prolog_debugger])
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process]  ---> 8219: send_pce: result = true([])
% [Thread pdt_console_client_0_Default Process] prolog_show_frame(377, [port(exit),choice(386),stack])
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process] GUI = @314569800228/prolog_debugger (from thread 'pdt_console_client_0_Default Process')
% [Thread pdt_console_client_0_Default Process] stack ...
% [Thread pdt_console_client_0_Default Process] real_thread: 'pdt_console_client_0_Default Process' --> 'pdt_console_client_0_Default Process'
% [Thread pdt_console_client_0_Default Process] Stack frames: [frame(377,exit),frame(328,38),frame(308,26),frame(83,2),frame(74,19),frame(61,50)]
% [Thread pdt_console_client_0_Default Process] Frame 377 at level 16
% [Thread pdt_console_client_0_Default Process] Frame 61 at level 1
% [Thread pdt_console_client_0_Default Process] Levels 1-16, CHP = 386
% [Thread pdt_console_client_0_Default Process] Choice 368 of type jump running frame 328
% [Thread pdt_console_client_0_Default Process] Choice 359 of type clause running frame 350
% [Thread pdt_console_client_0_Default Process] Choice 341 of type clause running frame 328
% [Thread pdt_console_client_0_Default Process] Choice 218 of type clause running frame 83
% [Thread pdt_console_client_0_Default Process] Choice 190 of type foreign running frame 83

Thanks.

How are you initiating them? What query did you run?

I believe now the JPL should no longer be a problem

I moved the examples to here for later:

https://github.com/TeamSPoon/pfc/tree/master/t/unit_tests

I did start to do them as tests a bit as well: https://github.com/TeamSPoon/pfc/tree/master/t/sanity_base

1 Like