2014-07-07 16:31:42 +00:00
|
|
|
import standard
|
|
|
|
|
|
|
|
namespace algebra
|
|
|
|
inductive mul_struct (A : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
mk_mul_struct : (A → A → A) → mul_struct A
|
2014-07-07 16:31:42 +00:00
|
|
|
|
|
|
|
definition mul [inline] {A : Type} {s : mul_struct A} (a b : A)
|
|
|
|
:= mul_struct_rec (λ f, f) s a b
|
|
|
|
|
|
|
|
infixl `*`:75 := mul
|
2014-08-07 23:59:08 +00:00
|
|
|
end algebra
|
2014-07-07 16:31:42 +00:00
|
|
|
|
|
|
|
namespace nat
|
|
|
|
inductive nat : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
zero : nat,
|
|
|
|
succ : nat → nat
|
2014-07-07 16:31:42 +00:00
|
|
|
|
|
|
|
variable mul : nat → nat → nat
|
|
|
|
variable add : nat → nat → nat
|
|
|
|
|
|
|
|
definition mul_struct [instance] : algebra.mul_struct nat
|
|
|
|
:= algebra.mk_mul_struct mul
|
2014-08-07 23:59:08 +00:00
|
|
|
end nat
|
2014-07-07 16:31:42 +00:00
|
|
|
|
|
|
|
section
|
2014-07-07 21:53:06 +00:00
|
|
|
using algebra nat
|
2014-07-07 16:31:42 +00:00
|
|
|
variables a b c : nat
|
|
|
|
check a * b * c
|
2014-07-13 21:39:16 +00:00
|
|
|
definition tst1 : nat := a * b * c
|
2014-07-07 16:31:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
section
|
|
|
|
using [notation] algebra
|
|
|
|
using nat
|
|
|
|
-- check mul_struct nat << This is an error, we are using only the notation from algebra
|
|
|
|
variables a b c : nat
|
|
|
|
check a * b * c
|
2014-07-13 21:39:16 +00:00
|
|
|
definition tst2 : nat := a * b * c
|
2014-07-07 16:31:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
section
|
|
|
|
using nat
|
|
|
|
-- check mul_struct nat << This is an error, we are using only the notation from algebra
|
|
|
|
variables a b c : nat
|
|
|
|
check #algebra a*b*c
|
2014-07-13 21:39:16 +00:00
|
|
|
definition tst3 : nat := #algebra a*b*c
|
2014-07-07 16:31:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
section
|
|
|
|
using nat
|
2014-07-13 21:39:16 +00:00
|
|
|
set_option pp.implicit true
|
2014-07-07 16:31:42 +00:00
|
|
|
definition add_struct [instance] : algebra.mul_struct nat
|
|
|
|
:= algebra.mk_mul_struct add
|
|
|
|
|
|
|
|
variables a b c : nat
|
|
|
|
check #algebra a*b*c -- << is using add instead of mul
|
2014-07-13 21:39:16 +00:00
|
|
|
definition tst4 : nat := #algebra a*b*c
|
2014-07-07 16:31:42 +00:00
|
|
|
end
|