section \BIGNAT - Specification and Verification\
text \
Hardware platforms have a limit on the largest number they can represent.
This is usually fixed by the bit lengths of registers and ALUs used.
In order to be able to perform calculations that require arbitrarily large
numbers, the provided arithmetic operations need to be extended in order for
them to work on an abstract data type representing numbers of arbitrary size.
In this project you will build and verify an implementation for BIGNAT,
an abstract data type representing natural numbers of arbitrary size.
(Adapted from \<^url>\http://isabelle.in.tum.de/exercises/proj/bignat/ex.pdf\)
\
theory Project_BIGNAT
imports Main
begin
subsection \Representation\
text \
A BIGNAT is represented by a list of natural numbers in a range supported by
the target machine. In our case, this will be all natural numbers smaller than
a given base \b\.
Note: Natural numbers in Isabelle are of arbitrary size.
\
type_synonym bignat = "nat list"
text \
Define a function \valid\ that takes a base and checks if a given BIGNAT
is valid.
\
fun valid :: "nat \ bignat \ bool"
where
"valid b n = undefined"
text \
Define a function \val\ that takes a BIGNAT and its corresponding base,
and returns the natural number represented by the BIGNAT.
\
fun val :: "nat \ bignat \ nat"
where
"val b n = undefined"
subsection \Addition\
text \
Define a function \add\ that adds two BIGNATs with the same base.
Make sure that your algorithm preserves the validity of the BIGNAT
representation.
\
fun add :: "nat \ bignat \ bignat \ bignat"
where
"add b m n = undefined"
text \
Using @{const val}, verify formally that your @{const add} function computes
the sum of two BIGNATs correctly.
\
lemma val_add: "val b (add b m n) = val b m + val b n"
sorry
text \
Using @{const valid}, verify formally that your function @{const add} preserves
the validity of the BIGNAT representation.
\
lemma valid_add:
assumes "valid b m" and "valid b n"
shows "valid b (add b m n)"
sorry
subsection \Multiplication\
text \
Define a function \mult\ that multiplies two BIGNATs with the same base.
You may use @{const add}, but not so often as to make the solution trivial.
Make sure that your algorithm preserves the validity of the BIGNAT
representation.
\
fun mult :: "nat \ bignat \ bignat \ bignat"
where
"mult b m n = undefined"
text \
Using \val\, verify formally that your @{const mult} function computes the
product of two BIGNATs correctly.
\
lemma val_mult: "val b (mult b m n) = val b m * val b n"
sorry
text \
Using \valid\, verify formally that your @{const mult} function preserves
the validity of the BIGNAT representation.
\
lemma valid_mult:
assumes "valid b m" and "valid b n"
shows "valid b (mult b m n)"
sorry
end