rewrite_finite_card(less(Card,Integer), Res, card_to_at_least_one_eq) :-
% card({a1,..,ak}) < k --> at least one eq (has n*log(n) disjuncts)
rewrite_finite_card_k_less_k(Card, Integer, Res).
rewrite_finite_card(greater(Integer,Card), Res, card_to_at_least_one_eq) :-
% k > card({a1,..,ak}) --> at least one eq (has n*log(n) disjuncts)
rewrite_finite_card_k_less_k(Card, Integer, Res).
rewrite_finite_card(less_equal(Card,Integer), Res, card_to_at_least_one_eq) :-
% card({a1,..,ak}) <= k - 1 --> at least one eq (has n*log(n) disjuncts)
rewrite_finite_card_k_leq_k_minus_1(Card, Integer, Res).
rewrite_finite_card(greater_equal(Integer,Card), Res, card_to_at_least_one_eq) :-
% k - 1 >= card({a1,..,ak}) --> at least one eq (has n*log(n) disjuncts)
rewrite_finite_card_k_leq_k_minus_1(Card, Integer, Res).
rewrite_finite_card(less_equal(Card,Integer), Res, card_to_truth_leq_k) :-
% card({a1,..,ak}) <= k --> truth
rewrite_finite_card_k_leq_k(Card, Integer, Res).
rewrite_finite_card(greater_equal(Integer,Card), Res, card_to_truth_leq_k) :-
% k >= card({a1,..,ak}) --> truth
rewrite_finite_card_k_leq_k(Card, Integer, Res).
rewrite_finite_card(less(Card,Integer), Res, card_to_truth_leq_k1) :-
% card({a1,..,ak}) < k + 1 --> truth
rewrite_finite_card_k_leq_k_plus_1(Card, Integer, Res).
rewrite_finite_card(greater(Integer,Card), Res, card_to_truth_leq_k1) :-
% k + 1 > card({a1,..,ak}) --> truth
rewrite_finite_card_k_leq_k_plus_1(Card, Integer, Res).
rewrite_finite_card(greater_equal(Card,Integer), Res, card_to_all_different_greater_eq) :-
% card({a1,..,ak}) >= k --> all_different
rewrite_finite_card_k_eq_k(Card, Integer, Res).
rewrite_finite_card(less_equal(Integer,Card), Res, card_to_all_different_greater_eq) :-
% k <= card({a1,..,ak}) --> all_different
rewrite_finite_card_k_eq_k(Card, Integer, Res).
rewrite_finite_card(greater(Card,Integer), Res, card_to_falsity) :-
% card({a1,..,ak}) > n --> falsity if n>=k
rewrite_finite_card_greater_less_k(Card, Integer, Res).
rewrite_finite_card(less(Integer,Card), Res, card_to_falsity) :-
% n < card({a1,..,ak}) --> falsity if n>=k
rewrite_finite_card_greater_less_k(Card, Integer, Res).
rewrite_finite_card(greater_equal(Card,Integer), Res, card_to_falsity) :-
% card({a1,..,ak}) >= n --> falsity if n>k
rewrite_finite_card_greatereq_lesseq_n(Card, Integer, Res).
rewrite_finite_card(less_equal(Integer,Card), Res, card_to_falsity) :-
% n <= card({a1,..,ak}) --> falsity if n>k
rewrite_finite_card_greatereq_lesseq_n(Card, Integer, Res).
rewrite_finite_card(greater(Card,Integer), Res, card_to_all_different_greater) :-
% card({a1,..,ak}) > k - 1 --> all different
rewrite_finite_card_greater_less_k1(Card, Integer, Res).
rewrite_finite_card(less(Integer,Card), Res, card_to_all_different_greater) :-
% k - 1 < card({a1,..,ak}) --> all different
rewrite_finite_card_greater_less_k1(Card, Integer, Res).
rewrite_finite_card(greater_equal(Card,Integer1), Res, card_to_truth) :-
% card({a1,..,ak}) >= 1 --> truth
rewrite_finite_card_geq_leq_1(Card, Integer1, Res).
rewrite_finite_card(less_equal(Integer1,Card), Res, card_to_truth) :-
% 1 <= card({a1,..,ak}) --> truth
rewrite_finite_card_geq_leq_1(Card, Integer1, Res).
rewrite_finite_card(equal(Card,Integer), Res, card_to_single_equality) :-
% card({a1,a2}) = 1 --> a1=a2
rewrite_finite_card_2_eq_1(Card, Integer, Res).
rewrite_finite_card(equal(Integer,Card), Res, card_to_single_equality) :-
% 1 = card({a1,a2}) --> a1=a2
rewrite_finite_card_2_eq_1(Card, Integer, Res).
rewrite_finite_card(not_equal(Card,Integer), Res, card_to_single_non_equality) :-
% card({a1,a2}) /= 1 --> a1/=a2
rewrite_finite_card_2_neq_1(Card, Integer, Res).
rewrite_finite_card(not_equal(Integer,Card), Res, card_to_single_non_equality) :-
% 1 /= card({a1,a2}) --> a1/=a2
rewrite_finite_card_2_neq_1(Card, Integer, Res).
rewrite_finite_card(equal(Card,Integer), Res, card_to_falsity_nonempty_eq_zero) :-
% card({a1,..,ak}) = 0 --> falsity
rewrite_finite_card_eq_0(Card, Integer, Res).
rewrite_finite_card(equal(Integer,Card), Res, card_to_falsity_nonempty_eq_zero) :-
% card({a1,..,ak}) = 0 --> falsity
rewrite_finite_card_eq_0(Card, Integer, Res).
rewrite_finite_card(equal(Card,Integer), Res, card_to_all_different_eq_k) :-
% card({a1,..,ak}) = k --> all different
rewrite_finite_card_k_eq_k(Card, Integer, Res).
rewrite_finite_card(equal(Integer,Card), Res, card_to_all_different_eq_k) :-
% k = card({a1,..,ak}) --> all different
rewrite_finite_card_k_eq_k(Card, Integer, Res).
rewrite_finite_card(greater_equal(Card,Integer), Res, card_to_all_different_geq_k) :-
% card({a1,..,ak}) >= k --> all different
rewrite_finite_card_k_eq_k(Card, Integer, Res).
rewrite_finite_card(less_equal(Integer,Card), Res, card_to_all_different_geq_k) :-
% k >= card({a1,..,ak}) --> all different
rewrite_finite_card_k_eq_k(Card, Integer, Res).