Skip to content

Commit c8fbb5b

Browse files
committed
Add matrix definitions and utility functions for probabilistic operations
1 parent 211ac4c commit c8fbb5b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import Mathlib.Data.Matrix.Basic
2+
import Mathlib.Data.Matrix.Basis
23

34
def matrix1 : Matrix (Fin 2) (Fin 3) Nat := ![![1, 2, 3], ![4, 5, 6]]
45
def matrix2 : Matrix (Fin 3) (Fin 2) Nat := ![![1, 2], ![3, 4], ![5, 6]]
56

67
#eval matrix1
78
#eval matrix1 * matrix2
9+
10+
11+
def matrix3 : Matrix (Fin 11) (Fin 11) Nat := 0
12+
13+
def manualBasisMatrix (row col : Fin 3) : Matrix (Fin 3) (Fin 3) Nat :=
14+
fun i j => if i = row ∧ j = col then 1 else 0

ProgramAnalysis/ProbabilisticPrograms/PWhile.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module
22
public import Lean
3+
public import Mathlib.Data.Matrix.Basic
4+
public import Mathlib.Data.Finset.Basic
35

46
namespace ProgramAnalysis.ProbabilisticPrograms
57

@@ -371,6 +373,14 @@ def Stmt.size : Stmt → Nat
371373
| .sif _ _ s1 s2 => s1.size + s2.size + 1
372374
| .swhile _ _ s => s.size + 1
373375

376+
def E (size : Nat) (row col : Fin size) : Matrix (Fin size) (Fin size) (Fin 2) :=
377+
fun i j => if i = row ∧ j = col then 1 else 0
378+
379+
def U (s : Finset Nat) (f : s → s) : Matrix s s (Fin 2) :=
380+
fun i j => if f i = j then 1 else 0
381+
382+
def P (s : Finset Nat) (f : s → Bool) : Matrix s s (Fin 2) :=
383+
fun i j => if i = j ∧ f i then 1 else 0
374384

375385

376386
end ProgramAnalysis.ProbabilisticPrograms

0 commit comments

Comments
 (0)