:-module(_,[ldiff/3],[]).
'$applied_packages'([prelude,nonpure,condcomp,assertions,regtypes,rtchecks_shallow,predefres(res_steps),resdefs,resdefs/resources_decl,nativeprops,basicmodes,argnames,expander]).
:-add_clause_trans(expander_tr:expand_clause/4,9910).
:-prop listgnd/1+regtype.
:-entry ldiff(_A,_B,_C):(list(_A,gnd),list(_B,gnd),var(_C)).
:-check calls ldiff(A,B,C):(listgnd(A),listgnd(B),var(C)).
:-true success ldiff(A,B,C):(listgnd(A),listgnd(B),var(C))=>listgnd(C).
:-true pred ldiff(A,B,C):(list(A,gnd),list(B,gnd),term(C))=>(list(A,gnd),list(B,gnd),list(C,gnd)).
:-true pred ldiff(A,B,C):(mshare([[C]]),var(C),ground([A,B]))=>ground([A,B,C]).
:-checked calls ldiff_i(A,B,C):(listgnd(A),listgnd(B),var(C)).
:-checked success ldiff_i(A,B,C):(listgnd(A),listgnd(B),var(C))=>listgnd(C).
:-true pred ldiff_i(A,B,C):(list(A,gnd),list(B,gnd),term(C))=>(list(A,gnd),list(B,gnd),list(C,gnd)).
:-true pred ldiff_i(A,B,C):(mshare([[C]]),var(C),ground([A,B]))=>ground([A,B,C]).
:-checked calls memberchk(A,B):(gnd(B),listgnd(B)).
:-true pred memberchk(A,B):(gnd(A),list(B,gnd))=>(gnd(A),rt2(B)).
:-true pred memberchk(A,B):ground([A,B])=>ground([A,B]).
:-prop listgnd(_A)+regtype.
:-prop rt2/1+regtype.

ldiff(_1,_2,_3) :-
        'ldiff$pre'(_1,_2,_3),
        'ldiff$cls'(_1,_2,_3).
'ldiff$pre'(_1,_2,_3) :-
        reify_check(listgnd(_1),[_1],_7),
        reify_check(listgnd(_2),[_2],_8),
        reify_check(var(_3),[_3],_4),
        reify_check(list(_1,gnd),[_1,gnd],_5),
        reify_check(list(_2,gnd),[_2,gnd],_6),
        _10 is _4/\(_5/\_6),
        _9 is _4/\(_7/\_8),
        _11 is _9,
        _12 is _10,
        _13 is _11\/_12,
        warn_if_false(_13,'CP').
'ldiff$cls'(A,B,C) :-
        ldiff_i(A,B,C).
ldiff_i([],_L,[]).
ldiff_i([H|L1],L2,L3) :-
        memberchk(H,L2),
        !,
        ldiff_i(L1,L2,L3).
ldiff_i([H|L1],L2,[H|L3]) :-
        ldiff_i(L1,L2,L3).
memberchk(X,[X|_1]) :-
        !.
memberchk(X,[_1|L]) :-
        memberchk(X,L).
listgnd([]).
listgnd([E|T]) :-
        gnd(E),
        listgnd(T).
rt2([A|B]) :-
        gnd(A),
        list(B,gnd).