P. 1
Tutorial

Tutorial

|Views: 6|Likes:
Published by Alexandra Buruciuc

More info:

Published by: Alexandra Buruciuc on Sep 21, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/21/2011

pdf

text

original

Isabelle/HOL organises its numeric theories using axiomatic type classes.
Hundreds of basic properties are proved in the theory Ring_and_Field. These
lemmas are available (as simprules if they were declared as such) for all
numeric types satisfying the necessary axioms. The theory defines dozens of
type classes, such as the following:

8.4 Numbers 171

– semiring and ordered_semiring: a semiring provides the associative oper-
ators + and *, with 0 and 1 as their respective identities. The operators
enjoy the usual distributive law, and addition (+) is also commutative. An
ordered semiring is also linearly ordered, with addition and multiplication
respecting the ordering. Type nat is an ordered semiring.
– ring and ordered_ring: a ring extends a semiring with unary minus (the
additive inverse) and subtraction (both denoted -). An ordered ring in-
cludes the absolute value function, abs. Type int is an ordered ring.
– field and ordered_field: a field extends a ring with the multiplicative
inverse (called simply inverse and division (/)). An ordered field is based
on an ordered ring. Type complex is a field, while type real is an ordered
field.

– division_by_zero includes all types where inverse 0 = 0 and a / 0 = 0.
These include all of Isabelle’s standard numeric types. However, the basic
properties of fields are derived without assuming division by zero.

Hundreds of basic lemmas are proved, each of which holds for all types in
the corresponding type class. In most cases, it is obvious whether a property
is valid for a particular type. No abstract properties involving subtraction
hold for type nat; instead, theorems such as diff_mult_distrib are proved
specifically about subtraction on type nat. All abstract properties involving
division require a field. Obviously, all properties involving orderings required
an ordered structure.

The class ring_no_zero_divisors of rings without zero divisors satisfies
a number of natural cancellation laws, the first of which characterizes this
class:

(a * b = (0::’a)) = (a = (0::’a) ∨ b = (0::’a))

(mult_eq_0_iff)

(a * c = b * c) = (c = (0::’a) ∨ a = b)

(mult_cancel_right)

Setting the flag Isabelle > Settings > Show Sorts will display the type classes of
all type variables.

Here is how the theorem mult_cancel_left appears with the flag set.

((c::’a::ring_no_zero_divisors) * (a::’a::ring_no_zero_divisors) =

c * (b::’a::ring_no_zero_divisors)) =

(c = (0::’a::ring_no_zero_divisors) ∨ a = b)

Simplifying with the AC-Laws. Suppose that two expressions are equal,
differing only in associativity and commutativity of addition. Simplifying with
the following equations sorts the terms and groups them to the right, making
the two expressions identical.

a + b + c = a + (b + c)

(add_assoc)

a + b = b + a

(add_commute)

a + (b + c) = b + (a + c)

(add_left_commute)

172 8. More about Types

The name add_ac refers to the list of all three theorems; similarly there is

mult_ac. They are all proved for semirings and therefore hold for all numeric
types.

Here is an example of the sorting effect. Start with this goal, which in-

volves type nat.

1. Suc (i + j * l * k + m * n) = f (n * m + i + k * j * l)

Simplify using add_ac and mult_ac.

apply (simp add: add_ac mult_ac)

Here is the resulting subgoal.

1. Suc (i + (m * n + j * (k * l))) = f (i + (m * n + j * (k * l)))

Division Laws for Fields. Here is a selection of rules about the division
operator. The following are installed as default simplification rules in order
to express combinations of products and quotients as rational expressions:

a * (b / c) = a * b / c

(times_divide_eq_right)

b / c * a = b * a / c

(times_divide_eq_left)

a / (b / c) = a * c / b

(divide_divide_eq_right)

a / b / c = a / (b * c)

(divide_divide_eq_left)

Signs are extracted from quotients in the hope that complementary terms
can then be cancelled:

- (a / b) = - a / b

(minus_divide_left)

- (a / b) = a / - b

(minus_divide_right)

The following distributive law is available, but it is not installed as a

simplification rule.

(a + b) / c = a / c + b / c

(add_divide_distrib)

Absolute Value. The absolute value function abs is available for all ordered
rings, including types int, rat and real. It satisfies many properties, such as
the following:

|x * y| = |x| * |y|

(abs_mult)

(|a| ≤ b) = (a ≤ b ∧ - a ≤ b)

(abs_le_iff)

|a + b| ≤ |a| + |b|

(abs_triangle_ineq)

!!The absolute value bars shown above cannot be typed on a keyboard. They can
be entered using the X-symbol package. In ascii, type abs x to get |x|.

Raising to a Power. Another type class, ordered idom, specifies rings that
also have exponentation to a natural number power, defined using the obvi-
ous primitive recursion. Theory Power proves various theorems, such as the
following.

a ^ (m + n) = a ^ m * a ^ n

(power_add)

a ^ (m * n) = (a ^ m) ^ n

(power_mult)

|a ^ n| = |a| ^ n

(power_abs)

8.5 Introducing New Types 173

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->