2014-12-01 04:34:12 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
2014-12-15 21:43:42 +00:00
|
|
|
|
Module: init.prod
|
2014-12-01 04:34:12 +00:00
|
|
|
|
Author: Leonardo de Moura, Jeremy Avigad
|
|
|
|
|
-/
|
|
|
|
|
prelude
|
2015-02-01 16:39:47 +00:00
|
|
|
|
import init.num init.wf
|
2014-12-01 04:34:12 +00:00
|
|
|
|
|
|
|
|
|
definition pair := @prod.mk
|
2015-02-01 19:14:01 +00:00
|
|
|
|
notation A × B := prod A B
|
|
|
|
|
-- notation for n-ary tuples
|
|
|
|
|
notation `(` h `,` t:(foldl `,` (e r, prod.mk r e) h) `)` := t
|
2014-11-11 08:29:21 +00:00
|
|
|
|
|
|
|
|
|
namespace prod
|
2014-12-01 04:34:12 +00:00
|
|
|
|
notation A * B := prod A B
|
2015-02-01 19:14:01 +00:00
|
|
|
|
notation A × B := prod A B -- repeat, so this takes precedence
|
2014-12-01 04:34:12 +00:00
|
|
|
|
namespace low_precedence_times
|
2015-02-01 19:14:01 +00:00
|
|
|
|
reserve infixr `*`:30 -- conflicts with notation for multiplication
|
2014-12-01 04:34:12 +00:00
|
|
|
|
infixr `*` := prod
|
|
|
|
|
end low_precedence_times
|
|
|
|
|
|
|
|
|
|
notation `pr₁` := pr1
|
|
|
|
|
notation `pr₂` := pr2
|
|
|
|
|
|
2015-02-01 16:39:47 +00:00
|
|
|
|
namespace ops
|
|
|
|
|
postfix `.1`:(max+1) := pr1
|
|
|
|
|
postfix `.2`:(max+1) := pr2
|
|
|
|
|
end ops
|
|
|
|
|
|
2014-12-01 04:34:12 +00:00
|
|
|
|
open well_founded
|
|
|
|
|
|
2014-11-11 08:29:21 +00:00
|
|
|
|
section
|
|
|
|
|
variables {A B : Type}
|
|
|
|
|
variable (Ra : A → A → Prop)
|
|
|
|
|
variable (Rb : B → B → Prop)
|
|
|
|
|
|
2014-11-17 01:46:05 +00:00
|
|
|
|
-- Lexicographical order based on Ra and Rb
|
2014-11-11 08:29:21 +00:00
|
|
|
|
inductive lex : A × B → A × B → Prop :=
|
2014-11-17 01:46:05 +00:00
|
|
|
|
left : ∀{a₁ b₁} a₂ b₂, Ra a₁ a₂ → lex (a₁, b₁) (a₂, b₂),
|
|
|
|
|
right : ∀a {b₁ b₂}, Rb b₁ b₂ → lex (a, b₁) (a, b₂)
|
|
|
|
|
|
|
|
|
|
-- Relational product based on Ra and Rb
|
|
|
|
|
inductive rprod : A × B → A × B → Prop :=
|
|
|
|
|
intro : ∀{a₁ b₁ a₂ b₂}, Ra a₁ a₂ → Rb b₁ b₂ → rprod (a₁, b₁) (a₂, b₂)
|
2014-11-11 08:29:21 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context
|
|
|
|
|
parameters {A B : Type}
|
|
|
|
|
parameters {Ra : A → A → Prop} {Rb : B → B → Prop}
|
|
|
|
|
infix `≺`:50 := lex Ra Rb
|
|
|
|
|
|
2014-11-17 01:46:05 +00:00
|
|
|
|
definition lex.accessible {a} (aca : acc Ra a) (acb : ∀b, acc Rb b): ∀b, acc (lex Ra Rb) (a, b) :=
|
2014-11-11 08:29:21 +00:00
|
|
|
|
acc.rec_on aca
|
|
|
|
|
(λxa aca (iHa : ∀y, Ra y xa → ∀b, acc (lex Ra Rb) (y, b)),
|
|
|
|
|
λb, acc.rec_on (acb b)
|
|
|
|
|
(λxb acb
|
|
|
|
|
(iHb : ∀y, Rb y xb → acc (lex Ra Rb) (xa, y)),
|
|
|
|
|
acc.intro (xa, xb) (λp (lt : p ≺ (xa, xb)),
|
|
|
|
|
have aux : xa = xa → xb = xb → acc (lex Ra Rb) p, from
|
|
|
|
|
@lex.rec_on A B Ra Rb (λp₁ p₂, pr₁ p₂ = xa → pr₂ p₂ = xb → acc (lex Ra Rb) p₁)
|
|
|
|
|
p (xa, xb) lt
|
|
|
|
|
(λa₁ b₁ a₂ b₂ (H : Ra a₁ a₂) (eq₂ : a₂ = xa) (eq₃ : b₂ = xb),
|
|
|
|
|
show acc (lex Ra Rb) (a₁, b₁), from
|
|
|
|
|
have Ra₁ : Ra a₁ xa, from eq.rec_on eq₂ H,
|
|
|
|
|
iHa a₁ Ra₁ b₁)
|
|
|
|
|
(λa b₁ b₂ (H : Rb b₁ b₂) (eq₂ : a = xa) (eq₃ : b₂ = xb),
|
|
|
|
|
show acc (lex Ra Rb) (a, b₁), from
|
|
|
|
|
have Rb₁ : Rb b₁ xb, from eq.rec_on eq₃ H,
|
2014-11-11 08:39:53 +00:00
|
|
|
|
have eq₂' : xa = a, from eq.rec_on eq₂ rfl,
|
|
|
|
|
eq.rec_on eq₂' (iHb b₁ Rb₁)),
|
2014-11-11 08:29:21 +00:00
|
|
|
|
aux rfl rfl)))
|
|
|
|
|
|
|
|
|
|
-- The lexicographical order of well founded relations is well-founded
|
2014-11-17 01:46:05 +00:00
|
|
|
|
definition lex.wf (Ha : well_founded Ra) (Hb : well_founded Rb) : well_founded (lex Ra Rb) :=
|
|
|
|
|
well_founded.intro (λp, destruct p (λa b, lex.accessible (Ha a) (well_founded.apply Hb) b))
|
|
|
|
|
|
|
|
|
|
-- Relational product is a subrelation of the lex
|
|
|
|
|
definition rprod.sub_lex : ∀ a b, rprod Ra Rb a b → lex Ra Rb a b :=
|
|
|
|
|
λa b H, rprod.rec_on H (λ a₁ b₁ a₂ b₂ H₁ H₂, lex.left Rb a₂ b₂ H₁)
|
|
|
|
|
|
|
|
|
|
-- The relational product of well founded relations is well-founded
|
|
|
|
|
definition rprod.wf (Ha : well_founded Ra) (Hb : well_founded Rb) : well_founded (rprod Ra Rb) :=
|
2014-11-19 01:32:22 +00:00
|
|
|
|
subrelation.wf (rprod.sub_lex) (lex.wf Ha Hb)
|
2014-11-11 08:29:21 +00:00
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end prod
|