3:- module(common_logic_compiler,
4 [
5 nnf/3,
6 pfn4/3, cf/5,
7 8 13 atom_compat/3,
14 axiom_lhs_to_rhs/3,
15 b_d_p/2,
16 boxRule/3,
17 cf_to_flattened_clauses/4,
18 cf_to_flattened_clauses_0/4,
19 cirRule/3,
20 clausify/4,
21 clean_repeats_d/2,
22 cnf/3,
23 cnf1/3,
24 correct_boxlog/4,
25 correct_boxlog_0/4,
26 correct_cls/3,
27 correct_cls0/3,
28 corrected_modal/3,
29 corrected_modal0/3,
30 corrected_modal_recurse/3,
31 corrected_modal_recurse0/3,
32 ct_op/1,
33 delete_sublits/3,
34 to_modal1/3,
35 is_skolem_setting/1,
36 demodal_sents/3,
37 diaRule/3,
38 dnf/3,
39 dnf1/3,
40 expand_cl/3,
41 flattenConjs/3,
42 flatten_clauses/2,
43 get_quantifier_isa/3,
44 inclause/6,
45 incorrect_cl/2,
46 invert_modal/3,
47 is_lit_atom/1,
48 is_sent_op_modality/1,
49 logical_neg/3,
50 logical_pos/3,
51 logically_matches/3,
52 make_1_cl/4,
53 make_clause_from_set/3,
54 make_clause_set/3,
55 make_clauses/3,
56 make_each/3,
57
58 modal2sent/2,
59 mpred_quf/2,
60 mpred_quf_0/2,
61 neg_op/1,
62 negate/3,
63 negate0/3,
64 negate_one/3,
65 negate_one_maybe/3,
66 nnf/3,
67 nnf/5,
68
69
70 nonegate/3,
71 nonvar_unify/2,
72 notin/2,
73 nowrap_one/3,
74 pfn4/3,
75 pfn4/4,
76 putin/3,
77 removeQ/3,
78 removeQ/4,
79 removeQ_LC/4,
80 removes_literal/2,
81
82 share_scopes/2,
83 simplify_atom/2,
84 simplify_cheap/2,
85 simplify_cheap_must/2,
86
87 88 nnf_args/8,
89 third_order/1,
90 to_poss/3,
91 to_regular_cl/4,
92 unbuiltin_negate/3,
93 unbuiltin_negate/4,
94 until_op/1,
95 variants_are_equal/3
96 ]).
192
193
194:- include(library('logicmoo/common_logic/common_header.pi')). 198
200:- set_how_virtualize_file(bodies). 201
202
203:- include(common_logic_convert). 204
206
208:-
209 op(1150,fx,(was_dynamic)),
210 op(1150,fx,(was_multifile)),
211 op(1150,fy,(was_module_transparent)),
212 op(1150,fx,(was_export)). 213
214
215:-ain(baseKB:predicateConventionMt(mud_test,baseKB)). 216
218
219
220:- multifile((
221 baseKB:feature_test/0,
222 baseKB:regression_test/0,
223 baseKB:sanity_test/0)). 224:- dynamic((
225 baseKB:feature_test/0,
226 baseKB:regression_test/0,
227 baseKB:sanity_test/0)). 228:- multifile((
229 baseKB:feature_test/1,
230 baseKB:regression_test/1,
231 baseKB:sanity_test/1)). 232:- dynamic((
233 baseKB:feature_test/1,
234 baseKB:regression_test/1,
235 baseKB:sanity_test/1)). 236
238
239
241
242:- dynamic user:file_search_path/2. 243:- multifile user:file_search_path/2. 244:- prolog_load_context(source,File),file_directory_name(File,Dir),directory_file_path(_,Short,Dir),asserta_if_new(user:file_search_path(Short,Dir)). 245
246
247:- system:((
248 op(1199,fx,('==>')),
249 op(1190,xfx,('::::')),
250 op(1180,xfx,('==>')),
251 op(1170,xfx,'<==>'),
252 op(1160,xfx,('<-')),
253 op(1150,xfx,'=>'),
254 op(1140,xfx,'<='),
255 op(1130,xfx,'<=>'),
256 op(600,yfx,'&'),
257 op(600,yfx,'v'),
258 op(350,xfx,'xor'),
259 op(300,fx,'~'),
260 op(300,fx,'-'))). 261
262
263
266
274
275
278
279:- 280 281 282 op(400, fy, baseKB:(cir) ), 283 op(1075,xfx,user:'<-'),
284
285
286 287 288 op(400,fy,cir), 289
290 op(300,fx,'-'),
291 op(300,fx,'~'),
292 op(1075,xfx,'=>'),
293 op(1075,xfx,'<-'),
294 op(1075,xfx,'<=>'),
295 op(350,xfx,'xor'),
296 op(400,yfx,'&'),
297 op(500,yfx,'v')
298 ,!. 299
300
301
302:- create_prolog_flag(logicmoo_propagation, modal,[keep(true)]). 303:- create_prolog_flag(logicmoo_modality,late,[keep(true)]). 304
305:- thread_local(t_l:using_feature/1). 306is_using_feature(Feature):- t_l:using_feature(Feature).
307
314to_poss(KB,X,poss(BDT,X)):- is_ftVar(X),share_scopes(KB,BDT),!.
315to_poss(KB,poss(BDT,X),poss(BDT,X)):-nonvar(BDT),!,share_scopes(KB,BDT),!.
316to_poss(KB,X,poss(BDT,X)):-share_scopes(KB,BDT),!.
317
319to_nesc(KB,X,nesc(BDT,X)):- \+ compound(X), share_scopes(KB,BDT),!.
320to_nesc(_KB,nesc(BDT,X),nesc(BDT,X)):-!. 321to_nesc(_KB,nesc(X),nesc(X)):-!. 322to_nesc(KB,X,nesc(BDT,X)):-share_scopes(KB,BDT),!.
323
324
325:- thread_local(t_l:current_form/1). 326
327:- style_check(+singleton).
334nnf(KB,FmlNV,NNF):-
335 must(quietly(unnumbervars_with_names((KB,FmlNV),(KB0,FmlNV0)))),
336 must( \+ contains_dvar(KB0:FmlNV0)),
337 nnf0(KB0,FmlNV0,NNF),!.
338
345nnf0(KB,Fml,NNF):-
346 copy_term(Fml,Original),
347 348 locally_tl(current_form(Original),nnf(KB,Fml,[],NNF,_)),!.
349
350:- thread_local(t_l:skolem_setting/1). 351
360is_skolem_setting_default(in_nnf_implies).
361is_skolem_setting(S):- t_l:skolem_setting(SS)->S=SS;is_skolem_setting_default(S).
372
373
380nnf_dnf(KB,Fml,DNF):-
381 locally_tl(skolem_setting(ignore),
382 (removeQ(KB,Fml,FmlUQ),
383 nnf(KB,FmlUQ,NNF),
384 dnf(KB,NNF,DNF))).
385
386
387
395get_quantifier_isa([X,Col],X,Col):-var(X),nonvar(Col).
403logically_matches(_KB,_A,_B):-!,fail.
404logically_matches(KB,A,B):-nonvar(KB),!,logically_matches(_KB,A,B).
405logically_matches(_,A,B):- (var(A);var(B)),!,A=B.
406logically_matches(KB,all(_,A),B):-!,logically_matches(KB,A,B).
407logically_matches(KB,B,all(_,A)):-!,logically_matches(KB,A,B).
408logically_matches(KB,exists(V,A),exists(V,B)):-!,logically_matches(KB,A,B).
409logically_matches(KB,[A],B):-!,logically_matches(KB,B,A).
410logically_matches(KB,A,B):- once(corrected_modal_recurse(KB,A,AM)),A\=@=AM,!,logically_matches(KB,B,AM).
411logically_matches(_,A,A).
412
413
414is_leave_alone(P):- \+ compound(P),!.
415is_leave_alone(P):- leave_as_is_logically(P),!.
416is_leave_alone(P):- functor(P,F,A),is_leave_alone_pfa(P,F,A).
417
418is_leave_alone_pfa(_,F,_):- arg(_,v((v),(&),(=>),(<=>),(all),(exists),(~)),F),!,fail.
419is_leave_alone_pfa(_,assertTemplateReln,_).
420is_leave_alone_pfa(_,skolem,_).
421is_leave_alone_pfa(_,different,_).
422is_leave_alone_pfa(_,mudEquals,2).
423
424
425
426not_contains_var(X,FmlB):- \+ contains_var(X,FmlB).
427
428split_dlog_formula(FmlAB,OP,FmlA,unused):- FmlAB=..[OP,FmlA],move_inward_sent_op(OP),!.
429split_dlog_formula(FmlAB,OP,FmlA,FmlB):- FmlAB=..[OP,FmlA,FmlB],move_inward_sent_op(OP),!.
430unsplit_dlog_formula(OP,FmlA,U,FmlAB):- U==unused, FmlAB=..[OP,FmlA].
431unsplit_dlog_formula(OP,FmlA,FmlB,FmlAB):- FmlAB=..[OP,FmlA,FmlB].
432
433move_inward_sent_op(&). move_inward_sent_op(v). move_inward_sent_op(<=>). move_inward_sent_op(=>). move_inward_sent_op(~).
434move_inward_sent_op(nesc). move_inward_sent_op(poss).
435
436
437:- discontiguous(nnf1/5). 438:- discontiguous(axiom_lhs_to_rhs/3). 439
440discovered_var(_Fml,_Slots).
441discovered_term_slots(_Fml,_Slots).
442
456nnf(KB,Lit,FreeV,LitO,N):-nonvar(LitO),!,nnf1(KB,Lit,FreeV,LitM,N),!,LitM=LitO.
457nnf(KB,Lit,FreeV,LitO,N):-var(FreeV),!,trace_or_throw(bad_nnf(KB,Lit,FreeV,LitO,N)).
458nnf(KB,Lit,FreeV,LitO,N):-
459 (nb_current('$nnf_outer',Was);Was=[]),
460 b_setval('$nnf_outer',[Lit|Was]),
461 nnf1(KB,Lit,FreeV,LitO,N),!.
462
465
467nnf1(_KB, Lit,FreeV, Lit,1):- is_ftVar(Lit),!, 468 discovered_var(Lit,FreeV).
469nnf1(_KB,Lit,_FreeV,Lit,1):- leave_as_is(Lit),!.
470nnf1(_KB,~(Lit),_FreeV,~(Lit),1):- leave_as_is(Lit),!.
471nnf1(_KB,~(Lit),FreeV,~(Lit),1):- is_ftVar(Lit),!, 472 discovered_var(Lit,FreeV).
473
474
475
476
480nnf1(KB,(Q :- P),FreeV,(Q :- PP),Paths):- nnf1(KB,P,FreeV,PP,Paths),!.
481
482nnf1(KB,(Q :- P),FreeV,Lit,N):- nnf1(KB,~(Q) => ~(ante(P)),FreeV,Lit,N).
483
484
485
487nnf1(_KB,Lit,FreeV,Lit,1):- is_list(Lit),!,discovered_term_slots(Lit,FreeV).
489
491nnf1(KB,Fin,FreeV,NNF,Paths):- corrected_modal(KB,Fin,F)-> Fin \=@= F,!,nnf1(KB,F,FreeV,NNF,Paths).
492
493
494
495
496
500
501nnf1(KB,NNF,NewVars,NNF2,Paths):-
502 nnf_ex(KB,NNF,NewVars,NNF2,Paths),!.
503
509
511nnf1(KB,~(nesc(BDT,~(F))),FreeV,BOX,Paths):- nonvar(F),!,
512 nnf1(KB,poss(BDT,F),FreeV,BOX,Paths).
513
514nnf1(KB,~(poss(BDT,~(F))),FreeV,BOX,Paths):- nonvar(F),!,
515 nnf1(KB,nesc(BDT,F),FreeV,BOX,Paths).
516
517nnf1(KB,~(nesc(BDT,F)),FreeV,BOX,Paths):- nonvar(F),!,
518 nnf1(KB,poss(BDT,~(F)),FreeV,BOX,Paths).
519
520nnf1(KB,~(poss(BDT,F)),FreeV,BOX,Paths):- nonvar(F),!,
521 nnf1(KB,nesc(BDT,~(F)),FreeV,BOX,Paths).
522
526
527nnf1(KB,nesc(BDT,F),FreeV,BOX,Paths):-
528 nnf(KB,F,FreeV,NNF,Paths), cnf(KB,NNF,CNF), boxRule(KB,nesc(BDT,CNF), BOX),!.
529
530nnf1(KB,nesc(Fin),FreeV,NNF,Paths):- !, nnf(KB,Fin,FreeV,NNF,Paths).
531nnf1(KB,nesc(_,Fin),FreeV,NNF,Paths):- !, nnf(KB,Fin,FreeV,NNF,Paths).
532
533
537
539nnf1(KB,poss(BDT,PQ),FreeV,DIA,Paths):- fail, compound(PQ),PQ = (P=>Q), !,
540 nnf1(KB,poss(BDT,P)=>Q,FreeV,DIA,Paths).
541
542nnf1(KB,poss(BDT,F),FreeV,DIA,Paths):-
543 nnf(KB,F,FreeV,NNF,Paths), dnf(KB,NNF,DNF), diaRule(KB,poss(BDT,DNF), DIA).
544
548
549nnf1(KB, ~( Fml),FreeV,NNF,Paths):- nonvar(Fml),
550 (Fml = (beliefs(BDT,~(F))) -> Fml1 = knows(BDT, ( F));
551 Fml = (knows(BDT,~(F))) -> Fml1 = beliefs(BDT, ( F))
552 ),!,
553 nnf(KB,Fml1,FreeV,NNF,Paths).
560axiom_lhs_to_rhs(_KB, poss(BDT,beliefs(A,~(F1))),~(nesc(BDT,knows(A,F1)))).
561axiom_lhs_to_rhs(_KB, all(Vs,poss(BDT,A & B)) , ~(exists(Vs,nesc(BDT,A & B)))):- is_ftVar(Vs),!.
562
564nnf1(KB,Fin,FreeV,DIA,Paths):- fail, copy_term(Fin,Fml),axiom_lhs_to_rhs(KB,F1,F2) ,
565 \+ \+ (numbervars(Fin,0,_,[attvar(bind)]),logically_matches(KB,Fin,F1)),
566 show_success(nnf,(nop(Fml),logically_matches(KB,Fin,F1))),show_call(why,nnf(KB,F2,FreeV,DIA,Paths)).
567
569
570nnf1(KB,cir(CT,F),FreeV,CIR,Paths):-
571 nnf(KB,F,FreeV,NNF,Paths),
572 cirRule(KB,cir(CT,NNF), CIR),!.
573
575:- style_check(+singleton). 576
580
581nnf1(KB,all(XL,NNF),FreeV,FmlO,Paths):- is_list(XL),
582 (get_quantifier_isa(XL,X,Col) ->
583 nnf(KB,all(X,(isa(X,Col)=>NNF)),FreeV,FmlO,Paths);
584 (XL=[X|MORE],!,
585 (MORE==[] ->
586 nnf(KB,all(X,NNF),FreeV,FmlO,Paths);
587 nnf(KB,all(X,all(MORE,NNF)),FreeV,FmlO,Paths)))).
588
592nnf1(KB,all(X,NNF),FreeV,all(X,NNF2),Paths):- is_using_feature(quants_removed_in_removeQ),!,
593 add_to_vars(X,FreeV,NewVars),
594 nnf(KB,NNF,NewVars,NNF2,Paths).
595
596
600nnf1(KB,all(X,NNF),FreeV, NNF2, Paths):- 601 add_to_vars(X,FreeV,NewVars),
602 nnf(KB,NNF,NewVars,NNF2,Paths).
603
607
610nnf1(KB,release(CT,CurrentPsi,ReleaserPhi),FreeV,NNF,Paths):-
611 share_scopes(KB,CT),!,
612 Fml1 = (ReleaserPhi => ~(CurrentPsi)),
613 nnf(KB,Fml1,FreeV,NNF,Paths).
614
615% Until: \psi holds at the current or a future position, and \phi has to hold until that position. At that position \phi does not have to hold any more
616nnf1(KB,until(CurrentPsi,DisablerPhi),FreeV,NNF,Paths):-
617 Fml1 = (CurrentPsi v (DisablerPhi => ~(CurrentPsi))),
618 nnf(KB,Fml1,FreeV,NNF,Paths).
619
621nnf1(KB,~(until(CT,Future,Current)),FreeV,NNF,Paths):-
622
623 nnf(KB, ~( Future),FreeV,NNFuture,_),
624 nnf(KB, ~( Current),FreeV,NNCurrent,_),
625 share_scopes(KB,CT),!,
626 Fml1 = v(always(NNCurrent), until(CT,NNCurrent,&(NNFuture,NNCurrent))),
627 nnf(KB,Fml1,FreeV,NNF,Paths).
628
630nnf1(KB,~(cir(CT,Future)),FreeV,NNF,Paths):-
631 nnf(KB,cir(CT,~(Future)),FreeV,NNF,Paths),!.
632
634axiom_lhs_to_rhs(KB,startsAfterEndingOf(B,A),until(CT,A,B)):- share_scopes(KB,CT),!,set_is_lit(A),set_is_lit(B),!.
635
636nnf1(KB,until(CT,A,B),FreeV,NNF,Paths):- set_is_lit(A),set_is_lit(B), share_scopes(KB,CT),!,
637 nnf(KB,A,FreeV,NNF1,Paths1),
638 nnf(KB,B,FreeV,NNF2,Paths2),
639 Paths is Paths1 + Paths2,
640 set_is_lit(NNF1),
641 set_is_lit(NNF2),
642 NNF = until(CT,NNF1, NNF2).
643
644nnf1(KB,holdsIn(TIMESPAN,TRUTH),FreeV,NNF,Paths):-
645 nnf(KB,occuring(TIMESPAN) => TRUTH,FreeV,NNF,Paths).
646
647nnf1(KB,holdsIn(TIMESPAN,TRUTH),FreeV,NNF,Paths):- nnf(KB,temporallySubsumes(TIMESPAN,TRUTH),FreeV,NNF,Paths).
648
649nnf1(KB,temporallySubsumes(TIMESPAN,TRUTH),FreeV,NNF,Paths):-
650 nnf(KB,(until(CT,TRUTH,~(TIMESPAN))&until(CT,~(TRUTH),TIMESPAN)),FreeV,NNF,Paths).
651
655
656nnf1(KB, ~( different(X , Y)),FreeV,NNF,Paths):- !, nnf(KB, ( equals(X , Y)),FreeV,NNF,Paths).
657nnf1(KB, ~( equals(X , Y)),FreeV,NNF,Paths):- !, nnf(KB, ( different(X , Y)),FreeV,NNF,Paths).
658
659nnf1(KB, ~( ~(different(X , Y))),FreeV,NNF,Paths):- !, nnf(KB, ( ~(equals(X , Y))),FreeV,NNF,Paths).
660nnf1(KB, ~( ~(equals(X , Y))),FreeV,NNF,Paths):- !, nnf(KB, ( ~(different(X , Y))),FreeV,NNF,Paths).
661
662%nnf1(KB,hasName(Entity,Name),FreeV,NNF,Paths):- nonvar(Entity),
663% nnf(KB,equals(Entity,Entity0) => hasName(Entity0,Name),FreeV,NNF,Paths).
664
665% =================================
666% Back to Normal NNF-ing
667% =================================
668
669nnf1(KB, ~( xor(X , Y)),FreeV,NNF,Paths):-
670 !,
671 nnf(KB, ((X & Y) v ( ~( X) & ~( Y))),FreeV,NNF,Paths).
672
673nnf1(KB,xor(X , Y),FreeV,NNF,Paths):-
674 !,
675 nnf(KB,((X v Y) & ( ~( X) v ~( Y))),FreeV,NNF,Paths).
676
677nnf1(KB,(C => (A & B)),FreeV,NNFO,PathsO):- is_using_feature(two_implications),!,
678 nnf(KB,A,FreeV,NNF1,Paths1),contains_no_negs(NNF1),
679 nnf(KB,B,FreeV,NNF2,Paths2),contains_no_negs(NNF2),
680 to_poss(KB,NNF1,NNF1WFFChk),to_poss(KB,NNF2,NNF2WFFChk),
681 FullNNF2 = ((NNF1WFFChk => (C => NNF2))),
682 FullNNF1 = ((NNF2WFFChk => (C => NNF1))),
683 PathsO is Paths1 * Paths2,
684 (Paths1 > Paths2 -> NNF = (FullNNF2 & FullNNF1);
685 NNF = (FullNNF1 & FullNNF2)),
686 did_use_hack(two_implications),
687 nnf(KB,NNF,FreeV,NNFO,PathsO).
688
689% not disabled
690nnf1(KB,(A & B),FreeV,NNF,Paths):- fail, nb_current('$nnf_outer',[_,Was|_]), \+ has_modals(Was),!,
691 % is_using_feature(co_mingling),!,
692 to_poss(KB,A,PA),to_poss(KB,B,PB),
693 NEWFORM = ((PB => A) & (PA => B)) ,
694 nnf(KB,NEWFORM,FreeV,NNF,Paths).
695
696nnf1(KB,(A & B),FreeV,NNF,Paths):- !,
697 nnf(KB,A,FreeV,NNF1,Paths1),
698 nnf(KB,B,FreeV,NNF2,Paths2),
699 Paths is Paths1 * Paths2,
700 (Paths1 > Paths2 -> NNF = (NNF2 & NNF1);
701 NNF = (NNF1 & NNF2)).
702
703nnf1(KB,<=>(A,B),FreeV,NNFO,Paths):- !,
704 nnf(KB,A=>B,FreeV,NNF1,Paths1),
705 nnf(KB,B=>A,FreeV,NNF2,Paths2),
706 Paths is Paths1 * Paths2,
707 (Paths1 > Paths2 -> NNF = (NNF2 & NNF1);
708 NNF = (NNF1 & NNF2)),
709 nnf(KB,NNF,FreeV,NNFO,Paths).
710
711nnf1(KB,(A v B),FreeV,NNF,Paths):-
712 nnf(KB,A,FreeV,NNF1,Paths1),
713 nnf(KB,B,FreeV,NNF2,Paths2),
714 Paths is Paths1 + Paths2,
715 (Paths1 > Paths2 -> NNF = (NNF2 v NNF1);
716 NNF = (NNF1 v NNF2)).
717
718
719nnf1(KB, ~( Fml),FreeV,NNF,Paths):- nonvar(Fml), Fml = ~( A) ,!, nnf(KB,A,FreeV,NNF,Paths).
720nnf1(KB, ~( Fml),FreeV,NNF,Paths):- nonvar(Fml),
721
722 (Fml = ( ~( A)) -> must(double_neg(KB,A,Fml1));
723 Fml = (nesc(BDT,F)) -> Fml1 = poss(BDT, ~( F));
724 Fml = (poss(BDT,F)) -> Fml1 = nesc(BDT, ~( F));
725
726 Fml = (cir(CT,F)) -> Fml1 = cir(CT, ~( F));
727 Fml = (until(CT,A,B)) ->
728 (nnf(KB, ~( A),FreeV,NNA,_), nnf(KB, ~( B),FreeV,NNB,_),Fml1 = v(always(CT,NNB), until(CT,NNB,&(NNA,NNB))));
729
730 Fml = (exists(X,F)) -> Fml1 = all(X, ~( F));
731 Fml = (quant(atleast(N),X,F)) -> Fml1 = quant(atmost(N),X,F);
732 Fml = (quant(atmost(N),X,F)) -> Fml1 = quant(atleast(N),X,F);
733
734 Fml = ((A v B)) -> Fml1 = ( ~( A) & ~( B) );
735 Fml = ((A & B)) -> Fml1 = ( ~( A) v ~( B) );
736 Fml = ('=>'(A,B)) -> Fml1 = ( A & ~( B) );
737 Fml = ('<=>'(A,B)) -> Fml1 = v(&(A, ~( B)) , &( ~( A), B) )
738 ),!,
739 must((share_scopes(KB,BDT),share_scopes(KB,CT))),!,
740 nnf(KB,Fml1,FreeV,NNF,Paths).
741
742nnf1(KB,Fml,FreeV,NNF,Paths):-
743 (Fml = '=>'(A,B) -> Fml1 = v( ~( A), B );
744 Fml = '<=>'(A,B) -> Fml1 = v(&(A, B), &( ~( A), ~( B)) );
745 Fml = '<=>'(A,B) -> Fml1 = v('=>'(A, B), '=>'(B, A) )
746 ),!, nnf(KB,Fml1,FreeV,NNF,Paths).
747
748
759
774
778nnf1(KB,Fml,FreeV,FmlO,Paths):- no_poss(Fml),
779 breakup_nnf(KB,Fml,FmlM),
780 Fml\=@=FmlM,
781 nnf(KB,FmlM,FreeV,FmlO,Paths).
782
783
785
786
790
791nnf1(_KB,mudEquals(A,B),FreeV,mudEquals(A,B),1):- is_ftVar(A), !,no_freev(FreeV).
792
793nnf1(KB, ~( Fml),FreeV,NNF,Paths):- nonvar(Fml), Fml = all(X,F), nnf(KB,exists(X, ~( F)),FreeV,NNF,Paths).
794
795nnf1(KB,Fml,FreeV,FmlO,N):-
796 compound(Fml),
797 \+ is_precond_like(Fml),
798 arg(_,Fml,Function),
799 compound(Function),
800 quietly(is_function_expr('=>',Function)),
801 802 function_to_predicate(Function,NewVar,PredifiedFunction),!,
803 subst(Fml,Function,NewVar,FmlMid),!,
804 nnf(KB,all(NewVar,(PredifiedFunction => FmlMid)),FreeV,FmlO,N).
805
806nnf1(_KB,PreCond,FreeV,PreCond,1):- is_precond_like(PreCond), !,no_freev(FreeV).
807
808
811
812nnf1(KB,Fml,FreeV,FmlO,N):- must((nonegate(KB,Fml,FmlM),nnf_lit(KB,FmlM,FreeV,FmlO,N))).
813
814nnf1(_KB,Fml,_,Fml,1):-!.
815
816
817nnf_l(KB,[FmlA],FreeVA,[NNFA],PathsA):-!,
818 nnf(KB,FmlA,FreeVA,NNFA,PathsA),!.
819nnf_l(KB,[FmlA|FmlS],FreeV,[NNFA|NNFS],Paths):-
820 nnf(KB,FmlA,FreeVA,NNFA,PathsA),
821 nnf_l(KB,FmlS,FreeVS,NNFS,PathsS),
822 append(FreeVS,FreeVA,FreeV),
823 Paths is PathsA + PathsS.
824nnf_l(_KB,[],[],[],0).
825
826
827no_poss(Fml):- sub_term(Term,Fml),compound(Term),functor(Term,poss,_),!,fail.
828no_poss(_Fml).
829
830no_freev(FreeV):- ignore(FreeV=[]).
831add_to_vars(X,FreeV,NewVars):- is_list(FreeV),!,list_to_set([X|FreeV],NewVars).
832add_to_vars(X,FreeV,NewVars):- [X|FreeV]=NewVars.
833
834nnf_lit(KB,all(X,Fml),FreeV,all(X,FmlO),N):- nonvar(Fml),!,nnf_lit(KB,Fml,FreeV,FmlO,N).
835nnf_lit(KB, ~( Fml),FreeV, ~( FmlO),N):- nonvar(Fml),!,nnf_lit(KB,Fml,FreeV,FmlO,N).
836
837nnf_lit(_KB,Fml,FreeV,Fml,1):-
functor(Fml,_,N),N>2,!,no_freev(FreeV).
838nnf_lit(KB,Fml,FreeV,FmlO,N3):-
839 Fml=..[F|ARGS],
840 nnf_args(Fml,F,1,KB,ARGS,FreeV,FARGS,N1),
841 Fml2=..[F|FARGS],
842 (Fml2 \=@= Fml ->
843 ((nnf(KB,Fml2,FreeV,FmlO,N2),N3 is (N1 + N2 -1 )));
844 must((FmlO=Fml2, N3 is N1))).
845nnf_args(_Sent,_F,_N,_KB,[],_FreeV,[],0):- !.
846
847nnf_args(Sent,F,N,KB,[A|RGS],FreeV,[FA|ARGS],N3):-
848 nop(closure_push(FA,admittedArgument(FA,N,F))),
849 850 must((nnf_arg(KB,A,FreeV,FA,N1),sanity(number(N1)))),!,
851 852 853 NPlus1 is N + 1,
854 nnf_args(Sent,F,NPlus1,KB,RGS,FreeV,ARGS,N2),
!,
855 must(N3 is (N1 + N2 -1)).
856
857
858nnf_arg(_KB,A,FreeV,A,1):- quietly(is_arg_leave_alone(A)),!,no_freev(FreeV).
859nnf_arg(KB,A,FreeV,FA,N1):- nnf(KB,A,FreeV,FA,N1).
860
861is_arg_leave_alone(A):- ground(A).
862is_arg_leave_alone(A):- is_lit_atom(A).
868is_lit_atom(IN):- leave_as_is_logically(IN),!.
869is_lit_atom(IN):- \+ is_sent_with_f(IN).
870
871is_sent_with_f(In):- is_a_sent_funct(F),subst(In,F,*,O),O \== In,!.
872
873is_a_sent_funct((&)).
874is_a_sent_funct((v)).
875is_a_sent_funct((all)).
876is_a_sent_funct((exists)).
877is_a_sent_funct((=>)).
878is_a_sent_funct((<=>)).
879is_a_sent_funct((~)).
880
881is_sent_like(XY):- \+ compound(XY),!,fail.
882is_sent_like(_ & _).
883is_sent_like(_ v _).
884is_sent_like(_ => _).
885is_sent_like(_ <=> _).
886is_sent_like(all(_ , _)).
887is_sent_like(exists(_ , _)).
889is_sent_like(~(XY)):- is_sent_like(XY).
890
891must_distribute_maybe(KB,PAB,Was,OUT):-
892 subst(PAB,Was,NewArg,NewPab),
893 functor(PAB,F,_),
894 must((arg(N,PAB,Arg),Arg==Was)),
895 copy_term(NewPab:NewArg,CNewPab:CWas),
896 CWas='$$val$$',
897 must(distribute_on(F-N,KB,
898 subst(CNewPab,CWas),Was,OUT)).
899
900:- meta_predicate distribute_on(*,*,2,?,?). 901
902distribute_on(_What,_KB,RE,XY,SAME):- \+ is_sent_like(XY),!, reconstuct(RE,XY,SAME).
903distribute_on(_What,KB,RE,XY,SAME):- compound(KB),functor(XY,F,_), cant_distrubute_on(F,KB),!,reconstuct(RE,XY,SAME).
904distribute_on(What,_KB,RE,XY,SAME):- functor(XY,F,_), cant_distrubute_on(F,What),!, reconstuct(RE,XY,SAME).
905distribute_on(What,KB,RE,((X v Y)),(RECON1 v RECON2)) :- !, distribute_on(What,KB,RE,X,RECON1), distribute_on(What,KB,RE,Y,RECON2).
906distribute_on(What,KB,RE,((X & Y)),(RECON1 & RECON2)) :- !, distribute_on(What,KB,RE,X,RECON1), distribute_on(What,KB,RE,Y,RECON2).
907distribute_on(What,KB,RE,((X => Y)),(RECON1 => RECON2)) :- ! , distribute_on(What,KB,RE,X,RECON1), distribute_on(What,KB,RE,Y,RECON2).
908distribute_on(What,KB,RE,((X <=> Y)),(RECON1 <=> RECON2)) :- ! , distribute_on(What,KB,RE,X,RECON1), distribute_on(What,KB,RE,Y,RECON2).
909distribute_on(What,KB,RE,(all(V, X)),all(V , RECON1)) :- ! , distribute_on(What,KB,RE,X,RECON1).
910distribute_on(What,KB,RE,(exists(V, X)),exists(V , RECON1)) :- ! , distribute_on(What,KB,RE,X,RECON1).
911distribute_on(What,KB,RE, ~(X) , RECON1) :- breakup_nnf(KB,~(X),Xp), ( ~(X) ) \== Xp, ! , distribute_on(What,KB,RE,Xp,RECON1).
912distribute_on(What,KB,RE, X , RECON1) :- breakup_nnf(KB, X,Xp), ( X ) \== Xp, ! , distribute_on(What,KB,RE,Xp,RECON1).
913distribute_on(_What,_KB,RE,XY,SAME):- reconstuct(RE,XY,SAME),!.
914
915:- meta_predicate reconstuct(2,?,?). 916
917reconstuct(RE,Arg,OUT):- must(call(RE,Arg,OUT)).
918
919can_distrubute_on(Sent,F-N):- !, can_distrubute_on(Sent,F,N).
920can_distrubute_on(Sent,FN):- can_distrubute_on(Sent,FN,0).
921
922cant_distrubute_on(Sent,F-N):- !, cant_distrubute_on(Sent,F,N).
923cant_distrubute_on(Sent,FN):- cant_distrubute_on(Sent,FN,0).
924
925
926can_distrubute_on(Sent,F,N):- \+ cant_distrubute_on(Sent,F,N),!,fail.
927can_distrubute_on(_Sent,_F,_A).
928
931
932cant_distrubute_on(v,release,3).
933cant_distrubute_on(&,release,2).
934
935cant_distrubute_on(v,until,2).
936cant_distrubute_on(&,until,3).
937
939cant_distrubute_on(v,knows,2).
940cant_distrubute_on(&,beliefs,2).
941
952
953
954
957
958breakup_nnf(_,Y,Y):- \+ compound(Y),!.
959breakup_nnf(_,Y,Y):- is_ftVar(Y),!.
960breakup_nnf(KB,cir(CT,(X & Y)),(cir(CT,Xp) & cir(CT,Yp))) :- ! , breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
961breakup_nnf(KB,cir(CT,X),cir(CT,Xp)) :- !, breakup_nnf(KB,X,Xp).
962
963breakup_nnf(KB,until(CT,(X & Y),Z),(U & V)) :- !, breakup_nnf(KB,until(CT,X,Z),U), breakup_nnf(KB,until(CT,Y,Z),V).
964breakup_nnf(KB,until(CT,X,(Y v Z)),(U v V)) :- !, breakup_nnf(KB,until(CT,X,Y),U), breakup_nnf(KB,until(CT,X,Z),V).
965breakup_nnf(KB,until(CT,X,Y),until(CT,Xp,Yp)) :- !, breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
966
967breakup_nnf(KB,release(CT,(X v Y),Z),(U v V)) :- !, breakup_nnf(KB,release(CT,X,Z),U), breakup_nnf(KB,release(CT,Y,Z),V).
968breakup_nnf(KB,release(CT,X,(Y & Z)),(U & V)) :- !, breakup_nnf(KB,release(CT,X,Y),U), breakup_nnf(KB,release(CT,X,Z),V).
969breakup_nnf(KB,release(CT,X,Y),release(CT,Xp,Yp)) :- !, breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
970
971
972/*
973breakup_nnf(KB,knows(Agt,(X v Y)), ~(beliefs(Agt,(~(X) & ~(Y))))) :- !,
974 breakup_nnf(KB,X,Xp),
975 breakup_nnf(KB,Y,Yp).
976
977breakup_nnf(KB,knows(AG,(~(X) v ~(Y))), ~(beliefs(AG,(U & V)))) :- !,
978 breakup_nnf(KB,X,U), breakup_nnf(KB,Y,V).
979
980*/
981
982breakup_nnf(KB,beliefs(Agt,(X & Y)),(beliefs(Agt,Xp) & beliefs(Agt,Yp))) :- ! , breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
983% wrong .. breakup_nnf(KB,knows(Agt,(X v Y)),(beliefs(Agt,Xp) v beliefs(Agt,Yp))) :- ! , breakup_nnf(KB,X,Xp),breakup_nnf(KB,Y,Yp).
984
985breakup_nnf(KB,(X & Y),(Xp & Yp)) :- breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
986breakup_nnf(KB,(X v Y),(Xp v Yp)) :- breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
987breakup_nnf(KB,~(X),~(Xp)) :- breakup_nnf(KB,X,Xp).
988breakup_nnf(KB,(X => Y),(Xp => Yp)) :- breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
989breakup_nnf(KB,(X <=> Y),(Xp <=> Yp)) :- breakup_nnf(KB,X,Xp), breakup_nnf(KB,Y,Yp).
990
991breakup_nnf(KB,PAB,OUT):- \+ is_sent_like(PAB), arg(_,PAB,XY),is_sent_like(XY),!,must(must_distribute_maybe(KB,PAB,XY,OUT)).
992breakup_nnf(KB,knows(E,P),knows(E,Q)) :- nnf(KB,P,[],Q,_), !.
993
994breakup_nnf(_KB,X,X).
995
996
997
1007
1009
1011
1013
1015
1016
1023third_order(asserted_t).
1024
1025
1027
1034boxRule(_KB,BOX, BOX):-leave_as_is_logically(BOX),!.
1035boxRule(KB,nesc(BDT,(A & B)), (BA & BB)):- nonvar(A),!, boxRule(KB,nesc(BDT,A),BA), boxRule(KB,nesc(BDT,B),BB).
1037boxRule(_KB,BOX, BOX).
1038
1039leave_as_is_logically(F):-quietly(leave_as_is_logically0(F)).
1040
1041leave_as_is_logically0(Box):- var_or_atomic(Box),!.
1042leave_as_is_logically0(_:P):-!,leave_as_is_logically0(P).
1044leave_as_is_logically0((P:-TRUE)):-!,is_true(TRUE),leave_as_is_logically0(P).
1045leave_as_is_logically0(DB):-functor(DB,F,A),leave_as_is_logically_fa(F,A),!.
1046leave_as_is_logically0(NART):-functor(NART,nartR,_),!,ground(NART).
1047
1048leave_as_is_logically0(LIST):- is_list(LIST),!, maplist(leave_as_is_logically0,LIST).
1050
1051:- kb_global(baseKB:workflow_holder_queue/1). 1052leave_as_is_logically_fa(meta_argtypes,1).
1053leave_as_is_logically_fa(skolem,_).
1054leave_as_is_logically_fa({},1).
1055leave_as_is_logically_fa(onSpawn,1).
1056leave_as_is_logically_fa(F,1):-clause_b(workflow_holder_queue(F)),!.
1057leave_as_is_logically_fa(F,A):-mpred_database_term(F,A,Type),Type\=fact(_),Type\=rule,!.
1058
1065diaRule(KB,A,B):- convertAndCall(as_dlog,diaRule(KB,A,B)).
1066diaRule(_KB,BOX, BOX):-leave_as_is_logically(BOX),!.
1067diaRule(KB,poss(BDT,(A v B)), v(DA,DB)):- !, diaRule(KB,poss(BDT,A),DA), diaRule(KB,poss(BDT,B),DB).
1070diaRule(_KB,DIA, DIA).
1071
1072
1079cirRule(KB,A,B):- convertAndCall(as_dlog,cirRule(KB,A,B)).
1080cirRule(_KB,BOX, BOX):-leave_as_is_logically(BOX),!.
1081cirRule(KB,cir(CT,(A v B)), v(DA,DB)):- !, cirRule(KB,cir(CT,A),DA), cirRule(KB,cir(CT,B),DB).
1082cirRule(KB,cir(CT,(A & B)), &(DA,DB)):- !, cirRule(KB,cir(CT,A),DA), cirRule(KB,cir(CT,B),DB).
1083cirRule(_KB,CIR, CIR).
1084
1085
1086
1093corrected_modal_recurse(_,Var,OUT):-leave_as_is_logically(Var),!,OUT=Var.
1094corrected_modal_recurse(KB, IN, OUT):- corrected_modal(KB,IN,OUTM),!,OUT=OUTM.
1095corrected_modal_recurse(KB, IN, OUTM):- corrected_modal_recurse0(KB, IN, M),!,
1096 (IN=@=M->OUT=M;corrected_modal_recurse(KB, M, OUT)),!,OUT=OUTM.
1097
1098
1105corrected_modal_recurse0(_,Var,OUT):-leave_as_is_logically(Var),!,OUT=Var.
1106corrected_modal_recurse0(KB, IN,FOO):- is_list(IN),!, must_maplist_det(corrected_modal_recurse(KB), IN,FOO ),!.
1107corrected_modal_recurse0(KB, H,FOO):- compound(H),!,H=..[F|ARGS], must_maplist_det(corrected_modal_recurse(KB), ARGS,FOOL ),!,FOO=..[F|FOOL].
1108corrected_modal_recurse0(_, INOUT, INOUT):- !.
1109
1110
1111
1112
1119corrected_modal(KB,I,O):- expandQuants(KB,I,M)->I\=@=M,rejiggle_quants(KB,M,O).
1120corrected_modal(KB,IN,OUTM):-
1121 corrected_modal0(KB,IN,M),!,must(corrected_modal_recurse0(KB,M,OUT)),!,OUT=OUTM.
1122
1123
1124
1131corrected_modal0(_,Var,_):-leave_as_is_logically(Var),!,fail.
1132corrected_modal0(_,nesc(BDT,F),nesc(BDT,F)):-!.
1133corrected_modal0(_,poss(BDT,F),poss(BDT,F)):-!.
1134corrected_modal0(_,until(CT,A,B),until(CT,A,B)):-!.
1135corrected_modal0(_,cir(CT,F),cir(CT,F)):-!.
1136corrected_modal0(KB,BF,nesc(b_d(KB,B,D),F)):- BF=..[B,F],b_d_p(B,D).
1137corrected_modal0(KB,BF,poss(b_d(KB,B,D),F)):- BF=..[D,F],b_d_p(B,D).
1138corrected_modal0(KB,CF,cir(ct(KB,CT),F)):- CF=..[CT,F],ct_op(CT).
1139corrected_modal0(KB,CF,until(ct(KB,CT),A,B)):- CF=..[CT,A,B],until_op(CT).
1140corrected_modal0(_,BF,nesc(b_d(KB,B,D),F)):- BF=..[B,KB,F],b_d_p(B,D).
1141corrected_modal0(_,BF,poss(b_d(KB,B,D),F)):- BF=..[D,KB,F],b_d_p(B,D).
1142corrected_modal0(_,CF,cir(ct(KB,CT),F)):- CF=..[CT,KB,F],ct_op(CT).
1143corrected_modal0(KB,CF,until(ct(KB,CT),A,B)):- CF=..[CT,KB,A,B],until_op(CT).
1144
1145
1146
1153share_scopes(KB,BDT):-compound(BDT),ignore(arg(1,BDT,KB)),!.
1154share_scopes(KB,ENV):-ignore(KB=ENV),!.
1155
1165
1172until_op(until).
1173
1174
1181ct_op(cir).
1182ct_op(nextly).
1183
1184
1187
1188
1195neg_op(not).
1196neg_op(~).
1197neg_op(~).
1198neg_op(-).
1199neg_op('\\+').
1200
1201
1208b_d_p(nesc,poss).
1209b_d_p(box,dia).
1211b_d_p(always,eventually).
1212b_d_p_1(sometimes,always).
1213
1215
1220
1227cnf(KB,A,B):- convertAndCall(as_dlog,cnf(KB,A,B)).
1228cnf(_KB,AS_IS, AS_IS):-leave_as_is_logically(AS_IS),!.
1229cnf(KB,&(P,Q), &(P1,Q1)):- !, cnf(KB,P, P1), cnf(KB,Q, Q1).
1230cnf(KB,v(P,Q), CNF):- !, cnf(KB,P, P1), cnf(KB,Q, Q1), cnf1(KB, v(P1,Q1), CNF ).
1231cnf(_KB,CNF, CNF).
1232
1233
1240cnf1(_KB,AS_IS, AS_IS):-leave_as_is_logically(AS_IS),!.
1241cnf1(KB, v(LEFT, R), &(P1,Q1) ):- nonvar_unify(LEFT , &(P,Q)), !, cnf1(KB, v(P,R), P1), cnf1(KB, v(Q,R), Q1).
1242cnf1(KB, v(P, RIGHT), &(P1,Q1) ):- nonvar_unify(RIGHT , &(Q,R)), !, cnf1(KB, v(P,Q), P1), cnf1(KB, v(P,R), Q1).
1243cnf1(_KB, CNF, CNF).
1244
1245
1252nonvar_unify(NONVAR,UNIFY):- \+ leave_as_is_logically(NONVAR), NONVAR=UNIFY.
1253
1258
1265dnf(KB,A,B):- convertAndCall(as_dlog,dnf(KB,A,B)).
1266dnf(_KB,AS_IS, AS_IS):-leave_as_is_logically(AS_IS),!.
1267dnf(KB, v(P,Q), v(P1,Q1) ):- !, dnf(KB,P, P1), dnf(KB,Q, Q1).
1268dnf(KB, &(P,Q), DNF):- !, dnf(KB,P, P1), dnf(KB,Q, Q1), dnf1(KB,&(P1,Q1), DNF).
1269dnf(_KB,DNF, DNF).
1270
1271
1278dnf1(KB,&(P, v(Q,R)), v(P1,Q1) ):- !, dnf1(KB,&(P,Q), P1), dnf1(KB,&(P,R), Q1).
1279dnf1(KB,&(v(P,Q), R), v(P1,Q1) ):- !, dnf1(KB,&(P,R), P1), dnf1(KB,&(Q,R), Q1).
1280dnf1(_KB,DNF, DNF ).
1281
1282
1283
1290simplify_cheap(IN,OUT):-nonvar(OUT),!,simplify_cheap(IN,M),!,OUT=M.
1291simplify_cheap(IN,IN):- leave_as_is_logically(IN),!.
1292simplify_cheap(IN,IN):- var_or_atomic(IN),!.
1295
1296simplify_cheap( ~( poss(BDT, ~( F))), OUT):-nonvar(F),!, simplify_cheap_must(nesc(BDT,F),OUT).
1297simplify_cheap( ~( nesc(BDT, ~( F))), OUT):-nonvar(F),!, simplify_cheap_must(poss(BDT,F),OUT).
1298simplify_cheap( ~( poss(BDT, ( F))), OUT):-nonvar(F),!, simplify_cheap_must(nesc(BDT,~(F)),OUT).
1299simplify_cheap( ~( nesc(BDT, ( F))), OUT):-nonvar(F),!, simplify_cheap_must(poss(BDT,~(F)),OUT).
1300simplify_cheap(poss(BDT,IN),OUT):- var_or_atomic(IN),!,poss(BDT,IN)=OUT.
1301simplify_cheap(nesc(BDT,IN),OUT):- var_or_atomic(IN),!,nesc(BDT,IN)=OUT.
1302
1303simplify_cheap(poss(BDT,nesc(BDT,IN)),OUT):- simplify_cheap_must(poss(BDT,IN),OUT).
1304simplify_cheap(poss(BDT,poss(BDT,IN)),OUT):- simplify_cheap_must(poss(BDT,IN),OUT).
1305simplify_cheap(nesc(BDT,poss(BDT,IN)),OUT):- simplify_cheap_must(poss(BDT,IN),OUT).
1306simplify_cheap(nesc(BDT,nesc(BDT,IN)),OUT):- simplify_cheap_must(nesc(BDT,IN),OUT).
1313simplify_cheap(INOUT,INOUT).
1314
1321simplify_cheap_must(IN,IN):- var_or_atomic(IN),!.
1322simplify_cheap_must(IN,IN):- leave_as_is_logically(IN),!.
1323simplify_cheap_must(IN,OUT):- simplify_cheap(IN,OUT),!.
1324simplify_cheap_must(IN,IN).
1325
1326
1330
1332
1333
1334
1341pfn4(KB, F,PNF):- pfn4(KB,F,[],PNF),!.
1342
1344
1345
1352pfn4(A,B,C,D):- convertAndCall(as_dlog,pfn4(A,B,C,D)),!.
1353
1354pfn4(_,Var,_ ,Var):- leave_as_is_logically(Var),!.
1355
1356pfn4(_, [], _, []):- !.
1357
1358pfn4(KB, IN, _, OUT):- is_list(IN),!, must_maplist_det(pfn4(KB),IN,OUT).
1359
1362
1363pfn4(KB, nesc(BDT,F),Vs, nesc(BDT,PNF)):- !, pfn4(KB,F,Vs, PNF),!.
1364
1365pfn4(KB, poss(BDT,F),Vs, poss(BDT,PNF)):- !, pfn4(KB,F,Vs, PNF),!.
1366
1367pfn4(KB, all(X,F),Vs, all(X,PNF)):- list_to_set([X|Vs],VVs), !, pfn4(KB,F, VVs, PNF),!.
1368
1369pfn4(KB, exists(X,F),Vs,exists(X,PNF)):- list_to_set([X|Vs],VVs), !, pfn4(KB,F, VVs, PNF),!.
1370
1371pfn4(KB, (&(exists(X,A) , B)),Vs, exists(Y,PNF)):- !, copy_term((X,A,Vs),(Y,Ay,Vs)), pfn4(KB,&(Ay,B),[Y|Vs], PNF),!.
1372
1373pfn4(KB, ( v(exists(X,A)), B),Vs, exists(Y,PNF)):- !, copy_term((X+A+Vs),(Y+Ay+Vs)), pfn4(KB,(v(Ay,B)),[Y|Vs], PNF).!.
1374
1375pfn4(KB, &(all(X,A), B),Vs, all(Y,PNF)):- !, copy_term((X,A,Vs),(Y,Ay,Vs)), pfn4(KB,&(Ay , B),[Y|Vs], PNF),!.
1376
1377pfn4(KB, v(all(X,A), B),Vs, all(Y,PNF)):- !, copy_term((X,A,Vs),(Y,Ay,Vs)), pfn4(KB,v(Ay,B),[Y|Vs], PNF),!.
1378
1379pfn4(KB, &(A,exists(X,B)),Vs, exists(Y,PNF)):- !, copy_term((X,B,Vs),(Y,By,Vs)),
1380 pfn4(KB,&(A, By),[Y|Vs], PNF),!.
1381pfn4(KB, v(A,exists(X,B)),Vs, exists(Y,PNF)):- !, copy_term((X,B,Vs),(Y,By,Vs)),
1382 pfn4(KB,v(A,By),[Y|Vs], PNF),!.
1383pfn4(KB, &(A,all(X,B)),Vs, all(Y,PNF)):- !, copy_term((X,B,Vs),(Y,By,Vs)),
1384 pfn4(KB,&(A,By),[Y|Vs], PNF),!.
1385pfn4(KB, v(A,all(X,B)),Vs, all(Y,PNF)):- !, copy_term((X,B,Vs),(Y,By,Vs)),
1386 pfn4(KB,v(A,By),[Y|Vs], PNF),!.
1387
1388pfn4(KB, &(A, B),Vs, PNF ):- pfn4(KB,A,Vs,Ap), pfn4(KB,B,Vs,Bp),
1389 (A\=Ap; B\=Bp), pfn4(KB,&(Ap,Bp),Vs,PNF),!.
1390
1391pfn4(KB, v(A, B),Vs, PNF ):- pfn4(KB,A,Vs,Ap), pfn4(KB,B,Vs,Bp),
1392 (A\=Ap; B\=Bp), pfn4(KB,v(Ap,Bp),Vs,PNF),!.
1393
1394
1395pfn4(KB, [A|B], Vs, PNF ):- !, pfn4(KB,A,Vs,Ap), pfn4(KB,B,Vs,Bp),
1396 (A\=Ap; B\=Bp), pfn4(KB,[Ap|Bp],Vs,PNF),!.
1397
1398
1400pfn4(KB, H,Vars,FOO ):- fail, compound(H),H=..[F|ARGS], is_sentence_functor(F), !, pfn4(KB, [F|ARGS],Vars,FOOL ),FOO=..FOOL.
1401
1402pfn4(_KB, PNF, _, PNF ).
1403
1404
1405:- meta_predicate if_debugging2(*,0). 1407if_debugging2(_,G):- call(G).
1410
1414
1423cf(_Why,KB,_Original,PNF, FlattenedOUT):- fail,
1424 check_kif_varnames(PNF),
1425 removeQ(KB,PNF,[], UnQ),
1426 cnf(KB,UnQ,CNF0),!,
1427 nnf(KB,CNF0,[],CNF,_),
1428 as_prolog_hook(CNF,PROLOG),
1429 tlog_nnf(PROLOG,even,RULIFY),
1430 rulify(constraint,RULIFY,FlattenedOUT),!.
1431
1432cf(Why,KB,_Original,PNF, FlattenedOUT):-
1433 must_det_l((
1434 check_kif_varnames(PNF),
1435 removeQ(KB,PNF,[], UnQ),
1436 cnf(KB,UnQ,CNF0),!,
1437 nnf(KB,CNF0,[],CNF,_),
1438 1439 call(( conjuncts_to_list_det(CNF,Conj), make_clause_set([infer_by(Why)],Conj,EachClause),
1440 sanity(is_list(EachClause)),
1441 must_maplist_det(correct_cls(KB),EachClause,SOO),
1442 expand_cl(KB,SOO,SOOO))),
1443 predsort(sort_by_pred_class,SOOO,SET),
1444 cf_to_flattened_clauses(KB,Why,SET,Flattened),
1445 list_to_set(Flattened,FlattenedM),!,
1446 correct_boxlog(FlattenedM,KB,Why,FlattenedOOO),
1447 demodal_clauses(KB,FlattenedOOO,FlattenedO),
1448 defunctionalize_each(FlattenedO,FlattenedOUT),
1449 nop((((pfc_for_print_left(FlattenedOOO,PrintPFC),wdmsg(boxlog:-PrintPFC),
1450 maybe_notrace(boxlog_to_pfc(FlattenedO,PFCPreview)),
1451 pfc_for_print_right(PFCPreview,PrintPFCPreview),wdmsg(preview:-PrintPFCPreview))),!,
1452 extract_conditions(PFCPreview,Conds), dmsg(conds= (Conds=>PFCPreview)))))).
1453
1454check_kif_varnames(KIF):-check_varnames(KIF),fail.
1455check_kif_varnames(KIF):-ground(KIF),!.
1457check_kif_varnames(_KIF):-!.
1458
1459
1460
1461conjuncts_to_list_det(I,O):- conjuncts_to_list(I,O),!.
1462list_to_conjuncts_det(C,I,O):- list_to_conjuncts(C,I,O),!.
1463list_to_conjuncts_det(I,O):- list_to_conjuncts(I,O),!.
1464
1465%=
1466
1467%% clean_repeats_d( ?PTTP, ?PTTP) is det.
1468%
1469% Clean Repeats (debug).
1470%
1471clean_repeats_d((PTT,P0),PTTP):-!, conjuncts_to_list_det((PTT,P0),DLIST),list_to_set(DLIST,DSET),must_maplist_det(clean_repeats_d,DSET,CSET),list_to_conjuncts_det((,),CSET,PTTP),!.
1472clean_repeats_d((PTT;P0),PTTP):-!, disjuncts_to_list((PTT;P0),DLIST),list_to_set(DLIST,DSET),must_maplist_det(clean_repeats_d,DSET,CSET),list_to_conjuncts_det((;),CSET,PTTP),!.
1473clean_repeats_d(PTTP,PTTP).
1474
1475
1476
1484invert_modal(_KB,nesc(BD,A),poss(BD,A)):-set_is_lit(A),!.
1485invert_modal(_KB,poss(BD,A),nesc(BD,A)):-set_is_lit(A),!.
1486invert_modal(KB,A,OUT):- must(adjust_kif0(KB,poss(A),OUT)).
1487
1490
1491
1492
1494double_neg(KB,I,O):- invert_modal(KB,I,O)->I\=O,!.
1495double_neg(_,IO,IO):-!.
1498
1499
1506removeQ(KB, F, HH):- removeQ(KB, F, _, RQ0),!,RQ0=HH.
1507
1509
1510
1517removeQ_LC(KB, MID,FreeV,OUT):-loop_check(removeQ(KB, MID,FreeV,OUT)).
1518
1519
1526removeQ(_,Var,_ ,Var):- leave_as_is_logically(Var),!.
1527
1529removeQ(KB, IN,FreeV,OUT):- once(simplify_cheap(IN,MID)), IN\=@=MID, removeQ_LC(KB, MID,FreeV,OUT),!.
1530
1531removeQ(KB, ~( NN),Vars, XF):- nonvar(NN),NN= ~( F), invert_modal(KB,F,FI),!, removeQ(KB, FI,Vars, XF) .
1532removeQ(KB, all(X,F),Vars, HH):- !, removeQ(KB,F,[X|Vars], RQ0),RQ0=HH.
1533
1541
1544
1545removeQ(KB, exists(X,F),Vars, HH):- is_skolem_setting(removeQ),!,wdmsg(removeQ(skolemizing(exists(X,F)))),
1546 mk_skolem(KB,F,X,Vars,Fsk),
1547 removeQ(KB,Fsk,Vars, HH).
1548
1549removeQ(KB, exists(X,F),Vars, HH):- must(removeQ(KB,F,[X|Vars], RQ0)),RQ0=HH.
1550
1551removeQ(KB, ':-'(H,B), Vars, ':-'(HH,BB ) ):- !, removeQ(KB,H, Vars, HH ),removeQ(KB,B, Vars, BB).
1552removeQ(KB, cl(H,B), _, O ):- !,correct_cls(KB,cl(H,B),O).
1553removeQ(KB, [ H|B ],Vars, [ HH|BB ] ):- !,removeQ(KB,H, Vars, HH ),removeQ(KB,B, Vars, BB).
1554
1556
1558removeQ(KB, H, Vars,HH ):- H = ~( _), once(nnf(KB,H,MM)),H\=@=MM, removeQ_LC(KB, MM, Vars, HH ).
1559
1560removeQ(KB, H, Vars, HH ):- convertAndCall(as_dlog,removeQ(KB,H, Vars, HH )).
1561
1562removeQ(KB, H,Vars,HH ):- compound(H),H=..[F|ARGS],!,removeQ(KB, ARGS,Vars,ARGSO ),HH=..[F|ARGSO].
1563
1564removeQ(KB, F,Vars,OUT ):- nnf(KB,F,Vars,F0,_),(F0 =@=F -> F0=OUT; removeQ(KB, F0,Vars,OUT )),!.
1565
1566
1567
1568
1569
1576nowrap_one(_,[One],One).
1577nowrap_one(Wrap,MORE,OUT):- OUT=..[Wrap,MORE].
1578
1579
1580
1587demodal_sents(KB,I,O):- must(to_modal1(KB,I,M)),must(modal2sent(M,O)).
1588
1589
1598
1599to_modal1(KB,Var, NonVar):- nonvar(NonVar),!,to_modal1(KB,Var, NewVar),!, NewVar=NonVar.
1600
1601to_modal1(_KB,Var, Var):- quietly(var_or_atomic(Var)),!.
1602
1603to_modal1(KB,[H|T],[HH|TT]):- !, to_modal1(KB,H,HH),to_modal1(KB,T,TT).
1604
1605to_modal1(KB, nesc(b_d(KB2,X,_),F), HH):- atom(X),KB\==KB2,XF =..[X,KB2,F],!,to_modal1(KB2,XF, HH).
1606to_modal1(KB, poss(b_d(KB2,_,X),F), HH):- atom(X),KB\==KB2,XF =..[X,KB2,F],!,to_modal1(KB2,XF, HH).
1607
1608to_modal1(KB, nesc(b_d(KB,X,_),F), HH):- atom(X), XF =..[X,F], !,to_modal1(KB,XF, HH).
1609to_modal1(KB, poss(b_d(KB,_,X),F), HH):- atom(X), XF =..[X,F], !,to_modal1(KB,XF, HH).
1610
1611to_modal1(KB, -XF, ~(HH)):- !,to_modal1(KB,XF, HH).
1612
1613to_modal1(KB, nesc(_,F), HH):- XF =..[nesc,F], !,to_modal1(KB,XF, HH).
1614to_modal1(KB, poss(_,F), HH):- XF =..[poss,F], !,to_modal1(KB,XF, HH).
1615
1616to_modal1(KB,H,HH ):- H=..[F|ARGS],!,must_maplist_det(to_modal1(KB),ARGS,ARGSO),!,HH=..[F|ARGSO].
1617
1618
1625is_sent_op_modality(not).
1626is_sent_op_modality(poss).
1627is_sent_op_modality(nesc).
1628
1629has_modals(P):- quietly((sub_term(A,P),compound(A),(functor(A,poss,_);functor(A,nesc,_)))),!.
1630
1637 1638atom_compat(F,HF,HHF):- fail,F\=HF, is_sent_op_modality(F),is_sent_op_modality(HF), format(atom(HHF),'~w_~w',[F,HF]).
1639
1640remove_unused_clauses([],[]):- !.
1641remove_unused_clauses([Unused|FlattenedO4],FlattenedO):-
1642 unused_clause(Unused) -> remove_unused_clauses(FlattenedO4,FlattenedO);
1643 (remove_unused_clauses(FlattenedO4,FlattenedM),FlattenedO=[Unused|FlattenedM]).
1644
1645unusual_body :- clause_b(feature_setting(use_unusual_body,true)),!,dmsg(used(unusual_body)).
1646unusual_body :- dmsg(skipped(unusual_body)),!,fail.
1647
1648unused_clause('$unused'(C):-_):-nonvar(C),!.
1650unused_clause(naf(C):- ~(_)):-nonvar(C),!.
1651
1652
1653poss_or_skolem(Var):- \+ compound(Var),!,fail.
1654poss_or_skolem(poss(_)).
1655poss_or_skolem(dif_objs(_,_)).
1656poss_or_skolem(nesc(X)):-!,poss_or_skolem(X).
1657poss_or_skolem(falsify(X)):-!,poss_or_skolem(X).
1659poss_or_skolem(skolem(_,_)).
1661
1665
1666disjoin(A,B,C) :-
1667 A == true ->
1668 C = true;
1669 B == true ->
1670 C = true;
1671 A == false ->
1672 C = B;
1673 B == false ->
1674 C = A;
1675 1676 C = (A ; B).
1677
1678
1679pos_or_isa(isa(_,_)).
1680pos_or_isa(poss(_)).
1681
1682pred_of(Head, Head):- is_ftVar(Head),!.
1683pred_of(~(Head), Head).
1684pred_of(Head, Head).
1685
1686
1687reverse_conj((A,B),Body):- !, reverse_conj(B,RB),conjoin(RB,A,Body).
1688reverse_conj(Body,Body).
1689
1690
1697modal2sent(Var, Var):- !.
1698modal2sent(Var, Var):- quietly(var_or_atomic(Var)),!.
1700modal2sent([H|T],[HH|TT]):- !, must(( modal2sent(H,HH),modal2sent(T,TT))),!.
1701modal2sent(poss([infer_by(_)],G), \+ ~(G)):- G \= ~(_).
1702modal2sent(nesc([infer_by(_)],G),G):- G \= ~(_).
1705modal2sent(H,HH ):- H=..[F|ARGS],!,must_maplist_det(modal2sent,ARGS,ARGSO),!,HH=..[F|ARGSO].
1706
1707
1708var_or_atomic(Var):- is_ftVar(Var),!.
1709var_or_atomic([]):-!.
1710var_or_atomic(Var):- atomic(Var),!.
1711
1718clausify(KB, &(P,Q), C1, C2 ):-
1719 !,
1720 clausify(KB, P, C1, C3 ),
1721 clausify(KB, Q, C3, C2 ).
1722clausify(KB, P, [cl(A,B)|Cs], Cs ):-
1723 inclause(KB, P, A, [], B, [] ),
1724 !.
1725clausify(_KB, _, C, C ).
1726
1727
1734inclause(KB, v(P,Q), A, A1, B, B1 ):-
1735 !,
1736 inclause(KB, P, A2, A1, B2, B1 ),
1737 inclause(KB, Q, A, A2, B, B2 ).
1738inclause(KB, ~( PP) , A, A, B1, B ):-
1739 negate(KB, ~( PP),P),
1740 !,
1741 notin(P, A ),
1742 putin(P, B, B1 ).
1743inclause(_KB, P, A1, A, B, B ):-
1744 !,
1745 notin(P, B ),
1746 putin(P, A, A1 ).
1747
1748
1755notin(X,[Y|_]):- X==Y, !, fail.
1756notin(X,[_|Y]):- !,notin(X,Y).
1757notin(_,[]).
1758
1759
1766putin(X,[], [X] ):- !.
1767putin(X,[Y|L],[Y|L] ):- X == Y,!.
1768putin(X,[Y|L],[Y|L1]):- putin(X,L,L1).
1769
1770
1777simplify_atom(H,SH):-simplify_cheap(H,SH),!.
1778simplify_atom(H,H).
1779
1780
1781%=
1782
1783%% to_regular_cl( ?KB, ?H1, ?Has, ?H1) is det.
1784%
1785% Converted To Regular Clause.
1786%
1787to_regular_cl(KB,[(H1 & H2)],[Has],[cl([H1],H1P),cl([H2],H2P)]):- cnf(KB,Has,HasC), append([HasC],[poss(H2)],H1P), append([HasC],[poss(H1)],H2P),!.
1788to_regular_cl(_KB,[(H1 & H2)],Has,[cl([H1],H1P),cl([H2],H2P)]):- append(Has,[poss(H2)],H1P), append(Has,[poss(H1)],H2P),!.
1789to_regular_cl(_KB,[H],[],[cl([SH],[])]):-is_lit_atom(H),simplify_atom(H,SH).
1790to_regular_cl(_KB,HL,BL,[cl(HL,BL)]).
1791
1792
1793
1800expand_cl(_KB,[],[]):-!.
1801expand_cl(KB,[cl(H,B)|O],OOut):-
1802 to_regular_cl(KB,H,B,More),!,
1803 expand_cl(KB,O,OO),
1804 append(More,OO,OOut).
1805
1806
1813make_clause_set(_Extras ,[],[]).
1814make_clause_set(Extras,[CJ|Conj],CLAUSES):-
1815 make_clauses(Extras,CJ,CLS),
1816 make_clause_set(Extras,Conj,CLAUS),
1817 append(CLS,CLAUS,CLAUSES).
1818
1820
1827make_clauses(Extras,CJ,OOut):- disjuncts_to_list(CJ,Conj),make_clause_from_set(Extras,Conj,OOut).
1828
1829
1836negate_one_maybe(Extras,One,Z):-negate_one(Extras,One,Z).
1837
1838
1845make_clause_from_set(Extras,Conj,Out):- findall(E,make_each(Extras,Conj,E),Out).
1846
1847
1854make_each(Extras,Conj,E):- member(One,Conj), make_1_cl(Extras,One,Conj,E).
1855
1856
1863make_1_cl(Extras,One,Conj,cl([One],NewBodyListO)):-
1864 negate_one_maybe(Extras,One,NHead),!,
1865 One\={_}, NHead\={_},
1866 delete_eq(Conj,One,Rest0),delete_eq(Rest0,NHead,Rest),
1867 must_maplist_det(negate_one_maybe(Extras),Rest,NewBodyList),!,
1868 flattenConjs(Extras,NewBodyList,NewBodyListM),
1869 Pred= baseKB:as_prolog_hook, must_maplist_det(Pred,NewBodyListM,NewBodyListO).
1870
1871
1878flattenConjs(_Extras,I,O):- conjuncts_to_list_det(I,M),must_maplist_det(conjuncts_to_list_det,M,L),flatten(L,O).
1879
1880
1881:- was_export(logical_pos/3). 1882:- was_export(logical_neg/3). 1883
1890logical_neg(KB,Wff,WffO):-
1891 must(nonegate(KB,Wff,Wff1)),nnf(KB, ~( Wff1),Wff2),must(nonegate(KB,Wff2,WffO)),!.
1892
1899logical_pos(KB,Wff,WffO):-
1900 must(nonegate(KB,Wff,Wff1)),nnf(KB,Wff1,Wff2),must(nonegate(KB,Wff2,WffO)),!.
1901
1902
1903
1910negate_one(KB,Wff,WffO):- logical_neg(KB,Wff,WffO).
1911
1912
1913
1920negate(KB,X,Z):- must(defunctionalize(X,Y)), must_det(negate0(KB,Y,Z)).
1921
1928negate0(_, ~( X),X).
1929negate0(_,X, ~( X)).
1930
1931
1932
1933
1940mpred_quf(In,Out):- transitive(mpred_quf_0,In,Out).
1941
1942
1949mpred_quf_0(InOut,InOut):- not_ftCompound(InOut),!.
1951mpred_quf_0(In,In).
1952
1953:- was_export(nonegate/3). 1954
1961nonegate(_KB,IO,IO):-!.
1962nonegate(KB,List,OutZ):- is_list(List),must_maplist_det(nonegate(KB),List,OutZ),!.
1963nonegate(KB,Fml,OutZ):- simplify_cheap(Fml,Fml2)-> Fml \=@= Fml2,nonegate(KB,Fml2,OutZ),!.
1964nonegate(KB,Fml,OutZ):- must((unbuiltin_negate(KB,Fml,Out),!,defunctionalize(Out,OutY),!,must(mpred_quf(OutY,OutZ)))),!.
1965
1966
1973unbuiltin_negate(_Neg,_, Fml,Fml):- is_ftVar(Fml),!.
1974unbuiltin_negate(_Neg,_, Fml,Out):- get_functor(Fml,F,A),find_and_call(pttp_builtin(F,A)),!,must(Out=Fml).
1975
1982unbuiltin_negate(_KB,Fml,Out):- once(negate(KB,Fml,Z)),negate(KB,Z,Out),!.
1983
1984
1985
2014
2015
2017
2018
2019
2026removes_literal(true_t(X),possible_t(X)).
2027removes_literal(true_t(X,Y),possible_t(X,Y)).
2028removes_literal(true_t(X,Y,Z),possible_t(X,Y,Z)).
2029removes_literal(true_t(X,Y,Z,A),possible_t(X,Y,Z,A)).
2030
2031removes_literal(not_true_t(X),possible_t(X)).
2032removes_literal(not_true_t(X,Y),possible_t(X,Y)).
2033removes_literal(not_true_t(X,Y,Z),possible_t(X,Y,Z)).
2034removes_literal(not_true_t(X,Y,Z,A),possible_t(X,Y,Z,A)).
2035
2036
2037
2038
2045delete_sublits(H0,B,HH):- delete_eq(H0,B,H1),delete_eq(H1,B,H2),delete_eq(H2,B,HH),!.
2046
2048
2049
2050
2057flatten_clauses([H|T],HHTT):-!,flatten_clauses(H,HH),flatten_clauses(T,TT),append(HH,TT,HHTT).
2058flatten_clauses(poss(~(~(H))),poss(HH)):- !,flatten_clauses(H,HH),!.
2059flatten_clauses(nesc(~(~(H))),HH):- !,flatten_clauses(H,HH),!.
2060flatten_clauses((H,T),HHTT):-!,flatten_clauses(H,HH),flatten_clauses(T,TT),append(HH,TT,HHTT).
2061flatten_clauses([H],[H]):-!.
2062
2063
2070correct_cls(KB,H,HH):-loop_check(correct_cls0(KB,H,HH),H=HH),!.
2071
2072
2079correct_cls0(_KB,CL0,CL0):- is_ftVar(CL0),!.
2080correct_cls0(KB,CL0,CL1):- is_list(CL0),!,must_maplist_det(correct_cls(KB),CL0,CL1).
2081correct_cls0(KB,(H,T),HHTT):-!,correct_cls(KB,H,HH),correct_cls(KB,T,TT),append(HH,TT,HHTT).
2082correct_cls0(KB,(H:-B),O):-!,conjuncts_to_list_det(H,HH),conjuncts_to_list_det(B,BB),correct_cls0(KB,cl(HH,BB),O).
2083
2084correct_cls0(KB,CL,O):- demodal_sents(KB,CL,CLM),CL\=@=CLM,!,correct_cls(KB,CLM,O).
2085correct_cls0(KB,cl(H,B),O):-flatten_clauses(B,BB),B\=@=BB,correct_cls0(KB,cl(H,BB),O).
2086correct_cls0(KB,cl(H,B),O):-removeQ(KB,H,HH),removeQ(KB,B,BB),(H\=@=HH ; B\=@=BB),!, correct_cls(KB,cl(HH,BB),O).
2087
2088correct_cls0(KB,cl(H,B),O):- member(E,B),removes_literal(E,R),delete_sublits(B,R,BB),BB\=@=B,!,correct_cls(KB,cl(H,BB),O).
2089
2090
2091
2092correct_cls0(KB,cl(H,B),O):- list_to_set(H,HH),HH\=@=H,!,correct_cls(KB,cl(HH,B),O).
2093correct_cls0(KB,cl(H,B),O):- list_to_set(B,BB),BB\=@=B,!,correct_cls(KB,cl(H,BB),O).
2094
2118
2119correct_cls0(_KB,cl(H,B),O):- !,O=cl(H,B).
2120correct_cls0(KB,H,O):-correct_cls0(KB,(H:-true),O).
2121
2122
2129incorrect_cl(cl(H,B),cl([z_unused(H:-B)],[])).
2130
2131
2132
2133:- was_export(correct_boxlog/4). 2134
2141interface_to_correct_boxlog(KB,WHY,IN,OUT):- correct_boxlog(IN,KB,WHY,OUT).
2142
2143correct_boxlog((CLAU,SES),KB,Why,FlattenedO):- nonvar(SES),conjuncts_to_list_det((CLAU,SES),CLAUSES),!,correct_boxlog_0(CLAUSES,KB,Why,FlattenedO),!.
2144correct_boxlog(CLAUSES,KB,Why,FlattenedO):- (\+ is_list(CLAUSES)),!,correct_boxlog_0([CLAUSES],KB,Why,FlattenedO),!.
2145correct_boxlog(BOXLOG,KB,Why,FlattenedS):-correct_boxlog_0(BOXLOG,KB,Why,FlattenedS),!.
2146
2147
2154correct_boxlog_0(BOXLOG,KB,Why,FlattenedS):-
2155 must_det_l((
2156 must_maplist_det(adjust_kif(KB),BOXLOG,MODAL),
2157 2158 must_maplist_det(to_modal1(KB),MODAL,CLAUSES),
2159 must_maplist_det(correct_cls(KB),CLAUSES,NCFs),
2160 must_maplist_det(clauses_to_boxlog(KB,Why),NCFs,ListOfLists),
2161 flatten([ListOfLists],Flattened),
2162 must_maplist_det(removeQ(KB),Flattened,FlattenedM),
2163 must_maplist_det(to_modal1(KB),FlattenedM,FlattenedO),
2164 predsort(variants_are_equal,FlattenedO,FlattenedS),
2165 nop(sdmsg(horn=(FlattenedS))))),!.
2166
2167
2174variants_are_equal( =, A,B):- unnumbervars(A+B,AA+BB),AA=@=BB,!.
2175variants_are_equal( Order, A,B):- compare(Order,A,B).
2182sort_by_pred_class( <, '$unused'(_),B):- B\='$unused'(_),!.
2183sort_by_pred_class( >, B, '$unused'(_)):- B\='$unused'(_),!.
2184sort_by_pred_class( <, proven_neg(_),B):- B\=proven_neg(_),!.
2185sort_by_pred_class( >, B, proven_neg(_)):- B\=proven_neg(_),!.
2186sort_by_pred_class( =, A,B):- unnumbervars(A+B,AA+BB),AA=@=BB,!.
2187sort_by_pred_class( Op, (A:-_), B):-sort_by_pred_class( Op, A,B), Op \== (=),!.
2188sort_by_pred_class( Op, A, (B:-_)):-!,sort_by_pred_class( Op, A,B), Op \== (=),!.
2189sort_by_pred_class( Order, A,B):- compare(Order,A,B).
2190
2191
2198cf_to_flattened_clauses(KB,Why,NCFsI,FlattenedO):-
2199 loop_check(cf_to_flattened_clauses_0(KB,Why,NCFsI,FlattenedO),NCFsI=FlattenedO),!.
2200
2201
2208cf_to_flattened_clauses_0(KB,Why,NCFsI,FlattenedO):-
2209 must_det_l((
2210 must_maplist_det(correct_cls(KB),NCFsI,NCFs),
2211 2212 must_maplist_det(clauses_to_boxlog(KB,Why),NCFs,ListOfLists),
2213 flatten([ListOfLists],Flattened),
2214 baseKB:as_prolog_hook(Flattened,FlattenedL),
2215 list_to_set(FlattenedL,FlattenedS),
2216 must_maplist_det(demodal_sents(KB),FlattenedS,FlattenedO))),!.
2217
2219
2220:- fixup_exports.
common_logic_compiler
Provides a prolog database replacement that uses an interpretation of KIF
t/N hybridRule/2
Logicmoo Project PrologMUD: A MUD server written in Prolog Maintainer: Douglas Miles Dec 13, 2035
Compute normal forms for SHOIQ formulae. Skolemize SHOI<Q> formula.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
References
[1] Planning with First-Order Temporally Extended Goals Using Heuristic Search, Baier, J. and McIlraith, S., 2006. Proceedings of the 21st National Conference on Artificial Intelligence (AAAI06), July, Boston, MA
FORMULA SYNTAX
~( A) &(F, F)
v(F, F)
'=>'(F, F) '<=>'(F, F)all(X,A)
exists(X,A)
atleast(X,N,A)
atmost(X,N,A)
Expressions
A BNF grammar for Expresions is the following:
BEXPR ::= <fluent-term> | ~(FACT) | FACT BEXPR ::=
or(BEXPR,BEXPR)
|and(BEXPR,BEXPR)
|not(BEXPR)
Temporal Boolean Expressions
BNF grammar:
TBE ::= BEXPR | final TBE ::=
always(TBE)
|eventually(TBE)
|until(TBE,TBE)
|release(CT,TBE,TBE)
|cir(CT,TBE)
*/