--- a/trunk/Toss/Solver/Structure.ml
+++ b/trunk/Toss/Solver/Structure.ml
@@ -425,27 +425,34 @@
   end
 
 (* Add to a named structure elements, relations and functions from the lists. *)
-let add_from_lists struc els rels funs =
-  List.fold_left (fun s (fn, assgns) ->
+let add_from_lists struc els rels_consts funs =
+  let rels, csts = ref [], ref [] in
+  List.iter (function 
+  | Aux.Left r -> rels := r :: !rels 
+  | Aux.Right c -> csts := c :: !csts) rels_consts;
+  let rels, csts = List.rev !rels, List.rev !csts in
+  let add_funs s (fn, assgns) =
     List.fold_left (fun s (ne, x) ->
       let s, e = find_or_new_elem s ne in
-      add_fun s fn (e, x))
-      s assgns)
-    (List.fold_left (fun s (rn, arity, tps) ->
-      let arity = match arity with
-        | None ->
-          if tps = [] then raise (
-            Structure_mismatch
-              ("Structure.add_from_lists: relation of undetermined arity: " ^
-		  rn))
-          else Array.length (List.hd tps)
-        | Some ar -> ar in
-      let s = add_rel_name rn arity s in
-      List.fold_left (fun s tp ->
-        let s, tp = array_fold_map find_or_new_elem s tp in
-        add_rel s rn tp) s tps)
-       (List.fold_left (fun s ne ->
-         fst (find_or_new_elem s ne)) struc els) rels) funs
+      add_fun s fn (e, x)) s assgns in
+  let add_rels s (rn, arity, tps) =
+    let arity = match arity with
+      | None ->
+        if tps = [] then raise (
+          Structure_mismatch
+            ("Structure.add_from_lists: relation of undetermined arity: " ^ rn))
+        else Array.length (List.hd tps)
+      | Some ar -> ar in
+    let s = add_rel_name rn arity s in
+    List.fold_left (fun s tp ->
+      let s, tp = array_fold_map find_or_new_elem s tp in
+      add_rel s rn tp) s tps in
+  let add_cst s (c, e) = 
+    let s, e = find_or_new_elem s e in
+    { s with constants = Aux.unique_sorted ((c, e) :: s.constants) } in
+  let add_elem s ne = fst (find_or_new_elem s ne) in
+  List.fold_left add_funs (List.fold_left add_rels (
+    List.fold_left add_cst (List.fold_left add_elem struc els) csts) rels) funs
 
 let create_from_lists ?struc els rels funs =
   let struc = match struc with
@@ -454,7 +461,7 @@
   add_from_lists struc els rels funs
 
 let circle_structure rx ry = 
-  create_from_lists ["e"] [("Circle", None, [[|"e"|]])]
+  create_from_lists ["e"] [Aux.Left ("Circle", None, [[|"e"|]])]
     [("rx", [("e", rx)]); ("ry", [("e", ry)]);
      ("x", [("e", 0.)]); ("y", [("e", 0.)])]
 
@@ -634,70 +641,17 @@
 
 (* Helper function: omit k first characters of s. *)
 let omit k s = 
-  let l = String.length s in 
-    if l > k then String.sub s k (l - k) else ""
+  let l = String.length s in if l > k then String.sub s k (l - k) else ""
 
 (* Print the element [e] as string. *)
-let elem_str struc e =
-  try IntMap.find e struc.inv_names
+let elem_str struc e = try IntMap.find e struc.inv_names
   with Not_found -> string_of_int e
-
 
 (* Print the tuple [tp] as string. *)
 let tuple_str ?(with_paren=true) struc tp =
-  if Array.length tp = 1 && not with_paren
-  then elem_str struc tp.(0)
-  else
+  if Array.length tp = 1 && not with_paren then elem_str struc tp.(0) else
     "(" ^ (String.concat ", "
              (Array.to_list (Array.map (elem_str struc) tp))) ^ ")"
-
-(* Print the relation named [rel_name] with tuples [ts] as string. *)
-let rel_str ?(print_arity=true) struc rel_name ts =
-  let tup_s = Tuples.fold (fun t s -> s ^ "; " ^
-    (tuple_str ~with_paren:false struc t)) ts "" in
-  if print_arity && Tuples.is_empty ts then
-    Printf.sprintf "%s:%d {}" rel_name
-      (StringMap.find rel_name struc.rel_signature)
-  else if Tuples.cardinal ts = 1 then
-    rel_name ^ " " ^ tuple_str ~with_paren:true struc
-      (Tuples.choose ts)
-  else
-    rel_name ^ " {" ^ omit 2 tup_s ^ "}"
-
-(* Print the function named [fun_name] with values [vals] as string. *)
-let fun_str struc fun_name vals =
-  let vals_s = ref "" in
-  let update i x = (elem_str struc i) ^ "->" ^ (string_of_float x) in
-    IntMap.iter (fun i x -> vals_s := !vals_s ^ ", " ^ (update i x)) vals;
-    fun_name ^ " {" ^ (omit 2 !vals_s) ^ "}"
-
-(* Print relational signature. *)
-let sig_str struc =
-  if StringMap.is_empty struc.rel_signature
-  then "" else
-    let s_str rel ar = rel ^ ": " ^ (string_of_int ar) in
-    let rel_structure struc =
-      StringMap.fold
-        (fun rel ar acc -> s_str rel ar::acc)
-        struc.rel_signature [] in
-    String.concat ", " (rel_structure struc)
-
-(* Print the structure [struc] as string, in extensive form (not using
-   condensed representations like boards). *)
-let ext_str ?(show_empty=true) struc = 
-  let elem_s = 
-    String.concat ", "
-      (List.map (elem_str struc) (Elems.elements struc.elements)) in
-  let (rel_s, fun_s) = (ref "", ref "") in
-    StringMap.iter
-      (fun rn ts ->
-        if show_empty || not (Tuples.is_empty ts) then
-          rel_s := !rel_s ^ "; " ^ rel_str struc rn ts)
-      struc.relations;
-    StringMap.iter
-      (fun fn vals -> fun_s := !fun_s ^ "; " ^ fun_str struc fn vals)
-      struc.functions;
-    "[" ^ elem_s ^ " | " ^ (omit 2 !rel_s) ^ " | " ^ (omit 2 !fun_s) ^ "]"
 
 (** {2 Printing of rectangular boards.}
 
@@ -1185,10 +1139,6 @@
           board ^ "\"",
         gc_elems !ret
 
-let str ?(show_empty=true) struc =
-  let board, struc = board_to_string struc in
-  ext_str ~show_empty struc ^ (if board = "" then "" else " " ^ board)
-
 let fprint_rel ?(print_arity=true) struc f (rel_name, ts) =
   if print_arity && Tuples.is_empty ts then
     Format.fprintf f "%s:%d {}" rel_name
@@ -1203,6 +1153,10 @@
            (tuple_str ~with_paren:false struc tp)))
       (Tuples.elements ts)
 
+(* Print the relation named [rel_name] with tuples [ts] as string. *)
+let rel_str ?(print_arity=true) struc rel_name ts =
+  AuxIO.sprint_of_fprint (fprint_rel ~print_arity struc) (rel_name, ts)
+
 let fprint_fun struc f (fun_name, vals) =
   let update f (i, x) =
     Format.fprintf f "%s->%s" (elem_str struc i) (string_of_float x) in
@@ -1220,13 +1174,27 @@
   let funs = List.sort (fun (f1,_) (f2,_) -> String.compare f2 f1)
     (StringMap.fold (fun k v acc -> (k,v)::acc) struc.functions []) in
   let rels = List.rev rels and funs = List.rev funs in
+  let consts_strs = List.fold_left (fun l (c, e) ->
+    (c ^ " = " ^ (elem_str struc e)) :: l) [] struc.constants in
+  let consts_str = String.concat "; " (List.rev consts_strs) in
+  let consts_str = if consts_strs = [] then consts_str else " ; "^ consts_str in
   Format.fprintf f
-    "[@[<1>@[<1>@,%a@]@ |@,@[<1>@ %a@]@ |@,@[<1>@ %a@]@]@,]"
+    "[@[<1>@[<1>@,%a@]@ |@,@[<1>@ %a@,%s@]@ |@,@[<1>@ %a@]@]@,]"
     (Aux.fprint_sep_list ","
        (fun f e->Format.pp_print_string f (elem_str struc e)))
     (Elems.elements struc.elements)
     (Aux.fprint_sep_list ";" (fprint_rel struc)) rels
+    consts_str
     (Aux.fprint_sep_list ";" (fprint_fun struc)) funs
+
+(* Print the structure [struc] as string, in extensive form (not using
+   condensed representations like boards). *)
+let ext_str ?(show_empty=true) struc =
+  AuxIO.sprint_of_fprint (fprint_ext_structure ~show_empty) struc
+
+let str ?(show_empty=true) struc =
+  let board, struc = board_to_string struc in
+  ext_str ~show_empty struc ^ (if board = "" then "" else " " ^ board)
 
 let fprint ~show_empty f struc =
   let board, struc = board_to_string struc in