-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:lecopivo/SciLean
- Loading branch information
Showing
10 changed files
with
371 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mcr.microsoft.com/devcontainers/base:jammy | ||
|
||
USER vscode | ||
WORKDIR /home/vscode | ||
ENV HOME=/home/vscode | ||
|
||
RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- -y --default-toolchain none | ||
|
||
ENV PATH="/home/vscode/.elan/bin:${PATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu | ||
{ | ||
"name": "Lean DevContainer on Ubuntu", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
|
||
"onCreateCommand": "lake exe cache get! && lake build", | ||
|
||
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", | ||
|
||
"customizations": { | ||
"vscode" : { | ||
"extensions" : [ | ||
"leanprover.lean4", | ||
"mhutchie.git-graph" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import SciLean.Data.IndexType | ||
|
||
namespace SciLean | ||
|
||
/-- Give `Fin n₁ × ... × Fin nₘ` for a list `[n₁,..., nₘ]` -/ | ||
def FinProd : List Nat → Type | ||
| [] => Unit | ||
| [n] => Fin n | ||
| n :: (m :: ns) => Fin n × FinProd (m :: ns) | ||
|
||
instance instIndexTypeFinProd (l : List Nat) : IndexType (FinProd l) := | ||
match l with | ||
| [] => by simp[FinProd]; infer_instance | ||
| [n] => by simp[FinProd]; infer_instance | ||
| n :: m :: ns => | ||
have e := instIndexTypeFinProd (m :: ns) | ||
by simp[FinProd]; infer_instance | ||
|
||
instance instToStringFinProd (l : List Nat) : ToString (FinProd l) := | ||
match l with | ||
| [] => by simp[FinProd]; infer_instance | ||
| [n] => by simp[FinProd]; infer_instance | ||
| n :: m :: ns => | ||
have e := instToStringFinProd (m :: ns) | ||
by simp[FinProd]; infer_instance | ||
|
||
/-- Given `(i₁, ..., iₘ) : Fin n₁ × ... × Fin nₘ` return `[i₁.1,..., iₘ.1]` -/ | ||
def FinProd.toList {l} (is : FinProd l) : List Nat := | ||
match l, is with | ||
| [], _ => [] | ||
| [_], i => [i.1] | ||
| _ :: _ :: _, (i, is) => i :: is.toList | ||
|
||
/-- Given `(i₁, ..., iₘ) : Fin n₁ × ... × Fin nₘ` return `[n₁-i₁.1-1,..., nₘ-iₘ.1-1]` -/ | ||
def FinProd.toListComplement {l} (is : FinProd l) : List Nat := | ||
match l, is with | ||
| [], _ => [] | ||
| [n], i => [n-i.1-1] | ||
| n :: _ :: _, (i, is) => (n-i.1-1) :: is.toListComplement | ||
|
||
|
||
-- #eval show IO Unit from do | ||
-- let l := [2,3,4] | ||
-- let N := size (FinProd l) | ||
-- for i in fullRange (Fin N) do | ||
-- let x : FinProd l := IndexType.fromFin i | ||
-- IO.println s!"{x}" | ||
|
||
-- IO.println "hoho" | ||
|
||
-- for i in fullRange (FinProd [2,3]) do | ||
-- IO.println s!"{i}" | ||
|
||
-- IO.println "hihi" | ||
|
||
|
||
--- tests | ||
example : FinProd [] = Unit := by rfl | ||
example (n) : FinProd [n] = (Fin n) := by rfl | ||
example (n m) : FinProd [n,m] = (Fin n × Fin m) := by rfl | ||
example : FinProd [1,2,4] = (Fin 1 × Fin 2 × Fin 4) := by rfl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.