Skip to content
Snippets Groups Projects
rat.lp 1.44 KiB
Newer Older
gabrielhdt's avatar
gabrielhdt committed
require open encodings.cert_f adlib.cert_f.booleans
prelude.cert_f.logic
gabrielhdt's avatar
gabrielhdt committed
require adlib.cert_f.nat as N

gabrielhdt's avatar
gabrielhdt committed
set builtin "0" ≔ N.zero
set builtin "+1" ≔ N.succ

gabrielhdt's avatar
gabrielhdt committed
constant symbol rat : Univ Type
constant symbol zero : Term rat

gabrielhdt's avatar
gabrielhdt committed
symbol frac : Term N.nat ⇒ Term N.nznat ⇒ Term rat
gabrielhdt's avatar
gabrielhdt committed
set infix 8 "/" ≔ frac
gabrielhdt's avatar
gabrielhdt committed

gabrielhdt's avatar
gabrielhdt committed
symbol times : Term rat ⇒ Term rat ⇒ Term rat
gabrielhdt's avatar
gabrielhdt committed

rule times (frac &a &b) (frac &c &d) →
gabrielhdt's avatar
gabrielhdt committed
  let bv ≔ fst N.not_zero &b in
  let dv ≔ fst N.not_zero &d in
gabrielhdt's avatar
gabrielhdt committed
  frac
   (N.times &a &c)
gabrielhdt's avatar
gabrielhdt committed
   (N.nznatc
gabrielhdt's avatar
gabrielhdt committed
    (N.times bv dv)
    (N.prod_not_zero bv dv
gabrielhdt's avatar
gabrielhdt committed
     (snd N.not_zero &b)
     (snd N.not_zero &d)))

gabrielhdt's avatar
gabrielhdt committed
symbol rateq : Term rat ⇒ Term rat ⇒ Univ Prop
gabrielhdt's avatar
gabrielhdt committed
rule rateq (&a / &b) (&c / &d) →
  let nzval x ≔ fst N.not_zero x in
  eq (N.times &a (nzval &d)) (N.times (nzval &b) &c)
gabrielhdt's avatar
gabrielhdt committed
definition onz : Term N.nznat ≔ N.nznatc 1 N.one_not_zero

gabrielhdt's avatar
gabrielhdt committed
theorem rrefl (a: Term N.nat) (b: Term N.nznat):
gabrielhdt's avatar
gabrielhdt committed
  Term (rateq (a / b) (a / b))
gabrielhdt's avatar
gabrielhdt committed
proof
gabrielhdt's avatar
gabrielhdt committed
assume a b
apply N.prod_comm a (fst N.not_zero b)
qed

gabrielhdt's avatar
gabrielhdt committed
// theorem one_neutral (a: Term N.nat) (b: Term N.nznat):
//   Term (rateq (times (a / b) (1 / onz)) (1 / onz))
gabrielhdt's avatar
gabrielhdt committed
// proof
// qed
gabrielhdt's avatar
gabrielhdt committed
type Term (N.nznat ⊑ N.nat)
type λ(b: Term N.nznat) (pr: Term (N.nznat ⊑ N.nat)),
  @↑ N.nznat N.nat pr b
// FIXME explicitness required
theorem right_cancellation (a: Term N.nat) (b: Term N.nznat)
  (pr: Term (N.nznat ⊑ N.nat)):
  Term (rateq (times (a / b) ((@↑ N.nznat N.nat pr b) / onz)) (a / onz))
proof
qed
// Should generate a TCC to provide [pr]