remove matrix.rank file

This commit is contained in:
jstoobysmith 2024-06-27 08:43:57 -04:00
parent 04df500fae
commit f92291885a
2 changed files with 1 additions and 89 deletions

View file

@ -1,85 +0,0 @@
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
import Mathlib.LinearAlgebra.UnitaryGroup
import Mathlib.Data.Complex.Exponential
import Mathlib.Tactic.Polyrith
import LeanCopilot
/-!
# Rank of matrices
This field contains addiational lemmas and results about the rank of matrices beyond
those which appear in Mathlib.
Our method is to provide a certificate checker for the rank of the matrix.
## TODO
- Automate, following the method of `polyrith`, the process of finding the
row-reduced form of a matrix.
-/
namespace Mathematics
variable {n m : }
open Matrix
/-- The proposition on a matrix for it to be in row echelon form. -/
def IsRowEchelonForm (M : Matrix (Fin n) (Fin m) ) : Prop :=
∀ i j, i < j →
match Fin.find (fun k => M i k ≠ 0), Fin.find (fun k => M j k ≠ 0) with
| some i', some j' => i' < j'
| some _, none => true
| none, some _ => false
| none, none => true
instance (M : Matrix (Fin n) (Fin m) ) : Decidable (IsRowEchelonForm M) := by
refine @Fintype.decidableForallFintype _ _ (fun i => ?_) _
refine @Fintype.decidableForallFintype _ _ (fun j => ?_) _
refine @instDecidableForall _ _ (i.decLt j) ?_
match Fin.find (fun k => M i k ≠ 0), Fin.find (fun k => M j k ≠ 0) with
| some i', some j' => exact i'.decLt j'
| some _, none => exact true.decEq true
| none, some _ => exact false.decEq true
| none, none => exact true.decEq true
example : IsRowEchelonForm !![1, 2, 3; 0, 1, 3; 0, 0, 1] := by
decide
example : ¬ IsRowEchelonForm !![1, 2, 3; 0, 1, 3; 0, 2, 1] := by
decide
/-- `M` is a row echelon form of `N`. -/
structure RowEchelonFormOf (M : Matrix (Fin n) (Fin m) ) where
rowEchelonForm : Matrix (Fin n) (Fin m)
transform : Matrix (Fin n) (Fin n)
transformInv : Matrix (Fin n) (Fin n)
transform_invert : transform * transformInv = 1 := by norm_num <;> decide
transform_mul : transform * M = rowEchelonForm := by norm_num
rowEchelonForm_isRowEchelonForm : IsRowEchelonForm rowEchelonForm := by decide
def sageRowEchelonFormQuery (M : Matrix (Fin n) (Fin m) ) : IO Unit :=
let M := List.map (fun i =>
String.intercalate ", " (List.map (fun j => toString (M i j)) (Fin.list m))) (Fin.list n)
let echelonForm :=
"M = Matrix([[" ++ String.intercalate "],[" M ++ "]])
REF, P = M.echelon_form(transformation=True)
def format(matrix):
rows = []
for row in matrix.rows():
rows.append(', '.join(map(str, row)))
return \"!![\" + \"; \".join(rows) + \"]\"
print(f\"rowEchelonForm := {format(REF)}\")
print(f\"transform := {format(P)}\")
print(f\"transformInv := {format(P.inverse())}\")"
IO.println (echelonForm)
def myTestMatrix : RowEchelonFormOf !![1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12] where
rowEchelonForm := !![1, 2, 3; 0, 3, 6; 0, 0, 0; 0, 0, 0]
transform := !![0, 0, 3, -2; 0, 0, 10, -7; 1, 0, -3, 2; 0, 1, -2, 1]
transformInv := !![1, 0, 1, 0; 4, -1, 0, 1; 7, -2, 0, 0; 10, -3, 0, 0]
end Mathematics

View file

@ -22,11 +22,9 @@ The functions
are adapted from `batteries.scripts.check_imports.lean` authored by Joe Hendrix.
-/
open Lean System Meta
/-- Recursively finds files in directory. -/
partial def addModulesIn (recurse : Bool) (prev : Array Name) (root : Name := .anonymous)
(path : FilePath) : IO (Array Name) := do
@ -41,7 +39,6 @@ partial def addModulesIn (recurse : Bool) (prev : Array Name) (root : Name := .a
r := r.push (root.mkStr mod)
pure r
/-- Compute imports expected by `HepLean.lean` by looking at file structure. -/
def expectedHepLeanImports : IO (Array Name) := do
let mut needed := #[]
@ -80,7 +77,7 @@ def checkMissingImports (modData : ModuleData) (reqImports : Array Name) :
def main (_ : List String) : IO UInt32 := do
initSearchPath (← findSysroot)
let mods : Name := `HepLean
let imp : Import := {module := mods}
let imp : Import := {module := mods}
let mFile ← findOLean imp.module
unless (← mFile.pathExists) do
throw <| IO.userError s!"object file '{mFile}' of module {imp.module} does not exist"