Functional-machine semantics and value encodings for the treewidth algorithm
DefinitionBodlaenderKloks_FunctionalMachinealgorithmsgraph-theorytreewidth
The language has finite function tables and an interpreter relation with bounds on step count and on represented values. Naturals, lists, trees and characteristics have value encodings. The elementary library procedures and their function-table extension interfaces provide the operations used by the decomposition programs.
Definition code
import Definitions.Def_BodlaenderKloks_CharacteristicTables
import Definitions.Def_EdgeSublinearMWIS_Main_NativeSchemeInterfaces
import Definitions.Def_EdgeSublinearMWIS_Main_NativeWordRAM
import Definitions.Def_Lax228581_Treewidth
import Definitions.Def_Lax689794_GraphWords
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Combinatorics.Enumerative.DoubleCounting
import Mathlib.Combinatorics.SimpleGraph.Acyclic
import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected
import Mathlib.Combinatorics.SimpleGraph.Maps
import Mathlib.Combinatorics.SimpleGraph.Metric
import Mathlib.Data.Finset.Card
import Mathlib.Data.Finset.Image
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Finset.Sum
import Mathlib.Data.Finset.Union
import Mathlib.Data.List.Basic
import Mathlib.Data.List.Dedup
import Mathlib.Data.List.Forall2
import Mathlib.Data.List.GetD
import Mathlib.Data.List.Induction
import Mathlib.Data.List.Sort
import Mathlib.Data.List.Sublists
import Mathlib.Data.Nat.Lattice
import Mathlib.Data.Set.Basic
import Mathlib.Data.Set.Card
import Mathlib.Logic.Relation
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic
set_option autoImplicit false
set_option maxRecDepth 12000
set_option maxHeartbeats 3200000
-- Lax689794Proofs.Fun.Defs
section SourceModule44
namespace Lax689794Proofs.Fun
set_option genSizeOfSpec false in
/-- Values: naturals and pairs (lists are `cons a (cons b … (nat 0))`). -/
inductive Val where
| nat (n : ℕ)
| cons (a b : Val)
def Val.size : Val → ℕ
| .nat _ => 1
| .cons a b => a.size + b.size + 1
def Val.maxNat : Val → ℕ
| .nat n => n
| .cons a b => max a.maxNat b.maxNat
set_option genInjectivity false in
set_option genSizeOfSpec false in
/-- Terms: first-order, call by value, de Bruijn variables into the environment list; recursion through
the function table; `callv` calls a function whose id is a run-time natural (defunctionalised higher order). -/
inductive Tm where
| lit (n : ℕ) | var (i : ℕ)
| add (a b : Tm) | sub (a b : Tm) | mul (a b : Tm) | lt (a b : Tm) | eq (a b : Tm)
| cons (a b : Tm) | fst (a : Tm) | snd (a : Tm) | isNat (a : Tm)
| ite (c t e : Tm) | letE (a b : Tm)
| call (f : ℕ) (args : List Tm)
| callv (f : Tm) (args : List Tm)
mutual
/-- Big-step evaluation with cost (= number of constructs evaluated); every natural produced is `< B`. -/
inductive Ev (Δ : ℕ → Option Tm) (B : ℕ) : List Val → Tm → Val → ℕ → Prop
| lit {ρ : List Val} {n : ℕ} : n < B → Ev Δ B ρ (.lit n) (.nat n) 1
| var {ρ : List Val} {i : ℕ} {v : Val} : ρ[i]? = some v → Ev Δ B ρ (.var i) v 1
| add {ρ a b m n c₁ c₂} : Ev Δ B ρ a (.nat m) c₁ → Ev Δ B ρ b (.nat n) c₂ → m + n < B →
Ev Δ B ρ (.add a b) (.nat (m + n)) (c₁ + c₂ + 1)
| sub {ρ a b m n c₁ c₂} : Ev Δ B ρ a (.nat m) c₁ → Ev Δ B ρ b (.nat n) c₂ →
Ev Δ B ρ (.sub a b) (.nat (m - n)) (c₁ + c₂ + 1)
| mul {ρ a b m n c₁ c₂} : Ev Δ B ρ a (.nat m) c₁ → Ev Δ B ρ b (.nat n) c₂ → m * n < B →
Ev Δ B ρ (.mul a b) (.nat (m * n)) (c₁ + c₂ + 1)
| lt {ρ a b m n c₁ c₂} : Ev Δ B ρ a (.nat m) c₁ → Ev Δ B ρ b (.nat n) c₂ →
Ev Δ B ρ (.lt a b) (.nat (if m < n then 1 else 0)) (c₁ + c₂ + 1)
| eq {ρ a b m n c₁ c₂} : Ev Δ B ρ a (.nat m) c₁ → Ev Δ B ρ b (.nat n) c₂ →
Ev Δ B ρ (.eq a b) (.nat (if m = n then 1 else 0)) (c₁ + c₂ + 1)
| cons {ρ a b u v c₁ c₂} : Ev Δ B ρ a u c₁ → Ev Δ B ρ b v c₂ → Ev Δ B ρ (.cons a b) (.cons u v) (c₁ + c₂ + 1)
| fst {ρ a u v c} : Ev Δ B ρ a (.cons u v) c → Ev Δ B ρ (.fst a) u (c + 1)
| snd {ρ a u v c} : Ev Δ B ρ a (.cons u v) c → Ev Δ B ρ (.snd a) v (c + 1)
| isNatT {ρ a n c} : Ev Δ B ρ a (.nat n) c → Ev Δ B ρ (.isNat a) (.nat 1) (c + 1)
| isNatF {ρ a u v c} : Ev Δ B ρ a (.cons u v) c → Ev Δ B ρ (.isNat a) (.nat 0) (c + 1)
| iteT {ρ cnd t e n v c₁ c₂} : Ev Δ B ρ cnd (.nat n) c₁ → n ≠ 0 → Ev Δ B ρ t v c₂ →
Ev Δ B ρ (.ite cnd t e) v (c₁ + c₂ + 1)
| iteF {ρ cnd t e v c₁ c₂} : Ev Δ B ρ cnd (.nat 0) c₁ → Ev Δ B ρ e v c₂ →
Ev Δ B ρ (.ite cnd t e) v (c₁ + c₂ + 1)
| letE {ρ a b u v c₁ c₂} : Ev Δ B ρ a u c₁ → Ev Δ B (u :: ρ) b v c₂ → Ev Δ B ρ (.letE a b) v (c₁ + c₂ + 1)
| call {ρ f args body vs v c₁ c₂} : EvL Δ B ρ args vs c₁ → Δ f = some body → Ev Δ B vs body v c₂ →
Ev Δ B ρ (.call f args) v (c₁ + c₂ + 1)
| callv {ρ ft f args body vs v c₀ c₁ c₂} : Ev Δ B ρ ft (.nat f) c₀ → EvL Δ B ρ args vs c₁ →
Δ f = some body → Ev Δ B vs body v c₂ → Ev Δ B ρ (.callv ft args) v (c₀ + c₁ + c₂ + 1)
inductive EvL (Δ : ℕ → Option Tm) (B : ℕ) : List Val → List Tm → List Val → ℕ → Prop
| nil {ρ : List Val} : EvL Δ B ρ [] [] 0
| cons {ρ t ts v vs c₁ c₂} : Ev Δ B ρ t v c₁ → EvL Δ B ρ ts vs c₂ → EvL Δ B ρ (t :: ts) (v :: vs) (c₁ + c₂)
end
/-- The function `f` of the table, applied to argument values, evaluates to `y` within `c` steps. -/
def Runs (Δ : ℕ → Option Tm) (B f : ℕ) (xs : List Val) (y : Val) (c : ℕ) : Prop :=
∃ body, Δ f = some body ∧ ∃ c' ≤ c, Ev Δ B xs body y c'
end Lax689794Proofs.Fun
end SourceModule44
-- Lax689794Proofs.Fun.ToVal
section SourceModule45
/-!
# typed views of values (`ToVal`), sizes `sz`, and maximal naturals `mx`
`toVal : α → Val` is injective. Conventions: lists end in `nat 0`; `Bool` is `nat 0/1`; `Option`: `none = nat 0`,
`some a = cons (nat 1) (toVal a)`; products are `cons`; `Finset ℕ` is the strictly sorted list of its elements.
-/
namespace Lax689794Proofs.Fun
/-- Typed views of values (`[] = nat 0`; `Finset ℕ` = strictly sorted list). -/
class ToVal (α : Type) where
toVal : α → Val
inj : Function.Injective toVal
open ToVal
instance : ToVal ℕ := ⟨Val.nat, fun _ _ h => by simpa using h⟩
instance : ToVal Val := ⟨id, fun _ _ h => h⟩
instance : ToVal Unit := ⟨fun _ => .nat 0, fun _ _ _ => rfl⟩
/-- the list view. -/
def listVal {α : Type} [ToVal α] : List α → Val
| [] => .nat 0
| a :: l => .cons (toVal a) (listVal l)
theorem listVal_injective {α : Type} [ToVal α] : Function.Injective (listVal (α := α)) := by
intro l₁
induction l₁ with
| nil => intro l₂ h; cases l₂ with
| nil => rfl
| cons b l₂ => simp [listVal] at h
| cons a l₁ ih => intro l₂ h; cases l₂ with
| nil => simp [listVal] at h
| cons b l₂ =>
simp only [listVal, Val.cons.injEq] at h
rw [ToVal.inj h.1, ih h.2]
instance {α : Type} [ToVal α] : ToVal (List α) := ⟨listVal, listVal_injective⟩
instance {α β : Type} [ToVal α] [ToVal β] : ToVal (α × β) :=
⟨fun p => .cons (toVal p.1) (toVal p.2), by
rintro ⟨a, b⟩ ⟨a', b'⟩ h
simp only [Val.cons.injEq] at h
rw [ToVal.inj h.1, ToVal.inj h.2]⟩
instance {α : Type} [ToVal α] : ToVal (Option α) :=
⟨fun o => match o with | none => .nat 0 | some a => .cons (.nat 1) (toVal a), by
intro a b h
cases a <;> cases b <;> simp at h ⊢
exact ToVal.inj h⟩
/-- A finite set of naturals as the strictly sorted list of its elements. -/
def finVal (S : Finset ℕ) : Val := toVal (S.sort (· ≤ ·))
instance : ToVal (Finset ℕ) := ⟨finVal, by
intro S T h
have h1 : S.sort (· ≤ ·) = T.sort (· ≤ ·) := ToVal.inj h
rw [← Finset.sort_toFinset (· ≤ ·) (s := S), h1, Finset.sort_toFinset]⟩
/-! ### the `simp` set for `toVal` -/
/-! ### sizes and maximal naturals -/
/-- Size (number of cells) of the value view. -/
def sz {α : Type} [ToVal α] (a : α) : ℕ := (toVal a).size
/-- Largest natural occurring in the value view. -/
def mx {α : Type} [ToVal α] (a : α) : ℕ := (toVal a).maxNat
end Lax689794Proofs.Fun
end SourceModule45
-- Lax689794Proofs.Fun.Kit
section SourceModule46
/-! ### `Lax689794Proofs.Fun.Meta` -/
section
/-!
# meta-theory of `Ev` / `EvL` / `Runs`
* determinism (value and cost),
* weakening in the bound `B` and in the function table `Δ` (`Δ ⊑ Δ'`),
* environment extension,
* `EvLe` (evaluation within a cost *bound*) and its constructor lemmas — the working interface of `ev_step`,
* congruence of `Runs` (`Runs.mono`, `Runs.mono_B`, `Runs.bind`, …).
-/
namespace Lax689794Proofs.Fun
/-- `Δ'` extends `Δ` (`Δ ⊑ Δ'`): every function of `Δ` is present with the same body. -/
def Ext (Δ Δ' : ℕ → Option Tm) : Prop := ∀ f b, Δ f = some b → Δ' f = some b
infixl:50 " ⊑ " => Ext
/-- A layered table: functions with id `≥ lo` come from `tbl`, all others from `base`. -/
def layerΔ (base : ℕ → Option Tm) (lo : ℕ) (tbl : ℕ → Option Tm) : ℕ → Option Tm :=
fun f => if lo ≤ f then tbl f else base f
/-- A finite table as an association list (first entry wins). -/
def lookupL : List (ℕ × Tm) → ℕ → Option Tm
| [], _ => none
| (i, t) :: es, f => if i = f then some t else lookupL es f
/-! ### weakening -/
/-! ### determinism -/
/-! ### environment extension -/
/-! ### evaluation within a cost bound -/
/-! ### `Runs` -/
end Lax689794Proofs.Fun
end
/-! ### `Lax689794Proofs.Fun.Kit` -/
/-!
# The `ev_*` tactic kit
Goals of the form `EvLe Δ B ρ t v c` (term `t` evaluates to `v` within cost `c`) are discharged by
* `ev_start` : replaces the cost bound `c` by a metavariable (the exact cost, assembled bottom-up) and leaves
the side goal `?c ≤ c` **last** (close it with `omega`/`nlinarith` after everything else);
* `ev_step` : one construct — `lit var add sub mul lt eq cons fst snd isNat(T/F) ite(T/F) letE`, and argument lists;
* `ev_run` : `repeat' ev_step`, leaving only side goals (`n < B`, `ρ[i]? = some v`, `n ≠ 0`, …);
* `ev_side` : closes the standard side goals (`rfl`, `simp`, `omega`, `decide`);
* `ev_call h`, `ev_callv h` : a call of a function whose behaviour is a `Runs` fact `h`.
`ite` needs the branch: `ev_iteT` / `ev_iteF`.
-/
end SourceModule46
-- Lax689794Proofs.Fun.Lib1
section SourceModule47
/-!
# F1, layer 1: first-order list combinators as F-functions
Function ids `0 … 63` are reserved for the library (layer 1: `0 … 31`). Every function is a `Tm` body over the
argument list (de Bruijn: `var 0` is the first argument). Lemmas are stated for every table `Δ` extending
`Lib1.Δ` (`Lib1.Δ ⊑ Δ`). Costs are upper bounds on the number of constructs evaluated by the *body*
(the `Runs` convention). Naturals produced must be `< B`; the hypotheses say how large `B` must be.
-/
namespace Lax689794Proofs.Fun
namespace Lib1
open ToVal
/-- variable `i` -/
abbrev V (i : ℕ) : Tm := .var i
abbrev fAppend : ℕ := 0
abbrev fLength : ℕ := 1
abbrev fNth : ℕ := 2
abbrev fTake : ℕ := 3
abbrev fDrop : ℕ := 4
abbrev fMap : ℕ := 5
abbrev fFilter : ℕ := 6
abbrev fFoldl : ℕ := 7
abbrev fFlatMap : ℕ := 8
abbrev fAny : ℕ := 9
abbrev fAll : ℕ := 10
abbrev fRangeAux : ℕ := 11
abbrev fRange : ℕ := 12
abbrev fZip : ℕ := 13
abbrev fEqV : ℕ := 14
abbrev fMem : ℕ := 15
abbrev fMin : ℕ := 16
abbrev fMax : ℕ := 17
/-- `append xs ys` -/
def appendTm : Tm := .ite (.isNat (V 0)) (V 1) (.cons (.fst (V 0)) (.call fAppend [.snd (V 0), V 1]))
/-- `length xs` -/
def lengthTm : Tm := .ite (.isNat (V 0)) (.lit 0) (.add (.call fLength [.snd (V 0)]) (.lit 1))
/-- `nth xs i` (`nat 0` when out of range) -/
def nthTm : Tm :=
.ite (.isNat (V 0)) (.lit 0)
(.ite (.eq (V 1) (.lit 0)) (.fst (V 0)) (.call fNth [.snd (V 0), .sub (V 1) (.lit 1)]))
/-- `take n xs` -/
def takeTm : Tm :=
.ite (.isNat (V 1)) (V 1)
(.ite (.eq (V 0) (.lit 0)) (.lit 0) (.cons (.fst (V 1)) (.call fTake [.sub (V 0) (.lit 1), .snd (V 1)])))
/-- `drop n xs` -/
def dropTm : Tm :=
.ite (.isNat (V 1)) (V 1)
(.ite (.eq (V 0) (.lit 0)) (V 1) (.call fDrop [.sub (V 0) (.lit 1), .snd (V 1)]))
/-- `map f ctx xs`: calls `f ctx x` -/
def mapTm : Tm :=
.ite (.isNat (V 2)) (V 2) (.cons (.callv (V 0) [V 1, .fst (V 2)]) (.call fMap [V 0, V 1, .snd (V 2)]))
/-- `filter f ctx xs`: keeps `x` with `f ctx x ≠ 0` -/
def filterTm : Tm :=
.ite (.isNat (V 2)) (V 2)
(.ite (.callv (V 0) [V 1, .fst (V 2)]) (.cons (.fst (V 2)) (.call fFilter [V 0, V 1, .snd (V 2)]))
(.call fFilter [V 0, V 1, .snd (V 2)]))
/-- `foldl f ctx acc xs`: `acc := f ctx acc x` -/
def foldlTm : Tm :=
.ite (.isNat (V 3)) (V 2)
(.call fFoldl [V 0, V 1, .callv (V 0) [V 1, V 2, .fst (V 3)], .snd (V 3)])
/-- `flatMap f ctx xs` -/
def flatMapTm : Tm :=
.ite (.isNat (V 2)) (V 2)
(.call fAppend [.callv (V 0) [V 1, .fst (V 2)], .call fFlatMap [V 0, V 1, .snd (V 2)]])
/-- `any f ctx xs` -/
def anyTm : Tm :=
.ite (.isNat (V 2)) (.lit 0)
(.ite (.callv (V 0) [V 1, .fst (V 2)]) (.lit 1) (.call fAny [V 0, V 1, .snd (V 2)]))
/-- `all f ctx xs` -/
def allTm : Tm :=
.ite (.isNat (V 2)) (.lit 1)
(.ite (.callv (V 0) [V 1, .fst (V 2)]) (.call fAll [V 0, V 1, .snd (V 2)]) (.lit 0))
/-- `rangeAux i n = [i, …, n-1]` -/
def rangeAuxTm : Tm :=
.ite (.lt (V 0) (V 1)) (.cons (V 0) (.call fRangeAux [.add (V 0) (.lit 1), V 1])) (.lit 0)
/-- `range n = [0, …, n-1]` -/
def rangeTm : Tm := .call fRangeAux [.lit 0, V 0]
/-- `zip xs ys` -/
def zipTm : Tm :=
.ite (.isNat (V 0)) (V 0)
(.ite (.isNat (V 1)) (V 1) (.cons (.cons (.fst (V 0)) (.fst (V 1))) (.call fZip [.snd (V 0), .snd (V 1)])))
/-- structural equality `eqV u v` (`nat 1` / `nat 0`) -/
def eqVTm : Tm :=
.ite (.isNat (V 0)) (.ite (.isNat (V 1)) (.eq (V 0) (V 1)) (.lit 0))
(.ite (.isNat (V 1)) (.lit 0)
(.ite (.call fEqV [.fst (V 0), .fst (V 1)]) (.call fEqV [.snd (V 0), .snd (V 1)]) (.lit 0)))
/-- `mem a xs` by structural equality -/
def memTm : Tm :=
.ite (.isNat (V 1)) (.lit 0)
(.ite (.call fEqV [V 0, .fst (V 1)]) (.lit 1) (.call fMem [V 0, .snd (V 1)]))
def minTm : Tm := .ite (.lt (V 0) (V 1)) (V 0) (V 1)
def maxTm : Tm := .ite (.lt (V 0) (V 1)) (V 1) (V 0)
end Lib1
end Lax689794Proofs.Fun
end SourceModule47
-- Lax689794Proofs.Fun.Lib2
section SourceModule48
/-!
# F1, layer 2: `foldr`, `reverse`, `dedup`, insertion sort (= `List.mergeSort` on total preorders)
Ids `32 …`. Extends `Lib1.Δ` through `layerΔ`.
-/
set_option linter.unusedSectionVars false
set_option linter.unusedTactic false
set_option linter.unreachableTactic false
namespace Lax689794Proofs.Fun
namespace Lib2
open ToVal Lib1
abbrev fFoldr : ℕ := 32
abbrev fRevAux : ℕ := 33
abbrev fReverse : ℕ := 34
abbrev fDedup : ℕ := 35
abbrev fIns : ℕ := 36
abbrev fISort : ℕ := 37
/-- `foldr f ctx z xs`: `f ctx x acc` -/
def foldrTm : Tm :=
.ite (.isNat (V 3)) (V 2)
(.callv (V 0) [V 1, .fst (V 3), .call fFoldr [V 0, V 1, V 2, .snd (V 3)]])
/-- `revAux xs acc` -/
def revAuxTm : Tm :=
.ite (.isNat (V 0)) (V 1) (.call fRevAux [.snd (V 0), .cons (.fst (V 0)) (V 1)])
def reverseTm : Tm := .call fRevAux [V 0, .lit 0]
/-- `dedup l` (Lean's `List.dedup`: keeps the last occurrence) -/
def dedupTm : Tm :=
.ite (.isNat (V 0)) (V 0)
(.letE (.call fDedup [.snd (V 0)])
(.ite (.call fMem [.fst (V 1), V 0]) (V 0) (.cons (.fst (V 1)) (V 0))))
/-- `ins f ctx a l`: `orderedInsert` -/
def insTm : Tm :=
.ite (.isNat (V 3)) (.cons (V 2) (V 3))
(.ite (.callv (V 0) [V 1, V 2, .fst (V 3)]) (.cons (V 2) (V 3))
(.cons (.fst (V 3)) (.call fIns [V 0, V 1, V 2, .snd (V 3)])))
/-- `isort f ctx l`: insertion sort -/
def isortTm : Tm :=
.ite (.isNat (V 2)) (V 2) (.call fIns [V 0, V 1, .fst (V 2), .call fISort [V 0, V 1, .snd (V 2)]])
end Lib2
end Lax689794Proofs.Fun
end SourceModule48
-- Lax689794Proofs.Fun.Lib4
section SourceModule49
/-! ### `Lax689794Proofs.Fun.Lib3` -/
section
/-!
# F1, layer 3: `Finset ℕ` as strictly sorted lists — membership, insert, erase, union, inter, diff, subset
Ids `48 …`. The functions run on raw lists (`unionL`, …, no sortedness needed for the *cost*); on strictly sorted lists
they implement the `Finset` operations (`toVal (S ∪ T)` etc.).
-/
set_option linter.unusedSectionVars false
set_option linter.unusedTactic false
set_option linter.unreachableTactic false
namespace Lax689794Proofs.Fun
namespace Lib3
open ToVal Lib1
abbrev fMemS : ℕ := 48
abbrev fInsertS : ℕ := 49
abbrev fEraseS : ℕ := 50
abbrev fUnionS : ℕ := 51
abbrev fInterS : ℕ := 52
abbrev fDiffS : ℕ := 53
abbrev fSubsetS : ℕ := 54
/-- `memS a xs` on a sorted list (stops early) -/
def memSTm : Tm :=
.ite (.isNat (V 1)) (.lit 0)
(.ite (.lt (V 0) (.fst (V 1))) (.lit 0)
(.ite (.eq (V 0) (.fst (V 1))) (.lit 1) (.call fMemS [V 0, .snd (V 1)])))
def insertSTm : Tm :=
.ite (.isNat (V 1)) (.cons (V 0) (V 1))
(.ite (.lt (V 0) (.fst (V 1))) (.cons (V 0) (V 1))
(.ite (.eq (V 0) (.fst (V 1))) (V 1) (.cons (.fst (V 1)) (.call fInsertS [V 0, .snd (V 1)]))))
def eraseSTm : Tm :=
.ite (.isNat (V 1)) (V 1)
(.ite (.lt (V 0) (.fst (V 1))) (V 1)
(.ite (.eq (V 0) (.fst (V 1))) (.snd (V 1)) (.cons (.fst (V 1)) (.call fEraseS [V 0, .snd (V 1)]))))
def unionSTm : Tm :=
.ite (.isNat (V 0)) (V 1)
(.ite (.isNat (V 1)) (V 0)
(.ite (.lt (.fst (V 0)) (.fst (V 1))) (.cons (.fst (V 0)) (.call fUnionS [.snd (V 0), V 1]))
(.ite (.lt (.fst (V 1)) (.fst (V 0))) (.cons (.fst (V 1)) (.call fUnionS [V 0, .snd (V 1)]))
(.cons (.fst (V 0)) (.call fUnionS [.snd (V 0), .snd (V 1)])))))
def interSTm : Tm :=
.ite (.isNat (V 0)) (V 0)
(.ite (.isNat (V 1)) (V 1)
(.ite (.lt (.fst (V 0)) (.fst (V 1))) (.call fInterS [.snd (V 0), V 1])
(.ite (.lt (.fst (V 1)) (.fst (V 0))) (.call fInterS [V 0, .snd (V 1)])
(.cons (.fst (V 0)) (.call fInterS [.snd (V 0), .snd (V 1)])))))
def diffSTm : Tm :=
.ite (.isNat (V 0)) (V 0)
(.ite (.isNat (V 1)) (V 0)
(.ite (.lt (.fst (V 0)) (.fst (V 1))) (.cons (.fst (V 0)) (.call fDiffS [.snd (V 0), V 1]))
(.ite (.lt (.fst (V 1)) (.fst (V 0))) (.call fDiffS [V 0, .snd (V 1)])
(.call fDiffS [.snd (V 0), .snd (V 1)]))))
def subsetSTm : Tm :=
.ite (.isNat (V 0)) (.lit 1)
(.ite (.isNat (V 1)) (.lit 0)
(.ite (.lt (.fst (V 0)) (.fst (V 1))) (.lit 0)
(.ite (.lt (.fst (V 1)) (.fst (V 0))) (.call fSubsetS [V 0, .snd (V 1)])
(.call fSubsetS [.snd (V 0), .snd (V 1)]))))
/-! ### the list-level functions (same recursion as the F bodies) -/
/-! ### the `Finset` operations -/
end Lib3
end Lax689794Proofs.Fun
end
/-! ### `Lax689794Proofs.Fun.Lib4` -/
section
/-!
# F1, layer 4: `find?`, `findSome?`, `filterMap`, `sum`, `head?`, `toFinset`, `sublists`, `card`
Ids `64 …`. `Option`: `none = nat 0`, `some a = cons (nat 1) (toVal a)`.
-/
set_option linter.unusedSectionVars false
set_option linter.unusedTactic false
set_option linter.unreachableTactic false
namespace Lax689794Proofs.Fun
namespace Lib4
open ToVal Lib1
abbrev fFind : ℕ := 64
abbrev fFindSome : ℕ := 65
abbrev fFilterMap : ℕ := 66
abbrev fSum : ℕ := 67
abbrev fHead : ℕ := 68
abbrev fToFinset : ℕ := 69
abbrev fSublists : ℕ := 70
abbrev fPairUp : ℕ := 71
/-- `find? p ctx xs` -/
def findTm : Tm :=
.ite (.isNat (V 2)) (.lit 0)
(.ite (.callv (V 0) [V 1, .fst (V 2)]) (.cons (.lit 1) (.fst (V 2))) (.call fFind [V 0, V 1, .snd (V 2)]))
/-- `findSome? f ctx xs` -/
def findSomeTm : Tm :=
.ite (.isNat (V 2)) (.lit 0)
(.letE (.callv (V 0) [V 1, .fst (V 2)])
(.ite (.isNat (V 0)) (.call fFindSome [V 1, V 2, .snd (V 3)]) (V 0)))
/-- `filterMap f ctx xs` -/
def filterMapTm : Tm :=
.ite (.isNat (V 2)) (V 2)
(.letE (.callv (V 0) [V 1, .fst (V 2)])
(.ite (.isNat (V 0)) (.call fFilterMap [V 1, V 2, .snd (V 3)])
(.cons (.snd (V 0)) (.call fFilterMap [V 1, V 2, .snd (V 3)]))))
/-- sum of a list of naturals -/
def sumTm : Tm := .ite (.isNat (V 0)) (.lit 0) (.add (.fst (V 0)) (.call fSum [.snd (V 0)]))
def headTm : Tm := .ite (.isNat (V 0)) (.lit 0) (.cons (.lit 1) (.fst (V 0)))
/-- `List.toFinset` on naturals, as the sorted list -/
def toFinsetTm : Tm := .ite (.isNat (V 0)) (V 0) (.call Lib3.fInsertS [.fst (V 0), .call fToFinset [.snd (V 0)]])
/-- `[x, a :: x]` with `a` the context -/
def pairUpTm : Tm := .cons (V 1) (.cons (.cons (V 0) (V 1)) (.lit 0))
/-- `List.sublists` (needs `fPairUp < B`) -/
def sublistsTm : Tm :=
.ite (.isNat (V 0)) (.cons (.lit 0) (.lit 0))
(.call Lib1.fFlatMap [.lit fPairUp, .fst (V 0), .call fSublists [.snd (V 0)]])
end Lib4
end Lax689794Proofs.Fun
end
end SourceModule49
-- Lax689794Proofs.Fun.Lib
section SourceModule50
/-! ### `Lax689794Proofs.Fun.Embeds` -/
/-! ### `Fits` -/
/-! ### term-level embeddings -/
/-! ### `Lax689794Proofs.Fun.Lib` -/
section
/-!
# The F library as one table
`Lib.entries` is the library as a finite association list (ids `0 … 71`; **ids `0 … 127` are reserved for the
library**), `Lib.Δ = lookupL Lib.entries`. Algorithm-specific functions use ids `≥ 128`:
def eTbl : ℕ → Option Tm := … -- ids ≥ 128 only
def algΔ : ℕ → Option Tm := layerΔ Lib.Δ 128 eTbl -- `Lib.Δ ⊑ algΔ` (`Lib.ext_layer`)
Several owners: give each a disjoint id range and a table `eTbl₁, eTbl₂ : ℕ → Option Tm`; the assembly uses
`layerΔ Lib.Δ 128 (orElseΔ eTbl₁ eTbl₂)` and `Ext.layer_mono (Ext.orElse_left …)` /
`Ext.layer_mono (Ext.orElse_right …)` to see that it extends each owner's own `layerΔ Lib.Δ 128 eTbl_i`.
All library lemmas take `hΔ : Lib_i.Δ ⊑ Δ'`; `Lib.ext1 … Lib.ext4` turn `Lib.Δ ⊑ Δ'` into that.
-/
namespace Lax689794Proofs.Fun
namespace Lib
open Lib1 Lib2 Lib3 Lib4
/-- ids reserved for the library -/
abbrev reserved : ℕ := 128
def entries : List (ℕ × Tm) :=
[ (fAppend, appendTm), (fLength, lengthTm), (fNth, nthTm), (fTake, takeTm), (fDrop, dropTm), (fMap, mapTm),
(fFilter, filterTm), (fFoldl, foldlTm), (fFlatMap, flatMapTm), (fAny, anyTm), (fAll, allTm),
(fRangeAux, rangeAuxTm), (fRange, rangeTm), (fZip, zipTm), (fEqV, eqVTm), (fMem, memTm), (fMin, minTm),
(fMax, maxTm),
(Lib2.fFoldr, foldrTm), (Lib2.fRevAux, revAuxTm), (Lib2.fReverse, reverseTm), (Lib2.fDedup, dedupTm),
(Lib2.fIns, insTm), (Lib2.fISort, isortTm),
(Lib3.fMemS, memSTm), (Lib3.fInsertS, insertSTm), (Lib3.fEraseS, eraseSTm), (Lib3.fUnionS, unionSTm),
(Lib3.fInterS, interSTm), (Lib3.fDiffS, diffSTm), (Lib3.fSubsetS, subsetSTm),
(Lib4.fFind, findTm), (Lib4.fFindSome, findSomeTm), (Lib4.fFilterMap, filterMapTm), (Lib4.fSum, sumTm),
(Lib4.fHead, headTm), (Lib4.fToFinset, toFinsetTm), (Lib4.fSublists, sublistsTm), (Lib4.fPairUp, pairUpTm) ]
/-- The library table. -/
def Δ : ℕ → Option Tm := lookupL entries
/-- extend the library by algorithm functions (ids `≥ 128`) -/
def extend (tbl : ℕ → Option Tm) : ℕ → Option Tm := layerΔ Δ reserved tbl
end Lib
end Lax689794Proofs.Fun
end
end SourceModule50
-- Lax689794Proofs.Fun.ToValAlg
section SourceModule60
/-!
# `ToVal` instances for the data types of the algorithm
Types that flow through `tables`, `extract`, `realIntro`, `realJoin`, `niceOf`, `compress`, `NT.addEverywhere`,
`NT.encode`, `improveC`, `decomposeC`, `introPlans`, `joinC`, `ringTypList`, `mergeReal`, `analyze`:
| type | view |
|---|---|
| `CT` (`node S y ks`) | `cons (S) (cons (y) (ks))`, `ks` the ordinary list view |
| `RT` (`node X ks`) | `cons (X) (ks)` |
| `NT` | `leaf = 0`, `intro v c = (1, (v, c))`, `forget v c = (2, (v, c))`, `join a b = (3, (a, b))` (right-nested `cons`) |
| `CNode` | `cons bag junk` |
| `AR` (`run S chain ks`) | `cons S (cons chain ks)` |
| `Cut` | `t1 f = (1, f)`, `t2 f = (2, f)` |
| `WPlan` | `endAt c = (1, c)`, `whole ps = (2, ps)` |
| `Plan` | `att c chain M = (1, (c, (chain, M)))`, `top pre w = (2, (pre, w))` |
| `WithTop ℕ` (`CT.key`) | as `Option ℕ` (`⊤ = 0`, `↑n = (1, n)`) |
Everything else is already an instance of `Prod/List/Option/ℕ/Bool/Finset ℕ`: `LState = List ℕ × List (ℕ × ℕ)`,
`List (List ℕ × Plan × CT)` (`introPlans`), `Option RT`, `Option (List AR)`, lattice paths `List (ℕ × ℕ)`, …
`Adj` (a function) is *not* a value: the machine receives the graph word `x` and reads adjacency off it (`adjOfWord`).
Injectivity of the nested ones is proved by mutual structural recursion. After each instance a `toVal_*` simp lemma
gives the view in terms of the *ordinary* list/option views (`encCTL ks = toVal ks` etc.).
-/
namespace Lax689794Proofs.Fun
open ToVal Lax689794Proofs.Chars Lax689794Proofs.Trees
/-! ## `CT` -/
mutual
def encCT : CT → Val
| .node S y ks => .cons (toVal S) (.cons (toVal y) (encCTL ks))
def encCTL : List CT → Val
| [] => .nat 0
| k :: ks => .cons (encCT k) (encCTL ks)
end
mutual
theorem encCT_inj_rec : ∀ a b : CT, encCT a = encCT b → a = b
| .node S y ks, .node S' y' ks', h => by
simp only [encCT, Val.cons.injEq] at h
obtain ⟨h1, h2, h3⟩ := h
have e1 : S = S' := ToVal.inj h1
have e2 : y = y' := ToVal.inj h2
have e3 := encCTL_inj_rec ks ks' h3
subst e1 e2 e3; rfl
theorem encCTL_inj_rec : ∀ a b : List CT, encCTL a = encCTL b → a = b
| [], [], _ => rfl
| [], _ :: _, h => by simp [encCTL] at h
| _ :: _, [], h => by simp [encCTL] at h
| k :: ks, k' :: ks', h => by
simp only [encCTL, Val.cons.injEq] at h
rw [encCT_inj_rec k k' h.1, encCTL_inj_rec ks ks' h.2]
end
theorem encCT_inj_pair : (type_of% @encCT_inj_rec) ∧ (type_of% @encCTL_inj_rec) :=
⟨@encCT_inj_rec, @encCTL_inj_rec⟩
theorem encCT_inj : type_of% @encCT_inj_rec := encCT_inj_pair.1
instance : ToVal CT := ⟨encCT, fun a b h => encCT_inj a b h⟩
/-! ## `RT` -/
mutual
def encRT : RT → Val
| .node X ks => .cons (toVal X) (encRTL ks)
def encRTL : List RT → Val
| [] => .nat 0
| k :: ks => .cons (encRT k) (encRTL ks)
end
mutual
theorem encRT_inj_rec : ∀ a b : RT, encRT a = encRT b → a = b
| .node X ks, .node X' ks', h => by
simp only [encRT, Val.cons.injEq] at h
obtain ⟨h1, h2⟩ := h
have e1 : X = X' := ToVal.inj h1
have e2 := encRTL_inj_rec ks ks' h2
subst e1 e2; rfl
theorem encRTL_inj_rec : ∀ a b : List RT, encRTL a = encRTL b → a = b
| [], [], _ => rfl
| [], _ :: _, h => by simp [encRTL] at h
| _ :: _, [], h => by simp [encRTL] at h
| k :: ks, k' :: ks', h => by
simp only [encRTL, Val.cons.injEq] at h
rw [encRT_inj_rec k k' h.1, encRTL_inj_rec ks ks' h.2]
end
theorem encRT_inj_pair : (type_of% @encRT_inj_rec) ∧ (type_of% @encRTL_inj_rec) :=
⟨@encRT_inj_rec, @encRTL_inj_rec⟩
theorem encRT_inj : type_of% @encRT_inj_rec := encRT_inj_pair.1
instance : ToVal RT := ⟨encRT, fun a b h => encRT_inj a b h⟩
/-! ## `NT` -/
def encNT : NT → Val
| .leaf => .nat 0
| .intro v c => .cons (.nat 1) (.cons (.nat v) (encNT c))
| .forget v c => .cons (.nat 2) (.cons (.nat v) (encNT c))
| .join a b => .cons (.nat 3) (.cons (encNT a) (encNT b))
theorem encNT_inj : ∀ a b : NT, encNT a = encNT b → a = b
| .leaf, .leaf, _ => rfl
| .leaf, .intro _ _, h => by simp [encNT] at h
| .leaf, .forget _ _, h => by simp [encNT] at h
| .leaf, .join _ _, h => by simp [encNT] at h
| .intro _ _, .leaf, h => by simp [encNT] at h
| .forget _ _, .leaf, h => by simp [encNT] at h
| .join _ _, .leaf, h => by simp [encNT] at h
| .intro v c, .intro v' c', h => by
simp only [encNT, Val.cons.injEq, Val.nat.injEq, true_and] at h
rw [h.1, encNT_inj c c' h.2]
| .forget v c, .forget v' c', h => by
simp only [encNT, Val.cons.injEq, Val.nat.injEq, true_and] at h
rw [h.1, encNT_inj c c' h.2]
| .join a b, .join a' b', h => by
simp only [encNT, Val.cons.injEq, true_and] at h
rw [encNT_inj a a' h.1, encNT_inj b b' h.2]
| .intro _ _, .forget _ _, h => by simp [encNT] at h
| .intro _ _, .join _ _, h => by simp [encNT] at h
| .forget _ _, .intro _ _, h => by simp [encNT] at h
| .forget _ _, .join _ _, h => by simp [encNT] at h
| .join _ _, .intro _ _, h => by simp [encNT] at h
| .join _ _, .forget _ _, h => by simp [encNT] at h
instance : ToVal NT := ⟨encNT, fun a b h => encNT_inj a b h⟩
/-! ## `CNode`, `AR` -/
instance : ToVal CNode := ⟨fun n => .cons (toVal n.bag) (toVal n.junk), by
rintro ⟨b, j⟩ ⟨b', j'⟩ h
simp only [Val.cons.injEq] at h
have e1 : b = b' := ToVal.inj h.1
have e2 : j = j' := ToVal.inj h.2
subst e1 e2; rfl⟩
mutual
def encAR : AR → Val
| .run S c ks => .cons (toVal S) (.cons (toVal c) (encARL ks))
def encARL : List AR → Val
| [] => .nat 0
| k :: ks => .cons (encAR k) (encARL ks)
end
mutual
theorem encAR_inj_rec : ∀ a b : AR, encAR a = encAR b → a = b
| .run S c ks, .run S' c' ks', h => by
simp only [encAR, Val.cons.injEq] at h
obtain ⟨h1, h2, h3⟩ := h
have e1 : S = S' := ToVal.inj h1
have e2 : c = c' := ToVal.inj h2
have e3 := encARL_inj_rec ks ks' h3
subst e1 e2 e3; rfl
theorem encARL_inj_rec : ∀ a b : List AR, encARL a = encARL b → a = b
| [], [], _ => rfl
| [], _ :: _, h => by simp [encARL] at h
| _ :: _, [], h => by simp [encARL] at h
| k :: ks, k' :: ks', h => by
simp only [encARL, Val.cons.injEq] at h
rw [encAR_inj_rec k k' h.1, encARL_inj_rec ks ks' h.2]
end
theorem encAR_inj_pair : (type_of% @encAR_inj_rec) ∧ (type_of% @encARL_inj_rec) :=
⟨@encAR_inj_rec, @encARL_inj_rec⟩
theorem encAR_inj : type_of% @encAR_inj_rec := encAR_inj_pair.1
instance : ToVal AR := ⟨encAR, fun a b h => encAR_inj a b h⟩
/-! ## `CT.Cut`, `CT.WPlan`, `CT.Plan` -/
instance : ToVal CT.Cut := ⟨fun c => match c with
| .t1 f => .cons (.nat 1) (.nat f)
| .t2 f => .cons (.nat 2) (.nat f), by
intro a b h
cases a <;> cases b <;> simp at h ⊢ <;> exact h⟩
mutual
def encWP : CT.WPlan → Val
| .endAt c => .cons (.nat 1) (toVal c)
| .whole ps => .cons (.nat 2) (encWPL ps)
def encWPL : List (Option CT.WPlan) → Val
| [] => .nat 0
| p :: ps => .cons (encWPO p) (encWPL ps)
def encWPO : Option CT.WPlan → Val
| none => .nat 0
| some p => .cons (.nat 1) (encWP p)
end
mutual
theorem encWP_inj_rec : ∀ a b : CT.WPlan, encWP a = encWP b → a = b
| .endAt c, .endAt c', h => by
simp only [encWP, Val.cons.injEq, true_and] at h
rw [show c = c' from ToVal.inj h]
| .whole ps, .whole ps', h => by
simp only [encWP, Val.cons.injEq, true_and] at h
rw [encWPL_inj_rec ps ps' h]
| .endAt _, .whole _, h => by simp [encWP] at h
| .whole _, .endAt _, h => by simp [encWP] at h
theorem encWPL_inj_rec : ∀ a b : List (Option CT.WPlan), encWPL a = encWPL b → a = b
| [], [], _ => rfl
| [], _ :: _, h => by simp [encWPL] at h
| _ :: _, [], h => by simp [encWPL] at h
| p :: ps, p' :: ps', h => by
simp only [encWPL, Val.cons.injEq] at h
rw [encWPO_inj_rec p p' h.1, encWPL_inj_rec ps ps' h.2]
theorem encWPO_inj_rec : ∀ a b : Option CT.WPlan, encWPO a = encWPO b → a = b
| none, none, _ => rfl
| none, some _, h => by simp [encWPO] at h
| some _, none, h => by simp [encWPO] at h
| some p, some p', h => by
simp only [encWPO, Val.cons.injEq, true_and] at h
rw [encWP_inj_rec p p' h]
end
theorem encWP_inj_triple : (type_of% @encWP_inj_rec) ∧ (type_of% @encWPL_inj_rec) ∧ (type_of% @encWPO_inj_rec) :=
⟨@encWP_inj_rec, @encWPL_inj_rec, @encWPO_inj_rec⟩
theorem encWP_inj : type_of% @encWP_inj_rec := encWP_inj_triple.1
instance : ToVal CT.WPlan := ⟨encWP, fun a b h => encWP_inj a b h⟩
instance : ToVal CT.Plan := ⟨fun p => match p with
| .att c ch M => .cons (.nat 1) (.cons (toVal c) (.cons (toVal ch) (toVal M)))
| .top pre w => .cons (.nat 2) (.cons (toVal pre) (toVal w)), by
intro a b h
cases a <;> cases b <;> simp at h
· obtain ⟨h1, h2, h3⟩ := h
have e1 : _ = _ := ToVal.inj h1
have e2 : _ = _ := ToVal.inj h2
have e3 : _ = _ := ToVal.inj h3
subst e1 e2 e3; rfl
· obtain ⟨h1, h2⟩ := h
have e1 : _ = _ := ToVal.inj h1
have e2 : _ = _ := ToVal.inj h2
subst e1 e2; rfl⟩
/-! ## `WithTop ℕ` (the key of `CT.key`) -/
instance : ToVal (WithTop ℕ) := ⟨fun x => toVal (show Option ℕ from x), fun _ _ h => ToVal.inj (α := Option ℕ) h⟩
end Lax689794Proofs.Fun
end SourceModule60
/-
Source attribution
The treewidth algorithm and its correctness proof are from yuvalyitz/treewidth-lax, commit b6743cf02087f552d8f023581f4718e68c42e444. The word-RAM semantics are from lax-archive/lax-submissions, commit 9394e531cc51cb67a0214bca3f9264dfe97ba5c7, word-ram/. The local streaming header and uniform output bounds extend these sources. Project-local proof tactics have been expanded into ordinary Lean proof steps.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
Source