# source:Deliverables/D4.1/Matita/Arithmetic.ma@257

Last change on this file since 257 was 257, checked in by mulligan, 9 years ago

Added exponential functions for nats. Working on operational semantics of processor.

File size: 3.5 KB
Line
1include "Universes.ma".
2include "Equality.ma".
3include "Connectives.ma".
4include "Nat.ma".
5include "Exponential.ma".
6include "Bool.ma".
7include "BitVector.ma".
8include "List.ma".
9
10ndefinition one ≝ S Z.
11ndefinition two ≝ (S(S(Z))).
12ndefinition three ≝ two + one.
13ndefinition four ≝ two + two.
14ndefinition five ≝ three + two.
15ndefinition six ≝ three + three.
16ndefinition seven ≝ three + four.
17ndefinition eight ≝ four + four.
18ndefinition nine ≝ five + four.
19ndefinition ten ≝ five + five.
20ndefinition eleven ≝ six + five.
21ndefinition twelve ≝ six + six.
22ndefinition thirteen ≝ seven + six.
23ndefinition fourteen ≝ seven + seven.
24ndefinition fifteen ≝ eight + seven.
25ndefinition sixteen ≝ eight + eight.
26ndefinition seventeen ≝ nine + eight.
27ndefinition eighteen ≝ nine + nine.
28ndefinition nineteen ≝ ten + nine.
29ndefinition one_hundred_and_twenty_eight ≝ sixteen * eight.
30ndefinition two_hundred_and_fifty_six ≝
31  one_hundred_and_twenty_eight + one_hundred_and_twenty_eight.
32
33ndefinition nat_of_bool ≝
34  λb: Bool.
35    match b with
36      [ False ⇒ Z
37      | True ⇒ S Z
38      ].
39
41      ∀n: Nat. ∀b, c: BitVector n. ∀carry: Bool. Cartesian (BitVector n) (List Bool) ≝
42  λn: Nat.
43  λb: BitVector n.
44  λc: BitVector n.
45  λcarry: Bool.
46    let b_as_nat ≝ nat_of_bitvector n b in
47    let c_as_nat ≝ nat_of_bitvector n c in
48    let carry_as_nat ≝ nat_of_bool carry in
49    let result_old ≝ b_as_nat + c_as_nat + carry_as_nat in
50    let ac_flag ≝ ((modulus b_as_nat ((S (S Z)) * n)) +
51                  (modulus c_as_nat ((S (S Z)) * n)) +
52                  c_as_nat) ≥ ((S (S Z)) * n) in
53    let bit_xxx ≝ (((modulus b_as_nat ((S (S Z))^(n - (S Z)))) +
54                  (modulus c_as_nat ((S (S Z))^(n - (S Z)))) +
55                  c_as_nat) ≥ ((S (S Z))^(n - (S Z)))) in
56    let result ≝ modulus result_old ((S (S Z))^n) in
57    let cy_flag ≝ (result_old ≥ ((S (S Z))^n)) in
58    let ov_flag ≝ exclusive_disjunction cy_flag bit_xxx in
59      ? (mk_Cartesian (BitVector n) ? (? (bitvector_of_nat n result))
60                          (cy_flag :: ac_flag :: ov_flag :: Empty Bool)).
61    //.
62nqed.
63
64(*
65ndefinition sub_8_with_carry ≝
66  λb: BitVector eight.
67  λc: BitVector eight.
68  λcarry: Bool.
69    let b_as_nat ≝ nat_of_bitvector eight b in
70    let c_as_nat ≝ nat_of_bitvector eight c in
71    let carry_as_nat ≝ nat_of_bool carry in
72    let result_old_1 ≝ subtraction_underflow b_as_nat c_as_nat in
73      match result_old_1 with
74        [ Nothing ⇒
75          let ac_flag ≝ True in
76
77        | Just result_old_1' ⇒
78        ]
79*)
80
83
84(*
85ndefinition increment ≝
86  λn: Nat.
87  λb: BitVector n.
88    let b_as_nat ≝ (nat_of_bitvector n b) + (S Z) in
89    let overflow ≝ b_as_nat ≥ (S (S Z))^n in
90      match overflow with
91        [ False ⇒ bitvector_of_nat n b_as_nat
92        | True ⇒ bitvector_of_nat n Z
93        ].
94
95ndefinition decrement ≝
96  λn: Nat.
97  λb: BitVector n.
98    let b_as_nat ≝ nat_of_bitvector n b in
99      match b_as_nat with
100        [ Z ⇒ max n
101        | S o ⇒ bitvector_of_nat n o
102        ].
103
104alias symbol "greater_than_or_equal" (instance 1) = "Nat greater than or equal prop".
105
106ndefinition bitvector_of_bool:
107      ∀n: Nat. ∀b: Bool. BitVector n ≝
108  λn: Nat.
109  λb: Bool.
110    ? (pad (n - (S Z)) (S Z) (Cons Bool ? b (Empty Bool))).
111  //.
112nqed.
113
114*)
Note: See TracBrowser for help on using the repository browser.