mpred_terms

% Provides a common set of operators in translation between the several logical languages % % Logicmoo Project PrologMUD: A MUD server written in Prolog % Maintainer: Douglas Miles % Dec 13, 2035 % */

    9:- module(mpred_core,
   10   [begin_pfc/0,
   11          op(1050,xfx,('==>')),
   12          op(1050,xfx,'<==>'),
   13          op(1050,xfx,('<-')),
   14          op(1050,xfx,('<==')),
   15          op(1100,fx,('==>')),
   16          any_to_number/2,
   17          is_ftText/1,
   18          any_to_value/2,
   19          atom_to_value/2
   20          %mpred_test/1
   21          ]).   22
   23:- throw(module(pfcumt,[umt/1])).   24
   25%:- use_module(library('pfc2.2/pfcsyntax')).
   26
   27begin_pfc :- use_module(library(pfc_lib_2_2)).
   28
   29
   30:- 
   31    op(1050,xfx,('==>')),
   32    op(1050,xfx,'<==>'),
   33    op(1050,xfx,('<-')),
   34    op(1050,xfx,('<==')),
   35    op(1100,fx,('==>')).   36
   37
   38:- op(1050,xfx,('<-')).   39:- op(1199,fx,('==>')).   40:- op(1190,xfx,('::::')).   41:- op(1180,xfx,('==>')).   42:- op(1170,xfx,'<==>').   43:- op(1160,xfx,('<-')).   44:- op(1150,xfx,'=>').   45:- op(1140,xfx,'<=').   46:- op(1130,xfx,'<=>').   47:- op(1100,fx,('nesc')).   48:- op(300,fx,'-').   49:- op(300,fx,'~').   50:- op(600,yfx,'&'). 
   51:- op(600,yfx,'v').   52:- op(1075,xfx,'<-').   53:- op(350,xfx,'xor').   54
   55:- meta_predicate on_x_rtrace(*).   56on_x_rtrace(G):-on_x_debug(G).
   57
   58:- meta_predicate 
   59   ain_expanded(:),
   60   mpred_add(:),
   61   mpred_ain(:),
   62   mpred_aina(:),
   63   mpred_ainz(:),
   64   mpred_ain(:,*),
   65   mpred_aina(:,*),
   66   mpred_ainz(:,*),
   67   mpred_retract(:),
   68   mpred_retractall(:).   69
   70
   71mpred_axiom(Ax):-axiom(Ax).
   72file_begin(_).
   73repropagate(_).
   74otherwise.
 mpred_ainz(+G, ?S) is semidet
PFC Ainz.
   80mpred_ainz(G):- locally_tl(assert_to(z),mpred_ain(G)).
   81mpred_ainz(G,S):- locally_tl(assert_to(z),mpred_ain(G,S)).
 mpred_aina(+G, ?S) is semidet
PFC Aina.
   87mpred_aina(G):- locally_tl(assert_to(a),mpred_ain(G)).
   88mpred_aina(G,S):- locally_tl(assert_to(a),mpred_ain(G,S)).
 mpred_ain(P, S)
asserts P into the dataBase with support from S.

mpred_ain/2 and mpred_post/2 are the proper ways to add new clauses into the database and have forward reasoning done.

   97mpred_ain(_:P):- P==end_of_file,!.
   98mpred_ain(MPRED):- must((mpred_to_pfc(MPRED,PFC),pfc_add(PFC))).
   99mpred_ain(MPRED,SUP):- must((mpred_to_pfc(MPRED+SUP,PFC+PFCSUP),pfc_add(PFC,PFCSUP))).
 ain_expanded(P, S)
asserts P into the dataBase with support from S.
  106ain_expanded(IIIOOO):- mpred_ain((IIIOOO)).
  107ain_expanded(IIIOOO,S):- mpred_ain(IIIOOO,S).
  108mpred_add(P):-mpred_ain(P).
  109
  110
  111mpred_withdraw(MPRED):- mpred_to_pfc(MPRED,PFC),pfc_rem(PFC).
  112mpred_withdraw(MPRED,S0):- mpred_to_pfc(MPRED+S0,PFC+S1),pfc_rem(PFC,S1).
  113
  114mpred_retract(MPRED):- mpred_to_pfc(MPRED,PFC),pfc_clause(PFC),pfc_rem2(PFC).
  115mpred_retract_all(MPRED):- doall(mpred_retract(MPRED)).
  116
  117mpred_retractall(MPRED):- expand_to_hb(MPRED,H,_),mpred_retract_all(H).
  118
  119
  120
  121
  122mpred_why(MPRED):- must(mpred_to_pfc(MPRED,PFC)),!,(show_call(pfcWhy(PFC))*->true;(red_line(mpred_why(MPRED)),!,fail)).
  123
  124%mpred_test(MPRED):- must(mpred_to_pfc(MPRED,PFC)),!,(show_call(umt(PFC))*->true;(pfc_call(PFC)*->mpred_why(MPRED);red_line(mpred_test(MPRED)),!,fail)).
  125
  126% mpred_test(MPRED):- mpred_to_pfc(MPRED,PFC),(show_success(pfcWhy(PFC))->true;(once(show_call(umt(PFC)))*->true;(red_line,!,fail))).
  127
  128
  129is_asserted(P):- mpred_to_pfc(P,PP), pfc_clause(PP).
  130
  131
  132pp_DB :- umt((ignore(pfcPrintDB),listing)).
  133
  134
  135mpred_literal(MPRED):- mpred_to_pfc(MPRED,PFC), pfc_literal(PFC).
  136
  137
  138% Avoid Warning: mpred_loader:prolog_load_context(reload,true), which is called from
  139mpred_unload_file:- \+ call(call,prolog_load_context(reload,true)),!.
  140mpred_unload_file:- source_location(File,_),mpred_unload_file(File).
  141mpred_unload_file(File):-
  142  findall(
  143    mpred_withdraw(Data,(mfl4(VarNameZ,Module, File, LineNum),AX)),
  144    % clause_u
  145    call_u(spft(Data, mfl4(VarNameZ,Module, File, LineNum),AX)),
  146                    ToDo),
  147     length(ToDo,Len),
  148     wdmsg(mpred_unload_file(File,Len)),
  149     maplist(call,ToDo),!.
  150
  151
  152/*
  153pfc_term_expansion((P=>Q),(:- add((P=>Q)))).
  154pfc_term_expansion((P=>Q),(:- add(('<='(Q,P))))).  % speed-up attempt
  155pfc_term_expansion(('<='(P,Q)),(:- add(('<='(P,Q))))).
  156pfc_term_expansion((P<=>Q),(:- add((P<=>Q)))).
  157pfc_term_expansion((RuleName :::: Rule),(:- add((RuleName :::: Rule)))).
  158pfc_term_expansion(=>(P),(:- add(P))).
  159pfc_term_expansion(P,(:- add(P))).
  160*/
  161
  162call_u(MPRED):- strip_module(MPRED,M,PRED),mpred_to_pfc(PRED,PFC),!,umt(M,PFC).
  163
  164
  165
  166
  167
  168:- set_prolog_flag(pfc_ready,false).  169
  170:- op(500,fx,'~').  171:- op(1050,xfx,('=>')).  172:- op(1050,xfx,'<=>').  173:- op(1050,xfx,('<=')).  174:- op(1100,fx,('=>')).  175:- op(1150,xfx,('::::')).  176
  177
  178% :- use_module(library(pfc_lib)).
  179% :- use_module(library(mpred_core)).
  180
  181
  182:- if(false).  183
  184:- module_transparent(pfc_feature/1).  185:- dynamic(pfc_feature/1).  186:- export(pfc_feature/1).  187
  188pfc_feature(test_a_feature).
  189
  190:- module_transparent(pfc_test_feature/2).  191:- export(pfc_test_feature/2).  192
  193pfc_test_feature(Feature,Test):- pfc_feature(Feature)*-> mpred_test(Test) ; true.
  194
  195:- system:import(pfc_feature/1).  196:- system:export(pfc_feature/1).  197:- system:import(pfc_test_feature/2).  198:- system:export(pfc_test_feature/2).  199
  200:- system:import(pfc_feature/1).  201:- system:export(pfc_feature/1).  202:- baseKB:import(pfc_test_feature/2).  203:- baseKB:export(pfc_test_feature/2).  204
  205
  206
  207
  208
  209
  210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  211% DUMPST ON WARNINGS
  212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  213
  214skip_warning(informational).
  215skip_warning(information).
  216skip_warning(debug).
  217
  218skip_warning(discontiguous).
  219skip_warning(query).
  220skip_warning(banner).
  221skip_warning(silent).
  222skip_warning(debug_no_topic).
  223skip_warning(break).
  224skip_warning(io_warning).
  225skip_warning(interrupt).
  226skip_warning(statistics).
  227% skip_warning(check).
  228skip_warning(compiler_warnings).
  229
  230
  231skip_warning(T):- \+ compound(T),!,fail.
  232skip_warning(_:T):- !, compound(T),functor(T,F,_),skip_warning(F).
  233skip_warning(T):-compound(T),functor(T,F,_),skip_warning(F).
  234base_message(T1,T2,_):- (skip_warning(T1);skip_warning(T2);(\+ thread_self_main)),!.
  235base_message(_,_,_):- \+ current_predicate(dumpST/0),!.
  236base_message(T,Type,Warn):- dmsg(message_hook(T,Type,Warn)),dumpST,dmsg(message_hook(T,Type,Warn)),!,fail.
  237
  238:- multifile prolog:message//1, user:message_hook/3.  239:- discontiguous(user:message_hook/3).  240user:message_hook(T,Type,Warn):- fail, ( \+ current_prolog_flag(runtime_debug,0)),
  241   catch(once(base_message(T,Type,Warn)),_,fail),fail.
  242
  243
  244:- dynamic(system:test_results/3).  245
  246maybe_message_hook(compiler_warnings(_,[always(true,var,_),always(false,integer,_),
  247   always(false,integer,_),always(true,var,_),always(false,integer,_),always(false,integer,_)]),
  248   warning,[]):- !.
  249
  250maybe_message_hook(import_private(_,_),_,_).
  251maybe_message_hook(check(undefined(_, _)),_,_).
  252maybe_message_hook(ignored_weak_import(header_sane,_),_,_).
  253% maybe_message_hook(_,warning,_).
  254maybe_message_hook(T,Type,Warn):-
  255  ignore(source_location(File,Line)),
  256  once((nl,dmsg(message_hook(T,Type,Warn)),nl,
  257  assertz(system:test_results(File:Line/T,Type,Warn)),dumpST,nl,dmsg(message_hook(File:Line:T,Type,Warn)),nl)),
  258  fail.
  259
  260maybe_message_hook(_,error,_):- current_prolog_flag(runtime_debug, N),N>2,break.
  261maybe_message_hook(_,warning,_):- current_prolog_flag(runtime_debug, N),N>2,break.
  262
  263system:test_completed:- list_problems,test_completed_exit_maybe(4).
  264system:test_retake:- list_problems,test_completed_exit_maybe(7).
  265
  266
  267list_problems:-listing(system:test_results/3),
  268  foo:listing(header_sane:_),
  269  nop((listing(user:_))).
  270
  271
  272test_completed_exit(4):- halt(4).
  273test_completed_exit(5):- halt(5).
  274test_completed_exit(N):- (debugging-> break ; true), halt(N).
  275
  276test_completed_exit_maybe(_):- system:test_results(_,error,_),test_completed_exit(9).
  277test_completed_exit_maybe(_):- system:test_results(_,warning,_),test_completed_exit(3).
  278test_completed_exit_maybe(_):- system:test_results(_,warn,_),test_completed_exit(3).
  279test_completed_exit_maybe(N):- test_completed_exit(N).
  280
  281set_file_abox_module(User):- '$set_typein_module'(User), '$set_source_module'(User),set_fileAssertMt(User).
  282
  283set_file_abox_module_wa(User):- set_file_abox_module(User),set_defaultAssertMt(User).
  284
  285
  286
  287:- multifile prolog:message//1, user:message_hook/3.  288% user:message_hook(import_private(pfc_lib,_:_/_),warning,_):- source_location(_,_),!.
  289user:message_hook(io_warning(_,'Illegal UTF-8 start'),warning,_):- source_location(_,_),!.
  290user:message_hook(T,Type,Warn):- current_prolog_flag(runtime_message_hook, true),
  291  ((current_prolog_flag(runtime_debug, N),N>2) -> true ; source_location(_,_)),
  292  memberchk(Type,[error,warning]),once(maybe_message_hook(T,Type,Warn)),fail.
  293
  294
  295
  296mpred_loader_file.
  297%system:term_expansion(end_of_file,_):-must(check_clause_counts),fail.
  298%system:term_expansion(EOF,_):-end_of_file==EOF,must(check_clause_counts),fail.
  299
  300
  301:- endif.  302
  303
  304
  305:- meta_predicate(mpred_to_pfc(*,*)).  306mpred_to_pfc(MPRED,PFC):- must(=(MPRED,PFC)),!.
  307mpred_to_pfc(MPRED,PFC):- must(mp2pfc(MPRED,PFC)),!.
  308
  309
  310
  311mpred_info(I):-mpred_to_pfc(I,O),!,
  312 % get_unnegated_functor(O,F,A),
  313 with_output_to(user_error,
  314 ((dmsg("======================================================================="),
  315  listing(O),
  316  dmsg("======================================================================="),
  317  maplist(mp_printAll(O),
  318 [+pfcType(O,v),
  319  call(pfcWhy(O)),
  320  +pfcChild(O,v),
  321  pfcFact(O),
  322  axiom(O),
  323  wellFounded(O),
  324  pfcSupported(local,O),
  325  pfcSupported(cycles,O),
  326  assumption(O),
  327  pfcTraced(O)])),
  328 dmsg("======================================================================="))).
  329
  330
  331mp_printAll(S,call(O)):- !,
  332  subst(O,S,s,NAME),
  333  nl,flush_output,fmt("=================="),wdmsg(NAME),wdmsg("---"),flush_output,
  334  doall(((flush_output,O,flush_output)*->true;wdmsg(false=NAME))),fmt("=================="),nl,flush_output.
  335
  336mp_printAll(S,+(O)):- !,
  337  subst(O,S,s,NAME),subst(O,v,V,CALL),functor(O,F,_),
  338  nl,flush_output, fmt("=================="),wdmsg(NAME),wdmsg("---"),flush_output,
  339  doall(((flush_output,CALL,flush_output)*->fmt9(V);(fail=F))),nl,fmt("=================="),nl,flush_output.
  340
  341mp_printAll(S,(O)):-  !,  functor(O,F,A),mp_nnvv(S,O,F,A),flush_output.
  342
  343mp_nnvv(_,(O),F,1):- !, doall(((flush_output,O,flush_output)*->wdmsg(+F);wdmsg(-F))).
  344mp_nnvv(S,(O),_,_):- !, subst(O,S,s,NAME), doall(((flush_output,O,flush_output)*->wdmsg(-NAME);wdmsg(+NAME))).
  345
  346
  347mpred_must(G):- must(mpred_test(G)).
 match_source_ref1(:TermARG1) is semidet
Match Source Ref Secondary Helper.
  355match_source_ref1(ax):-!.
  356match_source_ref1(mfl4(VarNameZ,_,_,_)).
 make_uu_remove(:TermU) is semidet
Make Uu Remove.
  362make_uu_remove((_,ax)).
 has_functor(:TermC) is semidet
Has Functor.
  369has_functor(_):-!,fail.
  370has_functor(F/A):-!,is_ftNameArity(F,A),!.
  371has_functor(C):- (\+ is_ftCompound(C)),!,fail.
  372has_functor(C):-is_ftCompound(C),\+is_list(C).
 mpred_each_literal(+P, ?E) is semidet
PFC Each Literal.
  379mpred_each_literal(P,E):-is_ftNonvar(P),P=(P1,P2),!,(mpred_each_literal(P1,E);mpred_each_literal(P2,E)).
  380mpred_each_literal(P,P). %:-conjuncts_to_list(P,List),member(E,List).
 retract_eq_quitely(+H) is semidet
Retract Using (==/2) (or =@=/2) ) Quitely.
  388retract_eq_quitely(H):- umt(retract_eq_quitely_f(H)).
 retract_eq_quitely_f(+H) is semidet
Retract Using (==/2) (or =@=/2) ) Quitely False.
  394retract_eq_quitely_f((H:-B)):- !,clause_asserted_i(H,B,Ref),erase(Ref).
  395retract_eq_quitely_f(pfclog(H)):- retract_eq_quitely_f(H),fail.
  396retract_eq_quitely_f((H)):- clause_asserted_i(H,true,Ref),erase(Ref).
 assert_eq_quitely(+H) is semidet
Assert Using (==/2) (or =@=/2) ) Quitely.
  403assert_eq_quitely(H):- attvar_op(db_op_call(assert,assert_if_new),H).
 mpred_is_tautology(+Var) is semidet
PFC If Is A Tautology.

:- module_transparent( (mpred_is_tautology)/1).

  411mpred_is_tautology(V):- (is_ftVar(V) -> true;(copy_term_nat(V,VC),numbervars(VC),mpred_is_taut(VC))),!.
 mpred_is_taut(:TermA) is semidet
PFC If Is A Taut.
  419mpred_is_taut(A):-var(A),!.
  420mpred_is_taut(A:-B):-!,mpred_is_taut(B==>A).
  421mpred_is_taut(A<-B):-!,mpred_is_taut(B==>A).
  422mpred_is_taut(A<==>B):-!,(mpred_is_taut(A==>B);mpred_is_taut(B==>A)).
  423mpred_is_taut(A==>B):- A==B,!.
  424mpred_is_taut((B,_)==>A):- mpred_is_assertable(B),mpred_is_taut(A==>B),!.
  425mpred_is_taut((_,B)==>A):- mpred_is_assertable(B),mpred_is_taut(A==>B),!.
  426mpred_is_taut(B==>(A,_)):- mpred_is_assertable(A),mpred_is_taut(A==>B),!.
  427mpred_is_taut(B==>(_,A)):- mpred_is_assertable(A),mpred_is_taut(A==>B),!.
  428
  429
  430% baseKB:decl_database_hook(Op,Hook):- loop_check_nr(pfc_provide_storage_op(Op,Hook)).
 is_retract_first(+VALUE1) is semidet
If Is A Retract First.
  437is_retract_first(one).
  438is_retract_first(a).
 mpred_is_assertable(+X) is semidet
PFC If Is A Assertable.
  447mpred_is_assertable(X):- mpred_literal_nv(X),\+ functor(X,{},_).
 mpred_literal_nv(+X) is semidet
PFC Literal Nv.
  453mpred_literal_nv(X):-is_ftNonvar(X),mpred_literal(X).
  454
  455
  456
  457if_missing1(Q):- mpred_literal_nv(Q), umt( \+ ~ Q), if_missing_mask(Q,R,Test),!, lookup_u(R), Test.
 if_missing_mask(+Q, ?R, ?Test) is semidet
If Missing Mask.
  465if_missing_mask(M:Q,M:R,M:Test):- nonvar(Q),!,if_missing_mask(Q,R,Test).
  466if_missing_mask(Q,~Q,\+Q):- \+ is_ftCompound(Q),!.
  467
  468if_missing_mask(ISA, ~ ISA, \+ ISA):- functor(ISA,F,1),(F==tSwim;umt(functorDeclares(F))),!.
  469if_missing_mask(HB,RO,TestO):- once(mpred_rule_hb(HB,H,B)),B\==true,HB\==H,!,if_missing_mask(H,R,TestO),subst(HB,H,R,RO).
  470if_missing_mask(Q,R,Test):-
  471   which_missing_argnum(Q,N),
  472   if_missing_n_mask(Q,N,R,Test),!.
  473if_missing_mask(ISA, ~ ISA, \+ ISA).
 if_missing_n_mask(+Q, ?N, ?R, ?Test) is semidet
If Missing Mask.
  480if_missing_n_mask(Q,N,R,Test):-
  481  get_unnegated_head_arg(N,Q,Was),
  482  (nonvar(R)-> (which_missing_argnum(R,RN),get_unnegated_head_arg(RN,R,NEW));replace_arg(Q,N,NEW,R)),!,
  483   Test=dif:dif(Was,NEW).
  484
  485/*
  486Old version
  487if_missing_mask(Q,N,R,dif:dif(Was,NEW)):- 
  488 must((is_ftNonvar(Q),acyclic_term(Q),acyclic_term(R),functor(Q,F,A),functor(R,F,A))),
  489  (singleValuedInArg(F,N) -> 
  490    (get_unnegated_head_arg(N,Q,Was),replace_arg(Q,N,NEW,R));
  491    ((get_unnegated_head_arg(N,Q,Was),is_ftNonvar(Was)) -> replace_arg(Q,N,NEW,R);
  492        (N=A,get_unnegated_head_arg(N,Q,Was),replace_arg(Q,N,NEW,R)))).
  493*/
 which_missing_argnum(+VALUE1, ?VALUE2) is semidet
Which Missing Argnum.
  500which_missing_argnum(Q,N):-
  501 must((acyclic_term(Q),is_ftCompound(Q),get_functor(Q,F,A))),
  502 F\=t,
  503  (umt(singleValuedInArg(F,N)) -> true;
  504    ((get_unnegated_head_arg(N,Q,Was),is_ftNonvar(Was)) -> true; ( A>1 -> N=A ; fail))).
  505
  506
  507
  508:- export(any_to_number/2).
 any_to_value(?Var, ?Var) is semidet
Any Converted To Value.
  513any_to_value(Var,Var):-var(Var),!.
  514any_to_value(V,Term):-atom(V),!,atom_to_value(V,Term).
  515any_to_value(A,V):-any_to_number(A,V).
  516any_to_value(A,A).
 any_to_number(:TermN, ?N) is semidet
Any Converted To Number.
  523any_to_number(N,N):- number(N),!.
  524any_to_number(ftDiceFn(A,B,C),N):- ground(A),if_defined(roll_dice(A,B,C,N)),!.
  525any_to_number(A,N):-atom(A),atom_to_value(A,V),A\=V,any_to_number(V,N).
  526any_to_number(A,N):- catch(number_string(N,A),_,fail).
 atom_to_value(?V, :TermTerm) is semidet
Atom Converted To Value.
  532atom_to_value(V,Term):-not(atom(V)),!,any_to_value(V,Term).
  533% 56
  534atom_to_value(V,Term):- catch((read_term_from_atom(V,Term,[variable_names([])])),_,fail),!.
  535% 18d18+4000
  536atom_to_value(V,ftDiceFn(T1,T2,+T3)):- atomic_list_concat_safe([D1,'d',D2,'+',D3],V), atom_to_value(D1,T1),atom_to_value(D2,T2),atom_to_value(D3,T3),!.
  537atom_to_value(V,ftDiceFn(T1,T2,-T3)):- atomic_list_concat_safe([D1,'d',D2,'-',D3],V), atom_to_value(D1,T1),atom_to_value(D2,T2),atom_to_value(D3,T3),!.
 is_ftText(?Arg) is semidet
If Is A Format Type Text.
  545is_ftText(Arg):- string(Arg),!.
  546is_ftText(Arg):- \+ compound(Arg),!,fail.
  547is_ftText(Arg):- functor(Arg,s,_),!.
  548is_ftText([Arg|_]):-string(Arg),!.
  549is_ftText(Arg):- is_ftVar(Arg),!,fail.
  550is_ftText(Arg):- text_to_string_safe(Arg,_),!.
  551is_ftText(Arg):- functor(Arg,S,_), ereq(resultIsa(S,ftText)).
  552
  553:- kb_global(baseKB:ftText/1).  554:- assert_if_new(baseKB:(ftText(A):- !, if_defined(term_is_ft(A, ftText),is_ftText(A)),!)).  555
  556% =======================================================
  557% term utils
  558% =======================================================
  559
  560:- was_export(inverse_args/2).
 inverse_args(?AR, ?GS) is semidet
Inverse Arguments.
  568inverse_args([AR,GS],[GS,AR]):-!.
  569inverse_args([AR,G,S],[S,G,AR]):-!.
  570inverse_args([A,R,G,S],[S,R,G,A]):-!.
  571inverse_args([P,A,R,G,S],[S,A,R,G,P]):-!.
  572
  573:- was_export(same_vars/2).
 same_vars(?T1, ?T2) is semidet
Same Variables.
  581same_vars(T1,T2):-term_variables(T1,V1),term_variables(T2,V2),!,V1==V2.
 replace_arg(?C, :PRED3A, ?VAR, ?CC) is semidet
Replace Argument.
  590replace_arg(C,A,_VAR,_CC):-sanity((is_ftCompound(C),integer(A))),fail.
  591replace_arg((C:-B),A,VAR,(CC:-B)):-!,replace_arg(C,A,VAR,CC).
  592replace_arg(~ (C),A,VAR,~(CC)):-!,replace_arg(C,A,VAR,CC).
  593replace_arg( \+ (C),A,VAR,~(CC)):-!,replace_arg(C,A,VAR,CC).
  594replace_arg(M:(C),A,VAR,M:(CC)):-!,replace_arg(C,A,VAR,CC).
  595replace_arg(C,0,VAR,CC):-!, C=..[_|ARGS],CC=..[VAR|ARGS].
  596replace_arg(C,1,VAR,CC):-!, C=..[F,_|ARGS],CC=..[F,VAR|ARGS].
  597replace_arg(C,2,VAR,CC):-!, C=..[F,A,_|ARGS],CC=..[F,A,VAR|ARGS].
  598replace_arg(C,3,VAR,CC):-!, C=..[F,A,B,_|ARGS],CC=..[F,A,B,VAR|ARGS].
  599% replace_arg(C,A,VAR,CO):- dupe_term(C,CC),setarg(A,CC,VAR),!,CC=CO.
  600replace_arg(C,A,VAR,CC):- C=..FARGS,replace_nth_arglist(FARGS,A,VAR,FARGO),!,CC=..FARGO.
  601
  602% :- mpred_trace_nochilds(replace_arg/4).
Replace the Nth (1-based) element of a list. :- mpred_trace_nochilds(replace_nth_arglist/4).
 replace_nth_arglist(:TermARG1, ?VALUE2, ?VAR, :TermVAR) is semidet
Replace Nth Arglist.
  614replace_nth_arglist([],_,_,[]):- !.
  615replace_nth_arglist([_|ARGO],0,VAR,[VAR|ARGO]):- !.
  616replace_nth_arglist([T|FARGS],A,VAR,[T|FARGO]):- 
  617    A2 is A-1,replace_nth_arglist(FARGS,A2,VAR,FARGO).
 replace_nth_ref(:TermARG1, ?N, ?OldVar, ?NewVar, :TermARG5) is semidet
Replace Nth Ref.
  627replace_nth_ref([],_N,_OldVar,_NewVar,[]):- !,trace_or_throw_ex(missed_the_boat).
  628replace_nth_ref([OldVar|ARGS],1,OldVar,NewVar,[NewVar|ARGS]):- !.
  629replace_nth_ref([Carry|ARGS],Which,OldVar,NewVar,[Carry|NEWARGS]):- 
  630 Which1 is Which-1,
  631 replace_nth_ref(ARGS,Which1,OldVar,NewVar,NEWARGS),!.
  632
  633
  634% :- mpred_trace_nochilds(update_value/3).
 update_value(?OLD, ?NEW, ?NEXT) is semidet
Update Value.
  642update_value(OLD,NEW,NEXT):- var(NEW),!,trace_or_throw_ex(logicmoo_bug(update_value(OLD,NEW,NEXT))).
  643update_value(OLD,NEW,NEWV):- var(OLD),!,compute_value_no_dice(NEW,NEWV).
  644update_value(OLD,X,NEW):- is_list(OLD),!,list_update_op(OLD,X,NEW),!.
  645update_value(OLDI,+X,NEW):- compute_value(OLDI,OLD),number(OLD),catch(NEW is OLD + X,_,fail),!.
  646update_value(OLDI,-X,NEW):- compute_value(OLDI,OLD),number(OLD),catch(NEW is OLD - X,_,fail),!.
  647update_value(OLDI,X,NEW):- number(X),X<0,compute_value(OLDI,OLD),number(OLD),catch(NEW is OLD + X,_,fail),!.
  648update_value(_,NEW,NEWV):- compute_value_no_dice(NEW,NEWV),!.
 flatten_append(?First, ?Last, ?Out) is semidet
Flatten Append.
  657flatten_append(First,Last,Out):-flatten([First],FirstF),flatten([Last],LastF),append(FirstF,LastF,Out),!.
 list_update_op(?OLDI, :TermX, ?NEW) is semidet
List Update Oper..
  666list_update_op(OLDI,+X,NEW):-flatten_append(OLDI,X,NEW),!.
  667list_update_op(OLDI,-X,NEW):-flatten([OLDI],OLD),flatten([X],XX),!,list_difference_eq(OLD,XX,NEW),!.
 compute_value_no_dice(?NEW, ?NEW) is semidet
Compute Value No Dice.
  676compute_value_no_dice(NEW,NEW):- compound(NEW),functor_catch(NEW,ftDiceFn,_),!.
  677compute_value_no_dice(NEW,NEW):- compound(NEW),functor_catch(NEW,ftDice,_),!.
  678compute_value_no_dice(NEW,NEWV):-compute_value(NEW,NEWV).
 compute_value(?NEW, ?NEWV) is semidet
Compute Value.
  687compute_value(NEW,NEWV):-catch(NEWV is NEW,_,fail),!.
  688compute_value(NEW,NEWV):-catch(any_to_value(NEW,NEWV),_,fail),!.
  689compute_value(NEW,NEW).
 insert_into(:TermARGS, ?VALUE2, ?Insert, :TermInsert) is semidet
Insert Converted To.
  698insert_into(ARGS,0,Insert,[Insert|ARGS]):- !.
  699insert_into([Carry|ARGS],After,Insert,[Carry|NEWARGS]):- 
  700   After1 is After - 1,
  701   insert_into(ARGS,After1,Insert,NEWARGS).
  702
  703
  704
  705% ========================================
  706% is_holds_true/is_holds_false
  707% ========================================
  708
  709
  710:- was_export(into_plist/2).  711
  712%= 	 	 
 into_plist(?In, ?Out) is semidet
Converted To Plist.
  718into_plist(In,Out):-into_plist_arities(2,12,In,Out).
  719
  720:- was_export(into_plist_arities/4).  721
  722%= 	 	 
 into_plist_arities(?Min, ?Max, ?PLIST, ?PLISTO) is semidet
Converted To Plist Arities.
  728into_plist_arities(Min,Max,PLIST,PLISTO):- var(PLIST),!,between(Min,Max,X),length(PLIST,X),PLISTO=PLIST.
  729into_plist_arities(_,_,[P|LIST],[P|LIST]):-var(P),!.
  730into_plist_arities(_,_,[(t)|PLIST],PLIST):-!.  % t is our versuion of '$holds' or call/N
  731into_plist_arities(_,_,plist(P,LIST),[P|LIST]):-!.
  732into_plist_arities(_,_,Call,PLIST):- Call=..PLIST. % finally the fallthrue
  733
  734
  735
  736%= 	 	 
 never_mpred_tcall(?VALUE1) is semidet
Never Managed Predicate Managed Predicate.
  743never_mpred_tcall(mpred_prop).
  744never_mpred_tcall(isa).
  745never_mpred_tcall(arity).
  746
  747
  748local_qh_mpred_prop(M,F,A,C):- umt(mpred_prop(M,F,A,C)).
  749
  750
  751% :- setup_mpred_ops.
  752
  753
  754                   
  755%= 	 	 
  756
  757:- meta_predicate(if_result(0,0)).  758
  759%= 	 	 
 if_result(:GoalTF, :Goal) is semidet
If Result.
  765if_result(TF,Call):-(TF->Call;true).
  766
  767
  768
  769
  770%= 	 	 
 mpred_plist_t(?P, :TermLIST) is semidet
Managed Predicate Plist True Stucture.
  776/* mpred_plist_t(P,[]):-!,t(P). */
  777mpred_plist_t(P,LIST):-var(P),!,is_list(LIST),CALL=..[t,P|LIST],on_x_debug((CALL)).
  778mpred_plist_t(t,[P|LIST]):-!, mpred_plist_t(P,LIST).
  779%mpred_plist_t(mpred_isa,[C,_A,I]):-!,ground(I:C),local_qh_mpred_isa(C,I).
  780mpred_plist_t(isa,[I,C]):-!,call(call,t,C,I).
  781mpred_plist_t(P,_):-never_mpred_tcall(P),!,fail.
  782mpred_plist_t(P,[L|IST]):-is_holds_true(P),!,mpred_plist_t(L,IST).
  783mpred_plist_t(P,LIST):-is_holds_false(P),!,umt(mpred_f(LIST)).
  784mpred_plist_t(P,LIST):- CALL=..[t,P|LIST],on_x_debug(CALL).
  785
  786
  787:- meta_predicate(mpred_fa_call(?,?,0)).  788
  789
  790
  791%= 	 	 
 mpred_fa_call(?F, ?UPARAM2, :Goal) is semidet
Managed Predicate Functor-arity Call.
  797mpred_fa_call(F,A,Call):- var(F),!,
  798 no_repeats(F,(clause_b(support_hilog(F,A));clause_b(arity(F,A)))), 
  799   once((F\==t, 
  800   \+ a(rtNotForUnboundPredicates,F),current_predicate(F,M:_OtherCall))),
  801    on_x_debug(M:Call).
  802mpred_fa_call(M:F,A,Call):- nonvar(M),!,mpred_fa_call(F,A,M:Call).
  803mpred_fa_call(F,_,Call):-F\==t,current_predicate(F,M:_OtherCall),!,M:Call.
  804
  805
  806%= 	 	 
 mpred_fact_arity(?VALUE1, ?VALUE2) is semidet
Managed Predicate Fact Arity.
  812mpred_fact_arity(F,A):- umt(arity(F,A)),
  813  suggest_m(M),
  814  once(local_qh_mpred_prop(M,F,A,prologHybrid);
  815     local_qh_mpred_prop(M,F,A,pfcControlled);
  816     local_qh_mpred_prop(M,F,A,prologPTTP);
  817     local_qh_mpred_prop(M,F,A,prologKIF)),!.
  818
  819
  820%= 	 	 
 prologHybridFact(?G) is semidet
Prolog Hybrid Fact.
  826prologHybridFact(G):- (var(G)->(mpred_fact_arity(F,A),functor(G,F,A));true),into_mpred_form(G,M),!,no_repeats(umt(M)).
 mpred_pbody(+H, ?B, ?R, ?BIn, ?WHY) is semidet
PFC Pbody.

mpred_pbody(H,B,_R,fail,deduced(backchains)):- get_bc_clause(H,_,B)),!. mpred_pbody(H,infoF(INFO),R,B,Why):-!,mpred_pbody_f(H,INFO,R,B,Why). mpred_pbody(H,B,R,BIn,WHY):- is_true(B),!,BIn=B,get_why(H,H,R,WHY). mpred_pbody(H,B,R,B,asserted(R,(H:-B))).

 get_why(+VALUE1, ?CL, ?R, :TermR) is semidet
Get Generation Of Proof.
  846get_why(_,CL,R,asserted(R,CL:-U)):- clause_u(spft(CL, U, ax),true),!.
  847get_why(H,CL,R,deduced(R,WHY)):- (mpred_get_support(H,WH)*->WHY=(H=WH);(mpred_get_support(CL,WH),WHY=(CL=WH))).
  848
  849mpred_get_support(P,S):-pfcGetSupport(P,S).
 mpred_pbody_f(+H, ?CL, ?R, ?B, ?WHY) is semidet
PFC Pbody False.
  856mpred_pbody_f(H,CL,R,B,WHY):- CL=(B==>HH),sub_term_eq(H,HH),!,get_why(H,CL,R,WHY).
  857mpred_pbody_f(H,CL,R,B,WHY):- CL=(HH<-B),sub_term_eq(H,HH),!,get_why(H,CL,R,WHY).
  858mpred_pbody_f(H,CL,R,B,WHY):- CL=(HH<==>B),sub_term_eq(H,HH),get_why(H,CL,R,WHY).
  859mpred_pbody_f(H,CL,R,B,WHY):- CL=(B<==>HH),sub_term_eq(H,HH),!,get_why(H,CL,R,WHY).
  860mpred_pbody_f(H,CL,R,fail,infoF(CL)):- trace_or_throw_ex(mpred_pbody_f(H,CL,R)).
 sub_term_eq(+H, ?HH) is semidet
Sub Term Using (==/2) (or =@=/2) ).
  867sub_term_eq(H,HH):-H==HH,!.
  868sub_term_eq(H,HH):-each_subterm(HH,ST),ST==H,!.
 sub_term_v(+H, ?HH) is semidet
Sub Term V.
  875sub_term_v(H,HH):-H=@=HH,!.
  876sub_term_v(H,HH):-each_subterm(HH,ST),ST=@=H,!.
 all_different_head_vals(+Clause) is det
Enforces All Different Head Vals.
  882all_different_head_vals(HB):- (\+ compound(HB) ; ground(HB)),!.
  883all_different_head_vals(HB):- 
  884  mpred_rule_hb(HB,H,B),
  885  term_slots(H,Slots),  
  886  (Slots==[]->
  887     all_different_head_vals(B);
  888    (lock_vars(Slots),all_different_head_vals_2(H,Slots),unlock_vars(Slots))),!.
  889  
  890
  891all_different_head_vals_2(_H,[]):-!.
  892all_different_head_vals_2(H,[A,R|EST]):-get_unnegated_head_arg(_,H,E1),E1 ==A,dif(A,E2),get_unnegated_head_arg(_,H,E2),\+ contains_var(A,E2),all_different_vals(dif_matrix,[A,E2,R|EST]),!.
  893all_different_head_vals_2(_H,[A,B|C]):-all_different_vals(dif_matrix,[A,B|C]),!.
  894all_different_head_vals_2(HB,_):- \+ compound(HB),!.
  895all_different_head_vals_2(H,[A]):-get_unnegated_head_arg(_,H,E1),E1 ==A, H=..[_|ARGS], all_different_vals(dif_matrix,ARGS),!.
  896all_different_head_vals_2(H,[A]):-get_unnegated_head_arg(_,H,E1),E1 ==A, get_unnegated_head_arg(_,H,E2), A\==E2, \+ contains_var(A,E2), dif(A,E2),!.
  897all_different_head_vals_2(H,[A]):-get_unnegated_head_arg(_,H,E1),E1\==A, compound(E1), contains_var(A,E1), all_different_head_vals_2(E1,[A]),!.
  898all_different_head_vals_2(_,_).
 mpred_rule_hb(+Outcome, ?OutcomeO, ?AnteO) is semidet
Calculate PFC Rule Head+body.
  905mpred_rule_hb(Outcome,OutcomeO,Body):- nonvar(OutcomeO),!,mpred_rule_hb(Outcome,OutcomeN,Body),must(OutcomeO=OutcomeN).
  906mpred_rule_hb(Outcome,OutcomeO,BodyO):- nonvar(BodyO),!,mpred_rule_hb(Outcome,OutcomeO,BodyN),must(BodyN=BodyO).
  907mpred_rule_hb(Outcome,OutcomeO,AnteO):- 
  908  quietly((mpred_rule_hb_0(Outcome,OutcomeO,Ante),
  909  mpred_rule_hb_0(Ante,AnteO,_))).
  910% :-mpred_trace_nochilds(mpred_rule_hb/3).
 mpred_rule_hb_0(+Rule, -Head, -Body) is nondet
Calculate PFC rule Head+Body Primary Helper.
  919mpred_rule_hb_0(Outcome,OutcomeO,true):-is_ftVar(Outcome),!,OutcomeO=Outcome.
  920mpred_rule_hb_0(Outcome,OutcomeO,true):- \+compound(Outcome),!,OutcomeO=Outcome.
  921mpred_rule_hb_0((Outcome1,Outcome2),OutcomeO,AnteO):- mpred_rule_hb(Outcome1,Outcome1O,Ante1),mpred_rule_hb(Outcome2,Outcome2O,Ante2),
  922                   conjoin(Outcome1O,Outcome2O,OutcomeO),
  923                   conjoin(Ante1,Ante2,AnteO).
  924mpred_rule_hb_0((Ante1==>Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  925mpred_rule_hb_0((Ante1=>Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  926mpred_rule_hb_0((Ante1->Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  927mpred_rule_hb_0((Ante1*->Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  928% mpred_rule_hb_0((Outcome/Ante1),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  929mpred_rule_hb_0(rhs([Outcome]),OutcomeO,Ante2):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  930% mpred_rule_hb_0(rhs([OutcomeH|OutcomeT]),OutcomeO,Ante2):- !, mpred_rule_hb(Outcome,OutcomeO,Ante2).
  931mpred_rule_hb_0({Outcome},OutcomeO,Ante2):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  932mpred_rule_hb_0((Outcome<-Ante1),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  933mpred_rule_hb_0((Ante1 & Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  934mpred_rule_hb_0((Ante1 , Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  935mpred_rule_hb_0((Outcome<==>Ante1),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  936mpred_rule_hb_0((Ante1<==>Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  937mpred_rule_hb_0(_::::Outcome,OutcomeO,Ante2):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb_0(Outcome,OutcomeO,Ante2).
  938mpred_rule_hb_0(bt(Outcome,Ante1),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  939mpred_rule_hb_0(pt(Ante1,Outcome),OutcomeO,(Ante1,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  940mpred_rule_hb_0(pk(Ante1a,Ante1b,Outcome),OutcomeO,(Ante1a,Ante1b,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  941mpred_rule_hb_0(nt(Ante1a,Ante1b,Outcome),OutcomeO,(Ante1a,Ante1b,Ante2)):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  942mpred_rule_hb_0(spft(Outcome,Ante1a,Ante1b),OutcomeO,(Ante1a,Ante1b,Ante2)):- (nonvar(Outcome)-> ! ; true),mpred_rule_hb(Outcome,OutcomeO,Ante2).
  943mpred_rule_hb_0(que(Outcome,_),OutcomeO,Ante2):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  944% mpred_rule_hb_0(pfc Default(Outcome),OutcomeO,Ante2):- (nonvar(Outcome)-> ! ; true), mpred_rule_hb(Outcome,OutcomeO,Ante2).
  945mpred_rule_hb_0((Outcome:-Ante),Outcome,Ante):-(nonvar(Outcome)-> ! ; true).
  946mpred_rule_hb_0(Outcome,Outcome,true).
 ain_minfo(+G) is semidet
Assert If New Metainformation.
  953:- module_transparent(ain_minfo/1).  954ain_minfo(G):-ain_minfo(assertz_if_new,G).
 ain_minfo(:PRED1How, ?H) is semidet
Assert If New Metainformation.
  960:- module_transparent(ain_minfo/2).  961ain_minfo(How,(H:-True)):-is_true(True),must(is_ftNonvar(H)),!,ain_minfo(How,H).
  962/*
  963ain_minfo(How,(H<-B)):- !,ain_minfo(How,(H:-infoF(H<-B))),!,get_bc_clause(H,Post),ain_minfo(How,Post),ain_minfo_2(How,(B:-infoF(H<-B))).
  964ain_minfo(How,(B==>H)):- !,ain_minfo(How,(H:-infoF(B==>H))),!,ain_minfo_2(How,(B:-infoF(B==>H))).
  965ain_minfo(How,(B<==>H)):- !,ain_minfo(How,(H:-infoF(B<==>H))),!,ain_minfo(How,(B:-infoF(B<==>H))),!.
  966ain_minfo(How,((A,B):-INFOC)):-mpred_is_info(INFOC),(is_ftNonvar(A);is_ftNonvar(B)),!,ain_minfo(How,((A):-INFOC)),ain_minfo(How,((B):-INFOC)),!.
  967ain_minfo(How,((A;B):-INFOC)):-mpred_is_info(INFOC),(is_ftNonvar(A);is_ftNonvar(B)),!,ain_minfo(How,((A):-INFOC)),ain_minfo(How,((B):-INFOC)),!.
  968ain_minfo(How,(-(A):-infoF(C))):-is_ftNonvar(C),is_ftNonvar(A),!,ain_minfo(How,((A):-infoF((C)))). % attvar_op(How,(-(A):-infoF(C))).
  969ain_minfo(How,(~(A):-infoF(C))):-is_ftNonvar(C),is_ftNonvar(A),!,ain_minfo(How,((A):-infoF((C)))). % attvar_op(How,(-(A):-infoF(C))).
  970ain_minfo(How,(A:-INFOC)):- is_ftNonvar(INFOC), get_bc_clause(A,(A:-INFOC)),!,attvar_op(How,(A:-INFOC)),!.
  971ain_minfo(How,bt(_ABOX,H,_)):-!,get_bc_clause(H,Post),attvar_op(How,Post).
  972ain_minfo(How,nt(H,Test,Body)):-!,attvar_op(How,(H:-fail,nt(H,Test,Body))).
  973ain_minfo(How,pt(H,Body)):-!,attvar_op(How,(H:-fail,pt(H,Body))).
  974ain_minfo(How,(A0:-INFOC0)):- mpred_is_info(INFOC0), copy_term_and_varnames((A0:-INFOC0),(A:-INFOC)),!,must((mpred_rewrap_h(A,AA),imploded_copyvars((AA:-INFOC),ALLINFO), attvar_op(How,(ALLINFO)))),!.
  975%ain_minfo(How,G):-pfc_trace_msg(skipped_add_meta_facts(How,G)).
  976*/
  977ain_minfo(_,_).
  978
  979
  980:- was_export(ain_minfo_2/2).
 ain_minfo_2(:PRED1How, ?G) is semidet
Assert If New Metainformation Extended Helper.
  986:- module_transparent(ain_minfo_2/2).  987ain_minfo_2(How,G):-ain_minfo(How,G).
 mpred_is_info(:TermC) is semidet
PFC If Is A Info.
  994mpred_is_info((AWC,_)):- awc == AWC.
  995mpred_is_info((ZWC,_)):- zwc == ZWC.
  996mpred_is_info(mpred_bc_only(C)):-is_ftNonvar(C),!.
  997mpred_is_info(infoF(C)):-is_ftNonvar(C),!.
  998mpred_is_info(inherit_above(_,_)).
  999mpred_is_info((Fail,_)):-Fail==fail.
 1000
 1001
 1002%:- was_dynamic(not_not/1).
 mpred_rewrap_h(+A, ?A) is semidet
PFC Rewrap Head.
 1008mpred_rewrap_h(A,A):-is_ftNonvar(A),\+ is_static_predicate(A).
 1009mpred_rewrap_h(A,F):- functor(A,F,_),\+ is_static_predicate(F),!.
 1010%mpred_rewrap_h(A,not_not(A)):-!.
 cwc is det
Cwc.
 1017cwc:-true.
 fwc is det
Fwc.
 1023fwc:-true.
 bwc is semidet
Bwc.
 1029bwc:-true.
 1030
 1031awc:-true.
 1032zwc:-true.
 wac is semidet
Wac.
 1038wac:-true.
 is_fc_body(+P) is semidet
If Is A Forward Chaining Body.
 1044is_fc_body(P):- has_body_atom(fwc,P).
 is_bc_body(+P) is semidet
If Is A Backchaining Body.
 1050is_bc_body(P):- has_body_atom(bwc,P).
 is_action_body(+P) is semidet
If Is A Action Body.
 1056is_action_body(P):- has_body_atom(wac,P).
 has_body_atom(+WAC, ?P) is semidet
Has Body Atom.
 1064has_body_atom(WAC,P):- call(
 1065   WAC==P -> true ; (is_ftCompound(P),get_unnegated_head_arg(1,P,E),has_body_atom(WAC,E))),!.
 1066
 1067/*
 1068has_body_atom(WAC,P,Rest):- call(WAC==P -> Rest = true ; (is_ftCompound(P),functor(P,F,A),is_atom_body_pfa(WAC,P,F,A,Rest))).
 1069is_atom_body_pfa(WAC,P,F,2,Rest):-get_unnegated_head_arg(1,P,E),E==WAC,get_unnegated_head_arg(2,P,Rest),!.
 1070is_atom_body_pfa(WAC,P,F,2,Rest):-get_unnegated_head_arg(2,P,E),E==WAC,get_unnegated_head_arg(1,P,Rest),!.
 1071*/
 1072
 1073
 1074same_functors(Head1,Head2):-must_det(get_unnegated_functor(Head1,F1,A1)),must_det(get_unnegated_functor(Head2,F2,A2)),!,F1=F2,A1=A2.
 mpred_update_literal(+P, ?N, ?Q, ?R) is semidet
PFC Update Literal.
 1082mpred_update_literal(P,N,Q,R):-
 1083    get_unnegated_head_arg(N,P,UPDATE),call(replace_arg(P,N,Q_SLOT,Q)),
 1084    must(umt(Q)),update_value(Q_SLOT,UPDATE,NEW), 
 1085    replace_arg(Q,N,NEW,R).
 1086
 1087
 1088% spft(5,5,5).
 1089
 1090% ======================= 
 1091% utils
 1092% ======================= 
 map_literals(+P, ?G) is semidet
Map Literals.
 1098map_literals(P,G):-map_literals(P,G,[]).
 map_literals(+VALUE1, :TermH, ?VALUE3) is semidet
Map Literals.
 1105map_literals(_,H,_):-is_ftVar(H),!. % skip over it
 1106map_literals(_,[],_) :- !.
 1107map_literals(Pred,(H,T),S):-!, apply(Pred,[H|S]), map_literals(Pred,T,S).
 1108map_literals(Pred,[H|T],S):-!, apply(Pred,[H|S]), map_literals(Pred,T,S).
 1109map_literals(Pred,H,S):- mpred_literal(H),must(apply(Pred,[H|S])),!.
 1110map_literals(_Pred,H,_S):- \+ is_ftCompound(H),!. % skip over it
 1111map_literals(Pred,H,S):-H=..List,!,map_literals(Pred,List,S),!.
 map_unless(:PRED1Test, ?Pred, ?H, ?S) is semidet
Map Unless.
 1119map_unless(Test,Pred,H,S):- call(Test,H),ignore(apply(Pred,[H|S])),!.
 1120map_unless(_Test,_,[],_) :- !.
 1121map_unless(_Test,_Pred,H,_S):- \+ is_ftCompound(H),!. % skip over it
 1122map_unless(Test,Pred,(H,T),S):-!, apply(Pred,[H|S]), map_unless(Test,Pred,T,S).
 1123map_unless(Test,Pred,[H|T],S):-!, apply(Pred,[H|S]), map_unless(Test,Pred,T,S).
 1124map_unless(Test,Pred,H,S):-H=..List,!,map_unless(Test,Pred,List,S),!.
 1125
 1126
 1127:- meta_predicate(map_first_arg(:,+)).
 map_first_arg(+Pred, ?List) is semidet
PFC Maptree.
 1132map_first_arg(CM:Pred,List):-map_first_arg(CM,Pred,List,[]).
 1133
 1134:- meta_predicate(map_first_arg(+,*,+,+)).
 map_first_arg(+Pred, :TermH, ?S) is semidet
PFC Maptree.
 1139map_first_arg(CM,Pred,H,S):-is_ftVar(H),!,CM:apply(Pred,[H|S]).
 1140map_first_arg(_,_,[],_) :- !.
 1141map_first_arg(CM,Pred,(H,T),S):-!, map_first_arg(CM,Pred,H,S), map_first_arg(CM,Pred,T,S).
 1142map_first_arg(CM,Pred,(H;T),S):-!, map_first_arg(CM,Pred,H,S) ; map_first_arg(CM,Pred,T,S).
 1143map_first_arg(CM,Pred,[H|T],S):-!, CM:apply(Pred,[H|S]), map_first_arg(CM,Pred,T,S).
 1144map_first_arg(CM,Pred,H,S):- CM:apply(Pred,[H|S]). 
 1145
 1146:- fixup_exports. 1147
 1148% % :- ensure_loaded(logicmoo(util/rec_lambda)).
 1149
 1150%example pfcVerifyMissing(mpred_isa(I,D), mpred_isa(I,C), ((mpred_isa(I,C), {D==C});-mpred_isa(I,C))). 
 1151%example pfcVerifyMissing(mudColor(I,D), mudColor(I,C), ((mudColor(I,C), {D==C});-mudColor(I,C))). 
 pfcVerifyMissing(+GC, ?GO, ?GO) is semidet
Prolog Forward Chaining Verify Missing.
 1158pfcVerifyMissing(GC, GO, ((GO, {D==C});\+ GO) ):-  GC=..[F,A|Args],append(Left,[D],Args),append(Left,[C],NewArgs),GO=..[F,A|NewArgs],!.
 1159
 1160%example mpred_freeLastArg(mpred_isa(I,C),~(mpred_isa(I,C))):-is_ftNonvar(C),!.
 1161%example mpred_freeLastArg(mpred_isa(I,C),(mpred_isa(I,F),C\=F)):-!.
 mpred_freeLastArg(+G, ?GG) is semidet
PFC Free Last Argument.
 1167mpred_freeLastArg(G,GG):- G=..[F,A|Args],append(Left,[_],Args),append(Left,[_],NewArgs),GG=..[F,A|NewArgs],!.
 1168mpred_freeLastArg(_G,false).
 1169
 1170
 1171:- fixup_exports.