I am failing with using the predicates from the library CLPQR in SWI-Prolog. The library itself works. Expressions like "clpq: {X = 5^2}" are solved correctly. But I can't figure out how to use "minimize", "maximize", "inf", "sup", etc.
Link to the Prolog Manual http://www.swi-prolog.org/pldoc/man?section=clpqr. I'd really appreciate if anybody can give some Code Examples!!
Related
I have to study Prolog for the AI course at school. My teacher uses Visual Prolog which is only available on Windows. I use MacOS so I downloaded SWI-Prolog thinking it's similar. However, I noticed that the syntax is not the same. For example: the keyword if is replaced by :- in SWI-Prolog, also my teacher used this syntax:
predicates
likes(symbol, symbol)
clauses
likes(ellen, tennis).
likes(john, football).
which gives me an error in SWI-Prolog. What do I have to download to use the same syntax?
with this knowledge base using https://swish.swi-prolog.org
:- dynamic happy/1.
go:-
assert(happy(mia)),
write(happy(mia)).
if I run go. I get
happy(mia)
true
If I just have
:- dynamic happy/1.
assert(happy(mia)).
and run happy(mia), I get false.
What fundamental concept am I missing please?
When you write:
assert(happy(mia)).
you are (re)defining the predicate assert/1, not calling it as in your definition of the go/0 predicate. Thus, happy(mia) is never added to the database. The query fails as the predicate happy/1 is know by the system (thanks to the dynamic/1 directive) but have no clauses.
Most Prolog systems prevent the redefinition of standard built-in predicates. But assert/1 is a legacy/deprecated predicate. That explains why SWI-Prolog doesn't complain about the redefinition. Always use the standard assertz/1 predicate instead of assert/1.
I'm trying to get the definitions for a few built-in predicates using SWI-Prolog 7.4.2. Specifically, split_string/4.
explain/1 returns:
system:split_string/4 is a built-in predicate
Summary: ``Break a string into substrings''
true.
listing/1 returns:
Foreign: system:split_string/4
true.
I've checked the System.pl file, but I cannot seem to find the definition. Is this possible at all?
SWI-Prolog is C based. Look for *.c in github, more specifically at this source.
I have a owl ontology and I would use prolog rules and XSB to make inference. I know that the THEA library helps to convert owl code into prolog but no examples are available .
So could anybody help me.
Thanks in advance.
In many Prolog systems it is easy to add a new search path for consulting file.
In Yap for example, the predicate I know it is add_to_path(NewPath).
Is there a way to do the same in SWI Prolog ?. My question is specifically about adding one path to the already existing paths, I am aware of the file_search_path/2 predicate for declaring directories, and the cd/1 predicate for changing the current directory, but I would like to know if there is an alternative method, like the one I found in Yap.
thanks in advance !
There are several mechanisms to this. The first one I met was in C-Prolog, which indeed used clauses for library_directory/1. The current SWI-Prolog mechanism is derived from Quintus and also used in SICStus. It generalises from the library_directory/1 approach
be treating expressions of the form <alias>(Path) as a search over the path-alias <alias>.
Paths for an alias are defined using the predicate file_search_path/2. Now, library is just an alias. Normally, libraries are added using a clause file_search_path(library, Dir).
This mechanism has proven to be pretty flexible. Of course, it would be nice if Prolog systems get more compatible here. I think todays YAP also supports the file_search_path system. (2016 Edit: It does indeed, see YAP Prolog User's Manual: Changing the Compiler’s Behavior)
In your .plrc/.yaprc/.sicstusrc/.swiplrc:
:- multifile(library_directory/1).
library_directory('/home/ulrich/lftp/Prolog-inedit').