b-prolog

Uneven tabling performance in BProlog 8.1

…衆ロ難τιáo~ 提交于 2019-12-19 19:50:06
问题 I did a few experiments with the tabling capabilities of b-prolog version 8.1 and was quite surprised by the performance I observed. Here is the code that I used. It counts the number of Collatz steps N required for reducing some positive integer I down to 1 : %:- table posInt_CollatzSteps/2. % remove comment to enable tabling posInt_CollatzSteps(I,N) :- ( I == 1 -> N = 0 % base case ; 1 is I /\ 1 -> I0 is I*3+1, posInt_CollatzSteps(I0,N0), N is N0+1 % odd ; I0 is I>>1, posInt_CollatzSteps(I0

Nested loops with accumulators in B-Prolog

北城余情 提交于 2019-12-10 21:37:41
问题 B-Prolog has logical loops. For example, that's how we can calculate sum of [1,2,3]: test1 :- foreach(A in 1..3, [], ac(Sa, 0), ( Sa^1 is Sa^0 + A )), writeln(sa(Sa)). ?- test1. test1. sa(6) yes But when I try two nested loops with accumulators, I get errors: test2 :- foreach(_A in 1..3, [Sb], ac(Sa, 0), ( foreach(B in 1..3, [], ac(Sb, 0), ( Sb^1 is Sb^0 + B )), writeln(sb(Sb)), Sa^1 is Sa^0 + Sb )), writeln(sa(Sa)). ?- test2. test2. *** error(invalid_argument,(+)/2) Another variant, not