swi-prolog

How to enable the occurs check in all unifications in SWI-Prolog?

只愿长相守 提交于 2021-02-09 04:14:37
问题 According to Wikipedia: Implementations offering sound unification for all unifications are Qu-Prolog and Strawberry Prolog and (optionally, via a runtime flag): XSB, SWI-Prolog and Tau Prolog. However, when I do apropos(occur) it only finds unify_with_occurs_check/2 . The man page doesn't mention "occur" either. How can the occurs check be enabled for all unifications in SWI-Prolog? 回答1: In the section on Environment Control, it lists the flags of the system. The occurs_check flag is the one

Defining CHR constraints at runtime

五迷三道 提交于 2021-02-07 14:51:13
问题 I'm trying to write a program that generates new constraints at runtime in SWI-Prolog. is_true([A,means,B]) is intended to generate another constraint at runtime: :- use_module(library(chr)). :- chr_constraint is_true/1. is_true([A,means,B]) ==> (is_true(A) ==> is_true(B),writeln('asserted')). is_true([[A,is,true],means,[A,is,not,false]]). is_true([something,is,true]). But when I type these queries, the is_true constraint seems to have no effect. is_true([something, is, not, false]) does not

Defining CHR constraints at runtime

空扰寡人 提交于 2021-02-07 14:50:09
问题 I'm trying to write a program that generates new constraints at runtime in SWI-Prolog. is_true([A,means,B]) is intended to generate another constraint at runtime: :- use_module(library(chr)). :- chr_constraint is_true/1. is_true([A,means,B]) ==> (is_true(A) ==> is_true(B),writeln('asserted')). is_true([[A,is,true],means,[A,is,not,false]]). is_true([something,is,true]). But when I type these queries, the is_true constraint seems to have no effect. is_true([something, is, not, false]) does not

What occurs-check optimizations is SWI Prolog using?

笑着哭i 提交于 2021-01-27 07:07:40
问题 To quote the SICStus Prolog manual: The usual mathematical theory behind Logic Programming forbids the creation of cyclic terms, dictating that an occurs-check should be done each time a variable is unified with a term. Unfortunately, an occurs-check would be so expensive as to render Prolog impractical as a programming language. However, I ran these benchmarks (The Prolog ones) and saw fairly minor differences (less than 20%) in SWI Prolog between the occurs check (OC) being on and off: OC

Overflow handling in GMP pow

吃可爱长大的小学妹 提交于 2021-01-26 06:53:04
问题 (I am only an indirect user of the GMP-library primarily through swi-prolog and yap. But I am very much interested in fixing this problem.) When performing exponentiations with ridiculously large values, the host-systems or GMP are no longer able to handle the overflows appropriately. I have talked to the developers of above systems, but they do not see an easy fix for this. Is this problem known to other GMP systems/users? How do you handle such overflows? As a sanity check first test the

Overflow handling in GMP pow

醉酒当歌 提交于 2021-01-26 06:52:40
问题 (I am only an indirect user of the GMP-library primarily through swi-prolog and yap. But I am very much interested in fixing this problem.) When performing exponentiations with ridiculously large values, the host-systems or GMP are no longer able to handle the overflows appropriately. I have talked to the developers of above systems, but they do not see an easy fix for this. Is this problem known to other GMP systems/users? How do you handle such overflows? As a sanity check first test the

Overflow handling in GMP pow

ε祈祈猫儿з 提交于 2021-01-26 06:51:42
问题 (I am only an indirect user of the GMP-library primarily through swi-prolog and yap. But I am very much interested in fixing this problem.) When performing exponentiations with ridiculously large values, the host-systems or GMP are no longer able to handle the overflows appropriately. I have talked to the developers of above systems, but they do not see an easy fix for this. Is this problem known to other GMP systems/users? How do you handle such overflows? As a sanity check first test the

Import csv file data to populate a Prolog knowledge base

这一生的挚爱 提交于 2021-01-22 08:50:33
问题 I have a csv file example.csv which contains two columns with header var1 and var2. I want to populate an initially empty Prolog knowledge base file import.pl with repeated facts, while each row of example.csv is treated same: fact(A1, A2). fact(B1, B2). fact(C1, C2). How can I code this in SWI-Prolog ? EDIT, based on answer from @Shevliaskovic : :- use_module(library(csv)). import:- csv_read_file('example.csv', Data, [functor(fact), separator(0';)]), maplist(assert, Data). When import. is

Import csv file data to populate a Prolog knowledge base

纵饮孤独 提交于 2021-01-22 08:49:09
问题 I have a csv file example.csv which contains two columns with header var1 and var2. I want to populate an initially empty Prolog knowledge base file import.pl with repeated facts, while each row of example.csv is treated same: fact(A1, A2). fact(B1, B2). fact(C1, C2). How can I code this in SWI-Prolog ? EDIT, based on answer from @Shevliaskovic : :- use_module(library(csv)). import:- csv_read_file('example.csv', Data, [functor(fact), separator(0';)]), maplist(assert, Data). When import. is

Import csv file data to populate a Prolog knowledge base

元气小坏坏 提交于 2021-01-22 08:48:45
问题 I have a csv file example.csv which contains two columns with header var1 and var2. I want to populate an initially empty Prolog knowledge base file import.pl with repeated facts, while each row of example.csv is treated same: fact(A1, A2). fact(B1, B2). fact(C1, C2). How can I code this in SWI-Prolog ? EDIT, based on answer from @Shevliaskovic : :- use_module(library(csv)). import:- csv_read_file('example.csv', Data, [functor(fact), separator(0';)]), maplist(assert, Data). When import. is