
ord_union([],Set2,Set2).
ord_union([H1|T1],Set2,Union) :- 
    ord_union_2(Set2,H1,T1,Union).

ord_union_2([],H1,T1,[H1|T1]).
ord_union_2([H2|T2],H1,T1,Union)  :-
    compare(Order,H1,H2),
    ord_union_3(Order,H1,T1,H2,T2,Union).

ord_union_3(<,H1,T1,H2,T2,[H1|Union]) :-
    ord_union_2(T1,H2,T2,Union).
ord_union_3(=,H1,T1,_,T2,[H1|Union]) :-
    ord_union(T1,T2,Union).
ord_union_3(>,H1,T1,H2,T2,[H2|Union]) :-
    ord_union_2(T2,H1,T1,Union).
