doc-src/IsarAdvanced/Codegen/Thy/examples/nat_binary.ML
author wenzelm
Tue, 14 Oct 2008 15:16:11 +0200
changeset 28586 d238b83ba3fc
parent 26999 284c871d3acb
permissions -rw-r--r--
renamed kill_all to kill, in conformance with atp_kill command; simplified/unified treatment of preferences; check_thread_manager: CRITICAL due to global ref; goal addressing via Thm.cprem_of; reduced NJ basis library stuff to bare minimum;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26999
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     1
structure Nat = 
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     2
struct
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     3
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     4
datatype nat = Dig1 of nat | Dig0 of nat | One_nat | Zero_nat;
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     5
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     6
fun plus_nat (Dig1 m) (Dig1 n) = Dig0 (plus_nat (plus_nat m n) One_nat)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     7
  | plus_nat (Dig1 m) (Dig0 n) = Dig1 (plus_nat m n)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     8
  | plus_nat (Dig0 m) (Dig1 n) = Dig1 (plus_nat m n)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
     9
  | plus_nat (Dig0 m) (Dig0 n) = Dig0 (plus_nat m n)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    10
  | plus_nat (Dig1 m) One_nat = Dig0 (plus_nat m One_nat)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    11
  | plus_nat One_nat (Dig1 n) = Dig0 (plus_nat n One_nat)
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    12
  | plus_nat (Dig0 m) One_nat = Dig1 m
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    13
  | plus_nat One_nat (Dig0 n) = Dig1 n
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    14
  | plus_nat m Zero_nat = m
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    15
  | plus_nat Zero_nat n = n;
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    16
284c871d3acb added new code_datatype example
haftmann
parents:
diff changeset
    17
end; (*struct Nat*)