82 fun formula_from_atom r = RelEq (r, true_atom) |
82 fun formula_from_atom r = RelEq (r, true_atom) |
83 (* formula -> rel_expr *) |
83 (* formula -> rel_expr *) |
84 fun atom_from_formula f = RelIf (f, true_atom, false_atom) |
84 fun atom_from_formula f = RelIf (f, true_atom, false_atom) |
85 |
85 |
86 (* Proof.context -> (typ -> int) -> styp list -> term -> formula *) |
86 (* Proof.context -> (typ -> int) -> styp list -> term -> formula *) |
87 fun kodkod_formula_for_term ctxt card frees = |
87 fun kodkod_formula_from_term ctxt card frees = |
88 let |
88 let |
89 (* typ -> rel_expr -> rel_expr *) |
89 (* typ -> rel_expr -> rel_expr *) |
90 fun R_rep_from_S_rep (T as Type ("fun", [T1, @{typ bool}])) r = |
90 fun R_rep_from_S_rep (T as Type ("fun", [T1, @{typ bool}])) r = |
91 let |
91 let |
92 val jss = atom_schema_of SRep card T1 |> map (rpair 0) |
92 val jss = atom_schema_of SRep card T1 |> map (rpair 0) |
143 | t1 $ t2 => Subset (to_S_rep Ts t2, to_R_rep Ts t1) |
143 | t1 $ t2 => Subset (to_S_rep Ts t2, to_R_rep Ts t1) |
144 | Free _ => raise SAME () |
144 | Free _ => raise SAME () |
145 | Term.Var _ => raise SAME () |
145 | Term.Var _ => raise SAME () |
146 | Bound _ => raise SAME () |
146 | Bound _ => raise SAME () |
147 | Const (s, _) => raise NOT_SUPPORTED ("constant " ^ quote s) |
147 | Const (s, _) => raise NOT_SUPPORTED ("constant " ^ quote s) |
148 | _ => raise TERM ("Minipick.kodkod_formula_for_term.to_F", [t])) |
148 | _ => raise TERM ("Minipick.kodkod_formula_from_term.to_F", [t])) |
149 handle SAME () => formula_from_atom (to_R_rep Ts t) |
149 handle SAME () => formula_from_atom (to_R_rep Ts t) |
150 (* typ list -> term -> rel_expr *) |
150 (* typ list -> term -> rel_expr *) |
151 and to_S_rep Ts t = |
151 and to_S_rep Ts t = |
152 case t of |
152 case t of |
153 Const (@{const_name Pair}, _) $ t1 $ t2 => |
153 Const (@{const_name Pair}, _) $ t1 $ t2 => |
304 val _ = fold_types (K o check_type ctxt) neg_t () |
304 val _ = fold_types (K o check_type ctxt) neg_t () |
305 val frees = Term.add_frees neg_t [] |
305 val frees = Term.add_frees neg_t [] |
306 val bounds = map2 (bound_for_free card) (index_seq 0 (length frees)) frees |
306 val bounds = map2 (bound_for_free card) (index_seq 0 (length frees)) frees |
307 val declarative_axioms = |
307 val declarative_axioms = |
308 map2 (declarative_axiom_for_free card) (index_seq 0 (length frees)) frees |
308 map2 (declarative_axiom_for_free card) (index_seq 0 (length frees)) frees |
309 val formula = kodkod_formula_for_term ctxt card frees neg_t |
309 val formula = kodkod_formula_from_term ctxt card frees neg_t |
310 |> fold_rev (curry And) declarative_axioms |
310 |> fold_rev (curry And) declarative_axioms |
311 val univ_card = univ_card 0 0 0 bounds formula |
311 val univ_card = univ_card 0 0 0 bounds formula |
312 val problem = |
312 val problem = |
313 {comment = "", settings = [], univ_card = univ_card, tuple_assigns = [], |
313 {comment = "", settings = [], univ_card = univ_card, tuple_assigns = [], |
314 bounds = bounds, int_bounds = [], expr_assigns = [], formula = formula} |
314 bounds = bounds, int_bounds = [], expr_assigns = [], formula = formula} |