Skip to content

Commit

Permalink
canary-90 metta_eq_def
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Aug 20, 2024
1 parent 82d0920 commit 8c9b830
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
22 changes: 11 additions & 11 deletions src/canary/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,11 @@
eval_args(Eq,RetType,Depth,Self,Template,Res).

%metta_atom_iter(Eq,_Depth,_Slf,Other,[Equal,[F|H],B]):- Eq == Equal,!, % trace,
% metta_defn(Eq,Other,[F|H],B).
% metta_eq_def(Eq,Other,[F|H],B).

/*
metta_atom_iter(Eq,Depth,Self,Other,[Equal,[F|H],B]):- Eq == Equal,!, % trace,
metta_defn(Eq,Other,[F|H],BB),
metta_eq_def(Eq,Other,[F|H],BB),
eval_sometimes(Eq,_RetType,Depth,Self,B,BB).
*/

Expand All @@ -708,9 +708,9 @@
into_space(Depth,Self,Other,Space),
metta_atom(Space,H).
% is this OK?
%metta_atom_true(Eq,Depth,Self,Other,H):- nonvar(H), metta_defn(Eq,Other,H,B), D2 is Depth -1, eval_args_true(Eq,_,D2,Self,B).
%metta_atom_true(Eq,Depth,Self,Other,H):- nonvar(H), metta_eq_def(Eq,Other,H,B), D2 is Depth -1, eval_args_true(Eq,_,D2,Self,B).
% is this OK?
%metta_atom_true(Eq,Depth,Self,Other,H):- Other\==Self, nonvar(H), metta_defn(Eq,Other,H,B), D2 is Depth -1, eval_args_true(Eq,_,D2,Other,B).
%metta_atom_true(Eq,Depth,Self,Other,H):- Other\==Self, nonvar(H), metta_eq_def(Eq,Other,H,B), D2 is Depth -1, eval_args_true(Eq,_,D2,Other,B).



Expand Down Expand Up @@ -1348,8 +1348,8 @@
eval_20(Eq,RetType,Depth,Self,['xor',X,Y],TF):- !,
as_tf( (eval_args_true(Eq,RetType,Depth,Self,X)), XTF), % evaluate X
as_tf( (eval_args_true(Eq,RetType,Depth,Self,Y)), YTF), % evaluate Y
as_tf( (bool_xor(XTF,YTF)) , TF).
as_tf( (bool_xor(XTF,YTF)) , TF).


eval_20(Eq,RetType,Depth,Self,['not',X],TF):- !,
as_tf(( \+ eval_args_true(Eq,RetType,Depth,Self,X)), TF).
Expand Down Expand Up @@ -1670,7 +1670,7 @@
lazy_findall(E2, Call2, List2),
% Step 3: Perform the subtraction logic
% Only return E1 if it is not a member of List2
\+ (member(E2, List2), E1 = E2).
\+ (member(E2, List2), E1 =@= E2).


eval_20(Eq,RetType,Depth,Self,PredDecl,Res):-
Expand Down Expand Up @@ -2191,7 +2191,7 @@
findall((XX->B0),get_defn_expansions(Eq,RetType,Depth,Self,X,XX,B0),XXB0L),
XXB0L\=[],!,
Depth2 is Depth-1,
if_trace((metta_defn),
if_trace((defn;metta_defn),
maplist(print_templates(Depth,' '),XXB0L)),!,
member(XX->B0,XXB0L), X=XX, Y=B0, X\=@=B0,
%(X==B0 -> trace; eval_args(Eq,RetType,Depth,Self,B0,Y)).
Expand All @@ -2208,20 +2208,20 @@
same_len_copy(Args,NewArgs):- length(Args,N),length(NewArgs,N).

get_defn_expansions(Eq,_RetType,_Depth,Self,[H|Args],[H|NewArgs],B0):- same_len_copy(Args,NewArgs),
metta_defn(Eq,Self,[H|NewArgs],B0).
metta_eq_def(Eq,Self,[H|NewArgs],B0).

get_defn_expansions(Eq,RetType,Depth,Self,[[H|Start]|T1],[[H|NewStart]|NewT1],[Y|T1]):- is_list(Start),
same_len_copy(Start,NewStart),
X = [H|NewStart],
findall((XX->B0),get_defn_expansions(Eq,RetType,Depth,Self,X,XX,B0),XXB0L),
XXB0L\=[], if_trace((metta_defn;eval_args),maplist(print_templates(Depth,'curry 1'),XXB0L)),!,
XXB0L\=[], if_trace((defn;metta_defn;eval_args),maplist(print_templates(Depth,'curry 1'),XXB0L)),!,
member(XX->B0,XXB0L), X=XX, Y=B0, X\=@=B0,
light_eval(Eq,RetType,Depth,Self,B0,Y),
same_len_copy(T1,NewT1).

get_defn_expansions(Eq,RetType,Depth,Self,[[H|Start]|T1],RW,Y):- is_list(Start), append(Start,T1,Args),
get_defn_expansions(Eq,RetType,Depth,Self,[H|Args],RW,Y),
if_trace((metta_defn;eval_args),indentq_d(Depth,'curry 2 ', [[[H|Start]|T1] ,'----->', RW])).
if_trace((defn;metta_defn;eval_args),indentq_d(Depth,'curry 2 ', [[[H|Start]|T1] ,'----->', RW])).

print_templates(Depth,_T,guarded_defn(Types,XX,B0)):-!,
Depth2 is Depth+2,
Expand Down
21 changes: 12 additions & 9 deletions src/canary/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@
start_html_of(_Filename):-
must_det_ll((
S = _,
%retractall(metta_defn(Eq,S,_,_)),
%retractall(metta_eq_def(Eq,S,_,_)),
nop(retractall(metta_type(S,_,_))),
%retractall(get_metta_atom(Eq,S,_,_,_)),
loonit_reset,
Expand Down Expand Up @@ -819,7 +819,7 @@
clear_spaces:- clear_space(_).
clear_space(S):-
retractall(user:loaded_into_kb(S,_)),
%retractall(metta_defn(_,S,_,_)),
%retractall(metta_eq_def(_,S,_,_)),
nop(retractall(metta_type(S,_,_))),
retractall(metta_atom_asserted(S,_)).

Expand Down Expand Up @@ -895,7 +895,7 @@
is_metta_data_functor(Eq,Other,H):-
metta_type(Other,H,_),
\+ get_metta_atom(Eq,Other,[H|_]),
\+ metta_defn(Eq,Other,[H|_],_).
\+ metta_eq_def(Eq,Other,[H|_],_).
*/
is_function(F):- symbol(F).

Expand Down Expand Up @@ -989,7 +989,8 @@
catch(rtrace(G),E,throw(give_up(E=G))),
throw(E))).

assertion_hb(metta_defn(Eq,Self,H,B),Self,Eq,H,B):-!.
assertion_hb(metta_eq_def(Eq,Self,H,B),Self,Eq,H,B):-!.
assertion_hb(metta_defn(Self,H,B),Self,'=',H,B):-!.
assertion_hb(metta_atom_asserted(KB,HB),Self,Eq,H,B):- !, assertion_hb(metta_atom(KB,HB),Self,Eq,H,B).
assertion_hb(metta_atom(Self,[Eq,H,B]),Self,Eq,H,B):- assert_type_cl(Eq),!.
assertion_hb(metta_atom(Self,[Eq,H|B]),Self,Eq,H,B):- assert_type_cl(Eq),!.
Expand Down Expand Up @@ -1068,15 +1069,17 @@
%metta_atom(KB,[F,A|List]):- metta_atom(KB,F,A,List), F \== '=',!.
is_metta_space(Space):- \+ \+ is_space_type(Space,_Test).

metta_defn(KB,Head,Body):- metta_defn(_Eq,KB,Head,Body).
metta_defn(Eq,KB,Head,Body):- ignore(Eq = '='), metta_atom(KB,[Eq,Head,Body]).
metta_eq_def(Eq,KB,Head,Body):- ignore(Eq = '='), metta_atom(KB,[Eq,Head,Body]).

metta_defn(KB,Head,Body):- metta_eq_def(_Eq,KB,Head,Body).
metta_type(KB,H,B):- if_or_else(metta_atom(KB,[':',H,B]),metta_atom_corelib([':',H,B])).
%metta_type(S,H,B):- S == '&corelib', metta_atom_stdlib_types([':',H,B]).
%typed_list(Cmpd,Type,List):- compound(Cmpd), Cmpd\=[_|_], compound_name_arguments(Cmpd,Type,[List|_]),is_list(List).


%maybe_xform(metta_atom(KB,[F,A|List]),metta_atom(KB,F,A,List)):- is_list(List),!.
maybe_xform(metta_defn(Eq,KB,Head,Body),metta_atom(KB,[Eq,Head,Body])).
maybe_xform(metta_eq_def(Eq,KB,Head,Body),metta_atom(KB,[Eq,Head,Body])).
maybe_xform(metta_defn(KB,Head,Body),metta_atom(KB,['=',Head,Body])).
maybe_xform(metta_type(KB,Head,Body),metta_atom(KB,[':',Head,Body])).
maybe_xform(metta_atom(KB,HeadBody),metta_atom_asserted(KB,HeadBody)).
maybe_xform(_OBO,_XForm):- !, fail.
Expand Down Expand Up @@ -1215,15 +1218,15 @@
*/
/*do_metta(File,Self,Load,PredDecl, Src):-fail,
metta_anew(Load,Src,metta_atom(Self,PredDecl)),
ignore((PredDecl=['=',Head,Body], metta_anew(Load,Src,metta_defn(Eq,Self,Head,Body)))),
ignore((PredDecl=['=',Head,Body], metta_anew(Load,Src,metta_eq_def(Eq,Self,Head,Body)))),
ignore((Body == 'True',!,do_metta(File,Self,Load,Head))),
nop((fn_append(Head,X,Head), fn_append(PredDecl,X,Body),
metta_anew((Head:- Body)))),!.*/
/*
asserted_do_metta2(Self,Load,[EQ,Head,Result], Src):- EQ=='=', !,
color_g_mesg_ok('#ffa504',must_det_ll((
discover_head(Self,Load,Head),
metta_anew(Load,Src,metta_defn(EQ,Self,Head,Result)),
metta_anew(Load,Src,metta_eq_def(EQ,Self,Head,Result)),
discover_body(Self,Load,Result)))).
*/
asserted_do_metta2(Self,Load,PredDecl, Src):-
Expand Down
26 changes: 13 additions & 13 deletions src/canary/metta_subst.pl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
subst_args_as(Depth,Self,['get-atoms',Other],PredDecl):- !,into_space(Self,Other,Space), metta_atom_iter_l1t(Eq,Depth,Space,PredDecl).
subst_args_as(_Dpth,Self,['add-atom',Other,PredDecl],TF):- !, into_space(Self,Other,Space), as_tf(do_metta(Space,load,PredDecl),TF).
subst_args_as(_Dpth,Self,['remove-atom',Other,PredDecl],TF):- !, into_space(Self,Other,Space), as_tf(do_metta(Space,unload,PredDecl),TF).
subst_args_as(_Dpth,Self,['atom-count',Other],Count):- !, into_space(Self,Other,Space), findall(_,metta_defn(Eq,Other,_,_),L_as),length(L_as,C_as),findall(_,get_metta_atom(Eq,Space,_),L2),length(L2,C2),Count is C_as+C2.
subst_args_as(_Dpth,Self,['atom-count',Other],Count):- !, into_space(Self,Other,Space), findall(_,metta_eq_def(Eq,Other,_,_),L_as),length(L_as,C_as),findall(_,get_metta_atom(Eq,Space,_),L2),length(L2,C2),Count is C_as+C2.
subst_args_as(_Dpth,Self,['atom-replace',Other,Rem,Add],TF):- !, into_space(Self,Other,Space), copy_term(Rem,RCopy),
as_tf((metta_atom_iter_l1t_ref(Space,RCopy,Ref), RCopy=@=Rem,erase(Ref), do_metta(Other,load,Add)),TF).

Expand Down Expand Up @@ -798,7 +798,7 @@
%is_user_defined_head_f1(Eq,Other,H):- metta_type(Other,H,_).
is_user_defined_head_f1(Eq,Other,H):- get_metta_atom(Eq,Other,[H|_]).
is_user_defined_head_f1(Eq,Other,H):- metta_defn(Eq,Other,[H|_],_).
is_user_defined_head_f1(Eq,Other,H):- metta_eq_def(Eq,Other,[H|_],_).
%is_user_defined_head_f(Eq,_,H):- is_metta_builtin(H).
Expand Down Expand Up @@ -845,7 +845,7 @@

subst_args30(Eq,Depth,Self,H,B):- (subst_args34(Depth,Self,H,B)*->true;subst_args37(Eq,Depth,Self,H,B)).

subst_args34(_Dpth,Self,H,B):- (metta_defn(Eq,Self,H,B);(get_metta_atom(Eq,Self,H),B=H)).
subst_args34(_Dpth,Self,H,B):- (metta_eq_def(Eq,Self,H,B);(get_metta_atom(Eq,Self,H),B=H)).

% Has argument that is headed by the same function
subst_args37(Eq,Depth,Self,[H1|Args],Res):-
Expand All @@ -856,7 +856,7 @@

subst_args37(Eq,Depth,Self,[[H|Start]|T1],Y):-
mnotrace((is_user_defined_head_f(Eq,Self,H),is_list(Start))),
metta_defn(Eq,Self,[H|Start],Left),
metta_eq_def(Eq,Self,[H|Start],Left),
subst_args(Eq,RetType,Depth,Self,[Left|T1],Y).

% Has subterm to subst
Expand All @@ -877,31 +877,31 @@
PredDecl\=@=Res.

subst_args38(Eq,_Dpth,Self,[H|_],_):- mnotrace( \+ is_user_defined_head_f(Eq,Self,H) ), !,fail.
subst_args38(Eq,_Dpth,Self,[H|T1],Y):- metta_defn(Eq,Self,[H|T1],Y).
subst_args38(Eq,_Dpth,Self,[H|T1],Y):- metta_eq_def(Eq,Self,[H|T1],Y).
subst_args38(Eq,_Dpth,Self,[H|T1],'True'):- get_metta_atom(Eq,Self,[H|T1]).
subst_args38(Eq,_Dpth,Self,CALL,Y):- fail,append(Left,[Y],CALL),metta_defn(Eq,Self,Left,Y).
subst_args38(Eq,_Dpth,Self,CALL,Y):- fail,append(Left,[Y],CALL),metta_eq_def(Eq,Self,Left,Y).


%subst_args3(Depth,Self,['ift',CR,Then],RO):- fail, !, %fail, % trace,
% metta_defn(Eq,Self,['ift',R,Then],Become),subst_args(Eq,RetType,Depth,Self,CR,R),subst_args(Eq,RetType,Depth,Self,Then,_True),subst_args(Eq,RetType,Depth,Self,Become,RO).
% metta_eq_def(Eq,Self,['ift',R,Then],Become),subst_args(Eq,RetType,Depth,Self,CR,R),subst_args(Eq,RetType,Depth,Self,Then,_True),subst_args(Eq,RetType,Depth,Self,Become,RO).

metta_atom_iter_l1t(Eq,_Dpth,Other,[Equal,H,B]):- Eq == Equal,!,
(metta_defn(Eq,Other,H,B)*->true;(get_metta_atom(Eq,Other,H),B=H)).
(metta_eq_def(Eq,Other,H,B)*->true;(get_metta_atom(Eq,Other,H),B=H)).

metta_atom_iter_l1t(Eq,Depth,_,_):- Depth<3,!,fail.
metta_atom_iter_l1t(Eq,_Dpth,_Slf,[]):-!.
metta_atom_iter_l1t(Eq,_Dpth,Other,H):- get_metta_atom(Eq,Other,H).
metta_atom_iter_l1t(Eq,Depth,Other,H):- D2 is Depth -1, metta_defn(Eq,Other,H,B),metta_atom_iter_l1t(Eq,D2,Other,B).
metta_atom_iter_l1t(Eq,Depth,Other,H):- D2 is Depth -1, metta_eq_def(Eq,Other,H,B),metta_atom_iter_l1t(Eq,D2,Other,B).
metta_atom_iter_l1t(Eq,_Dpth,_Slf,[And]):- is_and(And),!.
metta_atom_iter_l1t(Eq,Depth,Self,[And,X|Y]):- is_and(And),!,D2 is Depth -1, metta_atom_iter_l1t(Eq,D2,Self,X),metta_atom_iter_l1t(Eq,D2,Self,[And|Y]).
/*
metta_atom_iter_l1t2(_,Self,[=,X,Y]):- metta_defn(Eq,Self,X,Y).
metta_atom_iter_l1t2(_Dpth,Other,[Equal,H,B]):- '=' == Equal,!, metta_defn(Eq,Other,H,B).
metta_atom_iter_l1t2(_Dpth,Self,X,Y):- metta_defn(Eq,Self,X,Y). %, Y\=='True'.
metta_atom_iter_l1t2(_,Self,[=,X,Y]):- metta_eq_def(Eq,Self,X,Y).
metta_atom_iter_l1t2(_Dpth,Other,[Equal,H,B]):- '=' == Equal,!, metta_eq_def(Eq,Other,H,B).
metta_atom_iter_l1t2(_Dpth,Self,X,Y):- metta_eq_def(Eq,Self,X,Y). %, Y\=='True'.
metta_atom_iter_l1t2(_Dpth,Self,X,Y):- get_metta_atom(Eq,Self,[=,X,Y]). %, Y\=='True'.
*/
metta_atom_iter_l1t_ref(Other,['=',H,B],Ref):-clause(metta_defn(Eq,Other,H,B),true,Ref).
metta_atom_iter_l1t_ref(Other,['=',H,B],Ref):-clause(metta_eq_def(Eq,Other,H,B),true,Ref).
metta_atom_iter_l1t_ref(Other,H,Ref):-clause(get_metta_atom(Eq,Other,H),true,Ref).

%not_compound(Term):- \+ is_list(Term),!.
Expand Down
8 changes: 4 additions & 4 deletions src/canary/metta_types.pl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
is_metta_data_functor(Eq,Other,H):- H\=='Right', H\=='Something',
% metta_type(Other,H,_), % fail,
\+ get_metta_atom(Eq,Other,[H|_]),
\+ metta_defn(Eq,Other,[H|_],_),
\+ metta_eq_def(Eq,Other,[H|_],_),
\+ is_metta_builtin(H),
\+ is_comp_op(H,_),
\+ is_math_op(H,_,_).
Expand Down Expand Up @@ -456,7 +456,7 @@
throw_metta_return(L):-
asserta(thrown_metta_return(L)),
(throw(metta_return(L))).


into_typed_args(_Dpth,_Slf,T,M,Y):- (\+ iz_conz(T); \+ iz_conz(M)),!, M=Y.
into_typed_args(Depth,Self,[T|TT],[M|MM],[Y|YY]):-
Expand All @@ -478,7 +478,7 @@
wants_eval_kind(T):- nonvar(T), is_pro_eval_kind(T),!.
wants_eval_kind(_):- true.

metta_type:attr_unify_hook(Self=TypeList,NewValue):-
metta_type:attr_unify_hook(Self=TypeList,NewValue):-
attvar(NewValue),!,put_attr(NewValue,metta_type,Self=TypeList).
metta_type:attr_unify_hook(Self=TypeList,NewValue):-
get_type(20,Self,NewValue,Was),
Expand Down Expand Up @@ -598,7 +598,7 @@
%is_user_defined_head_f1(Eq,Other,H):- metta_type(Other,H,_).
%s_user_defined_head_f1(Other,H):- get_metta_atom(Eq,Other,[H|_]).
is_user_defined_head_f1(Other,H):- is_user_defined_head_f1(=,Other,H).
is_user_defined_head_f1(Eq,Other,H):- metta_defn(Eq,Other,[H|_],_).
is_user_defined_head_f1(Eq,Other,H):- metta_eq_def(Eq,Other,[H|_],_).
%is_user_defined_head_f(Eq,_,H):- is_metta_builtin(H).


Expand Down

0 comments on commit 8c9b830

Please sign in to comment.