now exports mk_bin
authorpaulson
Wed Jul 21 15:18:36 1999 +0200 (1999-07-21)
changeset 705591764e88d932
parent 7054 dfd96be49bd9
child 7056 522a7013d7df
now exports mk_bin
src/HOL/Tools/numeral_syntax.ML
     1.1 --- a/src/HOL/Tools/numeral_syntax.ML	Wed Jul 21 15:17:54 1999 +0200
     1.2 +++ b/src/HOL/Tools/numeral_syntax.ML	Wed Jul 21 15:18:36 1999 +0200
     1.3 @@ -8,8 +8,9 @@
     1.4  
     1.5  signature NUMERAL_SYNTAX =
     1.6  sig
     1.7 -  val dest_bin: term -> int
     1.8 -  val setup: (theory -> theory) list
     1.9 +  val dest_bin : term -> int
    1.10 +  val mk_bin   : int -> term
    1.11 +  val setup    : (theory -> theory) list
    1.12  end;
    1.13  
    1.14  structure NumeralSyntax: NUMERAL_SYNTAX =
    1.15 @@ -33,22 +34,26 @@
    1.16    | prefix_len pred (x :: xs) =
    1.17        if pred x then 1 + prefix_len pred xs else 0;
    1.18  
    1.19 -fun mk_bin str =
    1.20 +fun mk_bin n =
    1.21 +  let
    1.22 +    fun bin_of 0  = []
    1.23 +      | bin_of ~1 = [~1]
    1.24 +      | bin_of n  = (n mod 2) :: bin_of (n div 2);
    1.25 +
    1.26 +    fun term_of []   = Syntax.const "Numeral.bin.Pls"
    1.27 +      | term_of [~1] = Syntax.const "Numeral.bin.Min"
    1.28 +      | term_of (b :: bs) = Syntax.const "Numeral.bin.Bit" $ term_of bs 
    1.29 +                                                           $ mk_bit b;
    1.30 +    in term_of (bin_of n) end;
    1.31 +
    1.32 +fun bin_of_string str =
    1.33    let
    1.34      val (sign, digs) =
    1.35        (case Symbol.explode str of
    1.36          "#" :: "-" :: cs => (~1, cs)
    1.37        | "#" :: cs => (1, cs)
    1.38        | _ => raise ERROR);
    1.39 -
    1.40 -    fun bin_of 0  = []
    1.41 -      | bin_of ~1 = [~1]
    1.42 -      | bin_of n  = (n mod 2) :: bin_of (n div 2);
    1.43 -
    1.44 -    fun term_of []   = Syntax.const "Numeral.bin.Pls"
    1.45 -      | term_of [~1] = Syntax.const "Numeral.bin.Min"
    1.46 -      | term_of (b :: bs) = Syntax.const "Numeral.bin.Bit" $ term_of bs $ mk_bit b;
    1.47 -    in term_of (bin_of (sign * (#1 (Term.read_int digs)))) end;
    1.48 +    in mk_bin (sign * (#1 (Term.read_int digs))) end;
    1.49  
    1.50  (*we consider all "spellings"; Min is likely to be declared elsewhere*)
    1.51  fun bin_of (Const ("Pls", _)) = []
    1.52 @@ -82,7 +87,7 @@
    1.53  
    1.54  fun numeral_tr (*"_Numeral"*) [t as Free (str, _)] =
    1.55        (Syntax.const "Numeral.number_of" $
    1.56 -        (mk_bin str handle ERROR => raise TERM ("numeral_tr", [t])))
    1.57 +        (bin_of_string str handle ERROR => raise TERM ("numeral_tr", [t])))
    1.58    | numeral_tr (*"_Numeral"*) ts = raise TERM ("numeral_tr", ts);
    1.59  
    1.60  fun numeral_tr' show_sorts (*"number_of"*) (Type ("fun", [_, T])) (t :: ts) =