Difference between (Facts and Predicates) && (Single and Determ)

4k Views Asked by At

I just wonder, what is the difference between "facts" and "predicates" section in prolog ?

and what is the difference between "single" and "determ" keyword ?

2

There are 2 best solutions below

2
On BEST ANSWER

Just to point the obvious: "Facts section" is for facts, facts are predicates that are always true, are used to describe some properties.

Single and determ are "fact mode", used optionally in a fact declaration, Single means the fact always has one and only one value, determ means the fact can have zero or one value.

0
On

Fact in prolog is substitution of predicat like table in db Table(Column1,Column2, ...) indeed Facts takes the form like Fact(Arg1,Arg2) which gives us {true,false} values ONLY for the specific constants mentioned inside "()"

so Fact is a complex term or predicate of arguments indeed, Args are not a variables,are individual constants.

example

father(fathername,childname).

Rule are also substitutions of predicate takes the form

rule_type1(+In_Args,?Out_Args) :- body .  
rule_type2(+In_Args) :- body . % (true,false)
rule_type3 :- body . 

it order to generate data from facts or from logique rules derived into body through Querys

example

max(X,Y,Z) :- X>=Y -> Z=X ; Z=Y .

?- max(3,5,Z).   /* give us */ Z=5

in visual-prolog Facts can be declared with several optional keywords:

Facts declared with the keyword determ.

The keyword determ determins that the facts database can only contain one instance of a fact (database predicate) fact_N(...) declared with this keyword. So if you try to assert one and then a second such fact into the database, the Visual Prolog engine will generate runtime error. (1041 Assert to a fact declared as determ, but fact already exists). example

Facts declared with the keyword single.

The keyword single before a fact fact_N declaration determines that one and only one instance of a fact must always exist:

Since single facts must be already known when the program calls Goal; therefore, single facts must be initialized in a clauses section in the program's source code.

For example:

FACTS
single singleFact(STRING, STRING)
CLAUSES
singleFact("","").