chars
int64
40
24k
content_type
stringclasses
9 values
id
stringlengths
13
64
source
stringclasses
5 values
subset
stringclasses
31 values
text
stringlengths
40
24k
165
leanexplore_declaration
leanexplore:386177
leanexplore_sqlite
leanexplore_declarations
lemma not_johnson_adj_iff_lt {s t : {s : Finset (Fin n) // #s = k}} : ¬ J(n, k).Adj s t ↔ s = t ∨ #(s.val ∩ t.val) + 1 < k := by simp [johnson_adj_iff_ge]; tauto
541
leanexplore_declaration
leanexplore:386178
leanexplore_sqlite
leanexplore_declarations
lemma johnson_adj_iff_ge {s t : {s : Finset (Fin n) // #s = k}} : J(n, k).Adj s t ↔ s ≠ t ∧ k ≤ #(s.val ∩ t.val) + 1 := by obtain ⟨s, hs⟩ := s obtain ⟨t, ht⟩ := t simp only [johnson_adj, le_antisymm_iff (α := ℕ), ne_eq, Subtype.mk.injEq, and_congr_left_iff] rintro h constructor · rintro hst rfl simp...
48
leanexplore_declaration
leanexplore:386179
leanexplore_sqlite
leanexplore_declarations
scoped notation "J(" n ", " k ")" => johnson n k
127
leanexplore_declaration
leanexplore:386180
leanexplore_sqlite
leanexplore_declarations
@[simps -isSimp] def johnson (n k : ℕ) : SimpleGraph {s : Finset (Fin n) // #s = k} where Adj s t := #(s.val ∩ t.val) + 1 = k
361
leanexplore_declaration
leanexplore:386181
leanexplore_sqlite
leanexplore_declarations
/-- The Johnson graph $J(n, k)$ has as vertices the $k$-subsets of an $n$-set. Two vertices are adjacent if their intersection has size $k - 1$. -/ @[simps -isSimp] def johnson (n k : ℕ) : SimpleGraph {s : Finset (Fin n) // #s = k} where Adj s t := #(s.val ∩ t.val) + 1 = k symm s t h := by simpa [inter_comm] loop...
396
leanexplore_declaration
leanexplore:386182
leanexplore_sqlite
leanexplore_declarations
/-- A graph `G` is **Ramsey size linear** if there exists a constant `c > 0` such that for all graphs `H` with `m` edges and no isolated vertices, `r̂(G, H) ≤ c · m`. -/ def IsRamseySizeLinear {α : Type*} [Fintype α] (G : SimpleGraph α) : Prop := ∃ c > (0 : ℝ), ∀ (n : ℕ) (H : SimpleGraph (Fin n)) [DecidableRel H.Adj]...
566
leanexplore_declaration
leanexplore:386183
leanexplore_sqlite
leanexplore_declarations
/-- The size Ramsey number `r̂(G, H)` is the minimum number of edges in a graph `F` such that any 2-coloring of `F`'s edges contains a copy of `G` in one color or `H` in the other. A 2-coloring is represented by a subgraph `R ≤ F` (the "red" edges); the "blue" edges are `F \ R`. -/ noncomputable def sizeRamsey {α β : ...
271
leanexplore_declaration
leanexplore:386184
leanexplore_sqlite
leanexplore_declarations
/-- The simple graph of a Young diagram: two distinct cells are adjacent iff they lie in the same row or in the same column. -/ def YoungDiagram.toSimpleGraph (μ : YoungDiagram) : SimpleGraph μ.Cell := .fromRel fun a b => a.val.fst = b.val.fst ∨ a.val.snd = b.val.snd
91
leanexplore_declaration
leanexplore:386185
leanexplore_sqlite
leanexplore_declarations
instance (μ : YoungDiagram) : DecidableEq μ.Cell := inferInstanceAs (DecidableEq μ.cells)
83
leanexplore_declaration
leanexplore:386186
leanexplore_sqlite
leanexplore_declarations
instance (μ : YoungDiagram) : Fintype μ.Cell := inferInstanceAs (Fintype μ.cells)
58
leanexplore_declaration
leanexplore:386187
leanexplore_sqlite
leanexplore_declarations
def YoungDiagram.Cell (μ : YoungDiagram) : Type := μ.cells
418
leanexplore_declaration
leanexplore:386188
leanexplore_sqlite
leanexplore_declarations
def finEncodingListBoolProdListBool : Computability.FinEncoding (List Bool × List Bool) where Γ := Option Bool encode := fun ⟨l1, l2⟩ ↦ (l1.map some) ++ [none] ++ (l2.map some) decode := fun l ↦ match l.splitOnP Option.isNone with | [l1, l2] => some (l1.map (Option.getD · false), l2.map (Option.getD · fal...
384
leanexplore_declaration
leanexplore:386189
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma splitOnP_append_cons {α : Type} (l1 l2 : List α) (a : α) (P : α → Bool) (hPa : P a = true) : List.splitOnP P (l1 ++ a :: l2) = List.splitOnP P l1 ++ List.splitOnP P l2 := by induction l1 with | nil => simp [hPa] | cons hd tl ih => obtain ⟨hd1, tl1, h1'⟩ := List.exists_cons_of_ne_nil ...
199
leanexplore_declaration
leanexplore:386190
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma splitOnP_isNone_map_some {α : Type} (l : List α) : List.splitOnP Option.isNone (l.map some) = [l.map some] := by induction l with | nil => rfl | cons hd tl ih => simp [ih]
168
leanexplore_declaration
leanexplore:386191
leanexplore_sqlite
leanexplore_declarations
def finEncodingListBool : Computability.FinEncoding (List Bool) where Γ := Bool encode := id decode := Option.some decode_encode _ := rfl ΓFin := Bool.fintype
365
leanexplore_declaration
leanexplore:386192
leanexplore_sqlite
leanexplore_declarations
theorem haltingNumber_def (n : ℕ) (hn : ∃ a, M.multiStep (init []) n = some a) (ha' : M.multiStep (init []) (n + 1) = none) : M.haltingNumber = n := by refine IsGLB.sInf_eq (IsLeast.isGLB ⟨⟨n, by rwa [HaltsAfter], rfl⟩, fun m ⟨k, _, _⟩ ↦ ?_⟩) cases m · exact le_top · by_contra! hc simp_all [multiSte...
250
leanexplore_declaration
leanexplore:386193
leanexplore_sqlite
leanexplore_declarations
noncomputable def haltingNumber : ENat := -- The smallest `n` such that `M` halts after `n` steps when starting from an empty tape. -- If no such `n` exists then this is equal to `⊤`. sInf {(n : ENat) | (n : ℕ) (_ : HaltsAfter M (init []) n) }
568
leanexplore_declaration
leanexplore:386194
leanexplore_sqlite
leanexplore_declarations
lemma not_isHalting_of_forall_isSome (H : ∀ l s, ∃ a b, M l s = some (some a, b)) : ¬IsHalting M := by rw [not_isHalting_iff_forall_isSome_multiStep] intro n induction n with | zero => obtain ⟨a, b, H⟩ := H default (Tape.mk₁ []).head simp [init, step, H] | succ n ih => obtain ⟨a, b, hab⟩ := ex...
217
leanexplore_declaration
leanexplore:386195
leanexplore_sqlite
leanexplore_declarations
lemma not_isHalting_iff_forall_isSome_multiStep : ¬ IsHalting M ↔ ∀ n, M.multiStep (init []) (n + 1) |>.isSome := by simp_rw [isHalting_iff_exists_haltsAt, HaltsAfter, Option.isSome_iff_ne_none] push_neg rfl
418
leanexplore_declaration
leanexplore:386196
leanexplore_sqlite
leanexplore_declarations
lemma exists_of_not_haltsAfter (s : Cfg Γ Λ) (n : ℕ) (H : ¬M.HaltsAfter s n) : ∃ (a : Λ) (b : Tape Γ), M.multiStep s n = some ⟨a, b⟩ := by contrapose! H rw [HaltsAfter, multiStep_succ] obtain H | ⟨⟨u, u'⟩, hu⟩ := (Option.eq_none_or_eq_some (M.multiStep s n)) · simp [H] · suffices u = none by rw [hu, this]...
157
leanexplore_declaration
leanexplore:386197
leanexplore_sqlite
leanexplore_declarations
lemma isHalting_iff_exists_haltsAt : IsHalting M ↔ ∃ n, M.HaltsAfter (init []) n := ⟨fun _ ↦ eval_dom_iff.mpr IsHalting.halts, fun H ↦ ⟨eval_dom_iff.mp H⟩⟩
155
leanexplore_declaration
leanexplore:386198
leanexplore_sqlite
leanexplore_declarations
lemma haltsAfter_zero_iff (s : Cfg Γ Λ) : HaltsAfter M s 0 ↔ step M s = none := by rw [HaltsAfter, multiStep, Function.iterate_one, Option.bind_some]
246
leanexplore_declaration
leanexplore:386199
leanexplore_sqlite
leanexplore_declarations
/-- The predicate that a machine starting at configuration `s` stops after at most `n` steps, i.e. reaches a configuration from which there are no defined transitions. -/ def HaltsAfter (s : Cfg Γ Λ) (n : ℕ) : Prop := M.multiStep s (n+1) = none
154
leanexplore_declaration
leanexplore:386201
leanexplore_sqlite
leanexplore_declarations
/-- The property that a Turing Machine `M` eventually halts when starting from an empty tape -/ class IsHalting : Prop where halts : M.IsHaltingInput []
164
leanexplore_declaration
leanexplore:386202
leanexplore_sqlite
leanexplore_declarations
/-- `M.HaltsAtConfiguration s` is the predicate that `M` is a halting configuration for `M`. -/ def IsHaltingConfiguration (s : Cfg Γ Λ) : Prop := (step M s).isNone
146
leanexplore_declaration
leanexplore:386203
leanexplore_sqlite
leanexplore_declarations
/-- `M.IsHaltingInput l` is the predicate that `M` is a halting configuration for `M`. -/ def IsHaltingInput (l : List Γ) : Prop := (eval M l).Dom
272
leanexplore_declaration
leanexplore:386204
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma multiStep_eq_none_mono {M : Machine Γ Λ} {config : Cfg Γ Λ} {m n : ℕ} (H : M.multiStep config n = none) (hnm : n ≤ m) : M.multiStep config m = none := by induction hnm with | refl => exact H | @step m hnm H => rw [multiStep_succ, H] rfl
229
leanexplore_declaration
leanexplore:386205
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma multiStep_succ (M : Machine Γ Λ) (config : Cfg Γ Λ) (n : ℕ) : M.multiStep config (n + 1) = Option.bind (M.multiStep config n) M.step := by rw [multiStep, Function.iterate_succ', Function.comp_apply, multiStep]
112
leanexplore_declaration
leanexplore:386206
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma multiStep_one (M : Machine Γ Λ) (config : Cfg Γ Λ) : M.multiStep config 1 = M.step config := rfl
111
leanexplore_declaration
leanexplore:386207
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma multiStep_zero (M : Machine Γ Λ) (config : Cfg Γ Λ) : M.multiStep config 0 = some config := rfl
120
leanexplore_declaration
leanexplore:386208
leanexplore_sqlite
leanexplore_declarations
def multiStep (M : Machine Γ Λ) (config : Cfg Γ Λ) (n : ℕ) : Option (Cfg Γ Λ) := (Option.bind · (step M))^[n] config
211
leanexplore_declaration
leanexplore:386209
leanexplore_sqlite
leanexplore_declarations
/-- Evaluate a Turing machine on initial input to a final state, if it terminates. -/ def eval (M : Machine Γ Λ) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.tape.right₀
95
leanexplore_declaration
leanexplore:386210
leanexplore_sqlite
leanexplore_declarations
/-- The initial configuration. -/ def init (l : List Γ) : Cfg Γ Λ := ⟨some default, Tape.mk₁ l⟩
225
leanexplore_declaration
leanexplore:386211
leanexplore_sqlite
leanexplore_declarations
/-- The statement `Reaches M s₁ s₂` means that `s₂` is obtained starting from `s₁` after a finite number of steps from `s₂`. -/ def Reaches (M : Machine Γ Λ) : Cfg Γ Λ → Cfg Γ Λ → Prop := ReflTransGen fun a b ↦ b ∈ step M a
236
leanexplore_declaration
leanexplore:386212
leanexplore_sqlite
leanexplore_declarations
/-- Execution semantics of the Turing machine. -/ def step (M : Machine Γ Λ) : Cfg Γ Λ → Option (Cfg Γ Λ) | ⟨none, _⟩ => none | ⟨some q, T⟩ => (M q T.1).map fun ⟨q', a⟩ ↦ ⟨q', match a with | Stmt.write a d => (T.write a).move d⟩
318
leanexplore_declaration
leanexplore:386216
leanexplore_sqlite
leanexplore_declarations
@[ext] structure Cfg [Inhabited Γ] where /-- The current machine state. -/ q : Option Λ /-- The current state of the tape: current symbol, left and right parts. -/ tape : Tape Γ variable {Γ Λ} variable [Inhabited Λ] variable [Inhabited Γ] instance Cfg.inhabited : Inhabited (Cfg Γ Λ) := ⟨⟨default, default⟩⟩
531
leanexplore_declaration
leanexplore:386218
leanexplore_sqlite
leanexplore_declarations
/-- The configuration state of a Turing machine during operation consists of a label (machine state), and a tape. The tape is represented in the form `(a, L, R)`, meaning the tape looks like `L.rev ++ [a] ++ R` with the machine currently reading the `a`. The lists are automatically extended with blanks as the ...
105
leanexplore_declaration
leanexplore:386219
leanexplore_sqlite
leanexplore_declarations
instance Machine.inhabited [Inhabited Λ] : Inhabited (Machine Γ Λ) := by unfold Machine; infer_instance
827
leanexplore_declaration
leanexplore:386220
leanexplore_sqlite
leanexplore_declarations
/-- A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function which, given the current state `q : Λ` and the tape head `a : Γ`, either halts (returns `none`) or returns a new state `q' : Option Λ` and a `Stmt` describing what to do: a command to write a symbol and move left or right. Notice th...
212
leanexplore_declaration
leanexplore:386226
leanexplore_sqlite
leanexplore_declarations
/-- A Turing machine "statement" is just a command to write a symbol on the tape (at the current position) and then move left or right. -/ structure Stmt where write :: symbol : Γ dir : Dir deriving Inhabited
511
leanexplore_declaration
leanexplore:386227
leanexplore_sqlite
leanexplore_declarations
/-- `turing_machine% tmStringDescription` outputs a term of type `Machine Γ Λ` where `Γ = Fin 2` and `Λ` is an inductive type constructed on the fly with constructors `A, B, ...`, and named `State{n}` where `n` is the number of states of the machine. Warning: if `State{n}` already exists in the environment then this w...
1,576
leanexplore_declaration
leanexplore:386228
leanexplore_sqlite
leanexplore_declarations
/-- `parseTuring tmStringDescription` outputs the `Expr` corresponding to the Turing Machine described by the string `tmStringDescription`. To do so, it 1) Runs `mkStateType` to add the state type to the environment 2) Defines the corresponding Turing Machine as a function using the `match` syntax. Warning: if a stat...
1,166
leanexplore_declaration
leanexplore:386229
leanexplore_sqlite
leanexplore_declarations
/-- `mkStateType n` adds to the environment an inductive type with `n` states names `State{n}` with constructors the symbols `A, B, ...`, together with the instance `Inhabited (State{n})`. -/ def mkStateType (n : ℕ) (stateName : Name) : TermElabM Unit := do /- We may want to have some smarter check done here, e.g. ...
1,093
leanexplore_declaration
leanexplore:386230
leanexplore_sqlite
leanexplore_declarations
/-- Take as input a list of strings and return an array of `matchAltExpr` syntaxes mapping `(state, symbol)` pairs to actions of a Turing Machine, given by a term of type `Option (State n)`. -/ def mkMachineMatchAltExpr (L : List String) (stateName : Name) (numSymbols numStates: Nat) : TermElabM (Array (TSyntax ``m...
1,158
leanexplore_declaration
leanexplore:386231
leanexplore_sqlite
leanexplore_declarations
theorem eval_dom_iff {σ : Type*} {f : σ → Option σ} {s : σ} : (∃ n, ((Option.bind · f)^[n+1] s) = none) ↔ (Turing.eval f s).Dom := by refine ⟨fun ⟨n, hn⟩ ↦ ?_, fun H ↦ ?_⟩ · induction n generalizing s with | zero => rw [zero_add, Function.iterate_one, Option.bind_some] at hn simpa [Part.dom_iff_...
223
leanexplore_declaration
leanexplore:386232
leanexplore_sqlite
leanexplore_declarations
theorem eval_eq_eval {σ : Type*} {f : σ → Option σ} {a a' : σ} (H : f a = some a'): Turing.eval f a = Turing.eval f a' := by apply reaches_eval rw [Turing.Reaches] apply Relation.ReflTransGen.single rw [H] rfl
224
leanexplore_declaration
leanexplore:386233
leanexplore_sqlite
leanexplore_declarations
theorem eval_get_eval {σ : Type*} {f : σ → Option σ} {s : σ} (H : (Turing.eval f s).Dom) : Turing.eval f ((Turing.eval f s).get H) = Turing.eval f s := by symm apply Part.get_eq_get H (dom_of_apply_eq_none ?_) simp
212
leanexplore_declaration
leanexplore:386234
leanexplore_sqlite
leanexplore_declarations
@[simp] theorem apply_get_eval {σ : Type*} {f : σ → Option σ} {s : σ} (H : (Turing.eval f s).Dom) : f ((Turing.eval f s).get H) = none := by have := Part.get_mem H rw [mem_eval] at this exact this.right
149
leanexplore_declaration
leanexplore:386235
leanexplore_sqlite
leanexplore_declarations
lemma dom_of_apply_eq_none {σ : Type*} {f : σ → Option σ} {s : σ} (hf : f s = none) : s ∈ Turing.eval f s := by apply PFun.fix_stop simp [hf]
222
leanexplore_declaration
leanexplore:386236
leanexplore_sqlite
leanexplore_declarations
theorem Part.get_eq_get {σ : Type*} {a b : Part σ} (ha : a.Dom) (hb : a.get ha ∈ b) : a = b := by have hb' : b.Dom := Part.dom_iff_mem.mpr ⟨a.get ha, hb⟩ rwa [← Part.eq_get_iff_mem hb', Part.eq_iff_of_dom ha hb'] at hb
118
leanexplore_declaration
leanexplore:386237
leanexplore_sqlite
leanexplore_declarations
lemma card_lt_card_iff_of_subset (hst : s ⊆ t) : #s < #t ↔ s ≠ t := by rw [← not_le, card_le_card_iff_of_subset hst]
134
leanexplore_declaration
leanexplore:386238
leanexplore_sqlite
leanexplore_declarations
lemma card_le_card_iff_of_subset (hst : s ⊆ t) : #t ≤ #s ↔ s = t where mp := eq_of_subset_of_card_le hst mpr := by rintro rfl; rfl
181
leanexplore_declaration
leanexplore:386239
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma disjoint_powersetCard_powersetCard : Disjoint (powersetCard n s) (powersetCard n t) ↔ #(s ∩ t) < n := by simp [disjoint_iff_inter_eq_empty, ← powersetCard_inter]
145
leanexplore_declaration
leanexplore:386240
leanexplore_sqlite
leanexplore_declarations
lemma powersetCard_inter : powersetCard n (s ∩ t) = powersetCard n s ∩ powersetCard n t := by ext; simpa [subset_inter_iff] using and_and_right
494
leanexplore_declaration
leanexplore:386241
leanexplore_sqlite
leanexplore_declarations
theorem prod_primeFactors_factorization_apply (n : ℕ) {p : ℕ} (hp : p.Prime) {f : ℕ → ℕ → ℕ} (hf : ∀ q n, ¬ q ∣ n → f q n = 0) (hf₀ : ∀ q, f q 0 = 0): (∏ q ∈ n.primeFactors, q ^ f q n).factorization p = f p n := by rw [factorization_prod fun _ _ _ ↦ by simp_all, Finset.sum_congr rfl fun x hx ↦ by rw [fa...
421
leanexplore_declaration
leanexplore:386242
leanexplore_sqlite
leanexplore_declarations
/-- Simproc to compute the set `Nat.primeFactors`. -/ dsimproc primeFactorsEq (Nat.primeFactors _) := fun e ↦ do unless e.isAppOfArity `Nat.primeFactors 1 do return .continue let some n ← fromExpr? e.appArg! | return .continue let outAsList : List Q(ℕ) := (unsafe n.primeFactors.val.unquot).map mkNatLit let outA...
582
leanexplore_declaration
leanexplore:386243
leanexplore_sqlite
leanexplore_declarations
/-- If $n \equiv p \pmod{p ^ (k + 1)}$, for a prime $p$ then $n$ is not $(k + 1)$-full. -/ theorem not_full_of_prime_mod_prime_sq (n : ℕ) (k : ℕ) {p : ℕ} (hp : p.Prime) (h : n % p ^ (k + 1) = p) : ¬ (k + 1).Full n := by rw [Full] push_neg use p simp [mem_primeFactors, hp, ne_eq, true_and] constructor · ...
137
leanexplore_declaration
leanexplore:386244
leanexplore_sqlite
leanexplore_declarations
theorem full_of_le_full (k : ℕ) (n : ℕ) {m : ℕ} (hk : k ≤ m) (h : m.Full n) : k.Full n := fun p a ↦ pow_dvd_of_le_of_pow_dvd hk (h p a)
133
leanexplore_declaration
leanexplore:386245
leanexplore_sqlite
leanexplore_declarations
instance Powerful.decide : ∀ n, Decidable (Powerful n) := by intro n dsimp [Powerful, Full] apply Finset.decidableDforallFinset
268
leanexplore_declaration
leanexplore:386246
leanexplore_sqlite
leanexplore_declarations
/-- A [Powerful number](https://en.wikipedia.org/wiki/Powerful_number) is a natural number $n$ where for every prime divisor $p$, $p^2$ divides $n$. Powerful numbers are also known as "squareful", "square-full", or "$2$-full". -/ abbrev Powerful : ℕ → Prop := (2).Full
96
leanexplore_declaration
leanexplore:386247
leanexplore_sqlite
leanexplore_declarations
/-- $1$ is always $k$-full. -/ theorem Full.one_right (k : ℕ) : k.Full 1 := by simp [Nat.Full]
97
leanexplore_declaration
leanexplore:386248
leanexplore_sqlite
leanexplore_declarations
/-- $0$ is always $k$-full. -/ theorem Full.zero_right (k : ℕ) : k.Full 0 := by simp [Nat.Full]
123
leanexplore_declaration
leanexplore:386249
leanexplore_sqlite
leanexplore_declarations
/-- Every natural number is $1$-full. -/ theorem Full.one_left (n : ℕ) : (1 : ℕ).Full n := by aesop (add simp [Nat.Full])
112
leanexplore_declaration
leanexplore:386250
leanexplore_sqlite
leanexplore_declarations
/-- Every natural number is $0$-full. -/ theorem Full.zero_left (n : ℕ) : (0 : ℕ).Full n := by simp [Nat.Full]
100
leanexplore_declaration
leanexplore:386251
leanexplore_sqlite
leanexplore_declarations
instance Full.decide : ∀ k n, Decidable (Full k n) := by intro k n dsimp [Full] infer_instance
212
leanexplore_declaration
leanexplore:386252
leanexplore_sqlite
leanexplore_declarations
/-- A natural number $n$ is said to be $k$-full (or $k$-powerful) if for every prime factor $p$ of $n$, the $k$-th power $p^k$ also divides $n$. -/ def Full (k : ℕ) (n : ℕ) : Prop := ∀ p ∈ n.primeFactors, p^k ∣ n
124
leanexplore_declaration
leanexplore:386253
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_self_mul_sub : a ∣ a * b - c ↔ a ∣ c ∨ b * a ≤ c := by rw [Nat.mul_comm, Nat.dvd_mul_self_sub]
135
leanexplore_declaration
leanexplore:386254
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_mul_self_sub : a ∣ b * a - c ↔ a ∣ c ∨ b * a ≤ c := by rw [Nat.dvd_sub_iff_right' (Nat.dvd_mul_left _ _)]
124
leanexplore_declaration
leanexplore:386255
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_sub_self_mul : a ∣ b - a * c ↔ a ∣ b ∨ b ≤ c * a := by rw [Nat.mul_comm, Nat.dvd_sub_mul_self]
134
leanexplore_declaration
leanexplore:386256
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_sub_mul_self : a ∣ b - c * a ↔ a ∣ b ∨ b ≤ c * a := by rw [Nat.dvd_sub_iff_left' (Nat.dvd_mul_left _ _)]
197
leanexplore_declaration
leanexplore:386257
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma dvd_sub_iff_left' (hac : a ∣ c) : a ∣ b - c ↔ a ∣ b ∨ b ≤ c := by obtain hbc | hcb := b.le_total c · simp [*] · simp +contextual [Nat.dvd_sub_iff_left, ← Nat.le_antisymm hcb, *]
197
leanexplore_declaration
leanexplore:386258
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma dvd_sub_iff_right' (hab : a ∣ b) : a ∣ b - c ↔ a ∣ c ∨ b ≤ c := by obtain hbc | hcb := b.le_total c · simp [*] · simp +contextual [Nat.dvd_sub_iff_right, Nat.le_antisymm hcb, *]
112
leanexplore_declaration
leanexplore:386259
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_self_mul_add : a ∣ a * b + c ↔ a ∣ c := by rw [Nat.mul_comm, Nat.dvd_mul_self_add]
112
leanexplore_declaration
leanexplore:386260
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_mul_self_add : a ∣ b * a + c ↔ a ∣ c := by rw [Nat.add_comm, Nat.dvd_add_mul_self]
112
leanexplore_declaration
leanexplore:386261
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_add_self_mul : a ∣ b + a * c ↔ a ∣ b := by rw [Nat.mul_comm, Nat.dvd_add_mul_self]
117
leanexplore_declaration
leanexplore:386262
leanexplore_sqlite
leanexplore_declarations
@[simp] protected lemma dvd_add_mul_self : a ∣ b + c * a ↔ a ∣ b := by rw [Nat.dvd_add_left (Nat.dvd_mul_left _ _)]
247
leanexplore_declaration
leanexplore:386263
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma one_lt_maxPrimeFac_iff (n : ℕ) : 1 < maxPrimeFac n ↔ 1 < n := by rcases lt_trichotomy n 1 with hn | rfl | hn · simp only [lt_one_iff] at hn simp [hn] · simp · simpa [hn] using (prime_maxPrimeFac_of_one_lt n hn).one_lt
528
leanexplore_declaration
leanexplore:386264
leanexplore_sqlite
leanexplore_declarations
lemma maxPrimeFac_eq_of_dvd_of_le (n p : ℕ) (hn : 0 < n) (hp : p.Prime) (h_dvd : p ∣ n) (h_le : maxPrimeFac n ≤ p) : maxPrimeFac n = p := by refine le_antisymm h_le ?_ replace hn : 1 < n := Nat.lt_of_lt_of_le hp.one_lt (Nat.le_of_dvd hn h_dvd) set s := {p : ℕ | p.Prime ∧ p ∣ n} with hs have hs₁ : BddAbo...
448
leanexplore_declaration
leanexplore:386265
leanexplore_sqlite
leanexplore_declarations
lemma prime_maxPrimeFac_of_one_lt (n : ℕ) (h : 1 < n) : Prime (maxPrimeFac n) := by set s := {p : ℕ | p.Prime ∧ p ∣ n} with hs have hs₀ : s.Nonempty := by simp only [Set.Nonempty, Set.mem_setOf_eq, ← ne_one_iff_exists_prime_dvd, hs] omega have hs₁ : BddAbove s := by use n simp only [hs, mem_up...
136
leanexplore_declaration
leanexplore:386266
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma maxPrimeFac_one : maxPrimeFac 1 = 0 := by suffices {p : ℕ | p.Prime ∧ p = 1} = ∅ by simp [maxPrimeFac, this] aesop
139
leanexplore_declaration
leanexplore:386267
leanexplore_sqlite
leanexplore_declarations
@[simp] lemma maxPrimeFac_zero : maxPrimeFac 0 = 0 := by simpa [maxPrimeFac] using Set.Infinite.Nat.sSup_eq_zero infinite_setOf_prime
288
leanexplore_declaration
leanexplore:386268
leanexplore_sqlite
leanexplore_declarations
/-- The greatest prime divisor of a natural number `n > 1`. Takes the junk value `0` for `n = 0` and `n = 1`. TODO Consider redefining this using the computable implementation: `n.primeFactorsList.getLastI`. -/ noncomputable def maxPrimeFac (n : ℕ) : ℕ := sSup {p : ℕ | p.Prime ∧ p ∣ n}
196
leanexplore_declaration
leanexplore:386269
leanexplore_sqlite
leanexplore_declarations
instance IsPerfectPower.decide : ∀ n, Decidable (IsPerfectPower n) := fun n => decidable_of_iff (n > 1 ∧ n.primeFactors.gcd n.factorization > 1) (isPerfectPower_iff_factorization_gcd n).symm
4,379
leanexplore_declaration
leanexplore:386270
leanexplore_sqlite
leanexplore_declarations
theorem isPerfectPower_iff_factorization_gcd (n : ℕ) : IsPerfectPower n ↔ n > 1 ∧ n.primeFactors.gcd n.factorization > 1 := by constructor · -- Forward direction: IsPerfectPower n → n > 1 ∧ gcd > 1 intro ⟨k, m, hk, hm, hpow⟩ constructor · -- n > 1 have h : n ≥ 4 := by calc n = k ^ m :=...
605
leanexplore_declaration
leanexplore:386271
leanexplore_sqlite
leanexplore_declarations
/-- A [perfect power](https://en.wikipedia.org/wiki/Perfect_power) is a natural number that is a product of equal natural factors, or, in other words, an integer that can be expressed as a square or a higher integer power of another integer greater than one. More formally, $n$ is a perfect power if there exist na...
55
leanexplore_declaration
leanexplore:386272
leanexplore_sqlite
leanexplore_declarations
abbrev Nat.Composite (n : ℕ) : Prop := 1 < n ∧ ¬n.Prime
210
leanexplore_declaration
leanexplore:386273
leanexplore_sqlite
leanexplore_declarations
lemma Nat.exists_prime_not_dvd (n : ℕ) (hn : n ≠ 0) : ∃ p, p.Prime ∧ ¬p ∣ n := by let ⟨p, hp, h_lt, _⟩ := exists_prime_lt_and_le_two_mul n hn exact ⟨p, hp, not_dvd_of_pos_of_lt (Nat.pos_of_ne_zero hn) h_lt⟩
205
leanexplore_declaration
leanexplore:386274
leanexplore_sqlite
leanexplore_declarations
theorem Finset.Coprime_pair_iff (S : Finset ℕ) (a b : ℕ) (h : S = {a, b}) : S.Coprime ↔ Nat.Coprime a b := by simp only [h, Finset.Coprime, Nat.Coprime, gcd_insert, gcd_singleton, normalize_eq] rfl
148
leanexplore_declaration
leanexplore:386275
leanexplore_sqlite
leanexplore_declarations
/-- A Finset of numbers is coprime, or relatively prime, if its `gcd` is 1. -/ @[reducible] def Finset.Coprime (S : Finset ℕ) : Prop := S.gcd id = 1
142
leanexplore_declaration
leanexplore:386276
leanexplore_sqlite
leanexplore_declarations
theorem squarefree_infinite : Set.Infinite { n : ℕ | Squarefree n } := Set.Infinite.mono (fun _ hp ↦ hp.squarefree) Nat.infinite_setOf_prime
191
leanexplore_declaration
leanexplore:386277
leanexplore_sqlite
leanexplore_declarations
/-- The squarefree decomposition of a natural number. -/ theorem squarefreePart_mul_squarePart (n : ℕ) : n.squarefreePart * n.squarePart = n := Nat.mul_div_eq_iff_dvd.2 n.squarefreePart_dvd
66
leanexplore_declaration
leanexplore:386278
leanexplore_sqlite
leanexplore_declarations
theorem squarePart_zero : squarePart 0 = 0 := by simp [squarePart]
150
leanexplore_declaration
leanexplore:386279
leanexplore_sqlite
leanexplore_declarations
/-- The square part is the value of `b ^ 2` in the squarefree decomposition of `n = a₀ * b ^ 2`. -/ def squarePart (n : ℕ) : ℕ := n / n.squarefreePart
249
leanexplore_declaration
leanexplore:386280
leanexplore_sqlite
leanexplore_declarations
theorem squarefreePart_dvd (n : ℕ) : squarefreePart n ∣ n := by rcases eq_or_ne n 0 with (rfl | h₀); simp exact Nat.factorization_prime_le_iff_dvd n.squarefreePart_ne_zero h₀ |>.1 fun p hp ↦ squarefreePart_factorization _ hp ▸ Nat.mod_le _ _
350
leanexplore_declaration
leanexplore:386281
leanexplore_sqlite
leanexplore_declarations
theorem squarefree_squarefreePart (n : ℕ) : Squarefree n.squarefreePart := by refine Nat.squarefree_iff_factorization_le_one n.squarefreePart_ne_zero |>.2 fun p ↦ ?_ by_cases hp : p.Prime · linarith [n.squarefreePart_factorization hp, Nat.mod_lt (n.factorization p) two_pos] · linarith [factorization_eq_zero_of_...
91
leanexplore_declaration
leanexplore:386282
leanexplore_sqlite
leanexplore_declarations
theorem Prime.squarefree {p : ℕ} (hp : p.Prime) : Squarefree p := Irreducible.squarefree hp
518
leanexplore_declaration
leanexplore:386283
leanexplore_sqlite
leanexplore_declarations
/-- If $n = \prod_p p^{e_p}$ is the prime factorization of $n$, then $\prod_p p^{e_p \pmod{2}}$ is the prime factorization of the squarefree part of $n$. -/ theorem squarefreePart_factorization (n : ℕ) {p : ℕ} (hp : p.Prime) : n.squarefreePart.factorization p = n.factorization p % 2 := by rw [squarefreePart, prod...
422
leanexplore_declaration
leanexplore:386284
leanexplore_sqlite
leanexplore_declarations
/-- The squarefree part of any square is `1`. -/ theorem squarefreePart_of_isSquare {n : ℕ} (hn : IsSquare n) : squarefreePart n = 1 := by rcases eq_or_ne n 0 with (rfl | h₀); exact squarefreePart_zero obtain ⟨r, rfl⟩ := hn rw [ne_eq, mul_eq_zero, or_self] at h₀ rw [squarefreePart, Finsupp.prod, support_fac...
441
leanexplore_declaration
leanexplore:386285
leanexplore_sqlite
leanexplore_declarations
/-- If `n` is squarefree, then its squarefree part is itself. -/ theorem squarefreePart_of_squarefree {n : ℕ} (hn : Squarefree n) : squarefreePart n = n := by nth_rw 2 [← n.factorization_prod_pow_eq_self fun _ ↦ by simp_all] simp only [squarefreePart, Finsupp.prod, support_factorization] exact Finset.prod_con...
80
leanexplore_declaration
leanexplore:386286
leanexplore_sqlite
leanexplore_declarations
theorem squarefreePart_zero : squarefreePart 0 = 1 := by simp [squarefreePart]