Randomizing priority in Prolog predicates -


one of main differences between prolog , first order logic in strict rule priority of right parts in predicate. know if there way randomize priority without renouncing @ normal backtracking behaviour. in particular i'm working swi-prolog solution works interpreter.

although there no built-in way use randomness search strategy in prolog theorem prover, there native functions there generate random numbers used (in roundabout way) randomize instance of predicate chosen consideration next.

to elaborate, might include each instance of predicate path/n 2 additional tests represent range within 0 , 1 predicate holds. range (lo, hi) should chosen such hi - lo = 1 / k, k total number of instances predicate path/n has in knowledgebase.

path(n, ...) :- n >= 0.0, n < 0.2, ... path(n, ...) :- n >= 0.2, n < 0.4, ... path(n, ...) :- n >= 0.4, n < 0.6, ... path(n, ...) :- n >= 0.6, n < 0.8, ... path(n, ...) :- n >= 0.8, n <= 1.0, ... 

with embedding of ranges, making instances of path/n equally considered. whenever path/n called in rhs of rule or production (right of :- or -->), should preceded generation of random float between 0 , 1 passed first argument path/n; e.g. foo :- random(n), path(n, ...)..

this of course become cumbersome on time knowledge base increases in size, might want write compiler (like dcg compiler) generates randomness threading you. writing these sorts of compilers in prolog surprisingly not work predicates asserta , assertz.

if using "random derivation search" method avoid infinite left recursion, know nicer method might write solution uses breadth-first search rather prolog's intuitive depth-first. involved threading state argument predicates (worth google: prolog breadth-first).

edit: prolog higher-order logic (hol), except in strict left-derivation, first-predicate-first-considered way, leads problems left recursion. use (hol) features of prolog model search approach considers predicates evenly (assuming predicates pure predicates, no arithmetic, etc.). example, store right hand sides list of predicates [[p1, p1a1,...],[p2,p2a1,...]|_], randomize list before evaluation, evaluate shuffled list of predicates iteratively building predicate using =.. operator, i.e. x =.. [p1, p1a1, p1a2], x. x in snippet unified p1(p1a1,p1a2), , searched satisfiability.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -