Skip to content

Commit 612daaa

Browse files
committed
...
1 parent 05eefaa commit 612daaa

File tree

18 files changed

+153
-166
lines changed

18 files changed

+153
-166
lines changed

SciLean/Analysis/Calculus/Monad/StateT.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ instance (S : Type) [NormedAddCommGroup S] [NormedSpace K S] :
2626

2727
DifferentiableM_bind f g hf hg :=
2828
by
29-
simp; simp at hf; simp at hg
3029
simp[bind, StateT.bind]
3130
fun_prop
3231

3332
DifferentiableM_pair f hf :=
3433
by
35-
simp; simp at hf
3634
simp[bind, StateT.bind, pure, StateT.pure, Functor.map]
37-
simp only [StateT.map]
3835
fun_prop
3936

4037

SciLean/Analysis/Scalar/Basic.lean

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace SciLean
1919

2020
open Classical
2121

22+
2223
/-- `K` are real or complex numbers over real numbers `R`
2324
2425
This class allows us to write code independent of particular implementation of real or complex numbers.
@@ -115,7 +116,9 @@ This class allows us to write code independent of particular implementation of r
115116
116117
See `Scalar` for motivation for this class.
117118
-/
118-
class RealScalar (R :(Type _)) extends Scalar R R, LinearOrder R where
119+
class RealScalar (R : Type*) extends Scalar R R where
120+
[order : LinearOrder R]
121+
119122
is_real : ∀ x : R, im x = 0
120123

121124
asin (x : R) : R
@@ -127,6 +130,8 @@ class RealScalar (R :(Type _)) extends Scalar R R, LinearOrder R where
127130
atan (x : R) : R
128131
atan_def : ∀ x, toReal (atan x) = Real.arctan (toReal x)
129132

133+
instance {R : Type*} [RealScalar R] : LinearOrder R := RealScalar.order
134+
130135
def RealScalar.pi [RealScalar R] : R := RealScalar.acos (-1)
131136

132137
scoped notation "π" => @RealScalar.pi defaultScalar% inferInstance
@@ -282,10 +287,10 @@ noncomputable instance : RealScalar ℝ where
282287
pow_def := by intros; simp; rfl
283288

284289
abs x := abs x
285-
abs_def := by intros; simp; sorry_proof
290+
abs_def := by intros; sorry_proof
286291

287292
tgamma x := x.Gamma
288-
tgamma_def := by intros; simp; sorry_proof
293+
tgamma_def := by intros;sorry_proof
289294

290295
lgamma x := |x.Gamma|.log
291296
lgamma_def := by intros; simp; sorry_proof
@@ -296,36 +301,7 @@ noncomputable instance : RealScalar ℝ where
296301
isNaN x := false
297302
isInf x := false
298303

299-
le_total := by sorry_proof
300-
301-
decidableLE x y :=
302-
have := Classical.propDecidable
303-
if h : x ≤ y then
304-
.isTrue h
305-
else
306-
.isFalse h
307-
308-
decidableEq x y :=
309-
have := Classical.propDecidable
310-
if h : x = y then
311-
.isTrue h
312-
else
313-
.isFalse h
314-
315-
decidableLT x y :=
316-
have := Classical.propDecidable
317-
if h : x < y then
318-
.isTrue h
319-
else
320-
.isFalse h
321-
322-
min := fun a b => if a ≤ b then a else b
323-
max := fun a b => if a ≤ b then b else a
324-
min_def := by sorry_proof
325-
max_def := by sorry_proof
326-
compare a b := compareOfLessAndEq a b
327-
compare_eq_compareOfLessAndEq := by
328-
compareOfLessAndEq_rfl
304+
order := by infer_instance
329305

330306

331307

SciLean/Analysis/Scalar/FloatAsReal.lean

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,17 @@ instance : RealScalar Float where
213213
isInf x := x.isInf
214214
isFinite x := x.isFinite
215215

216-
le_total := by sorry_proof
217-
decidableLE := inferInstance
218-
decidableEq := inferInstance
219-
decidableLT := inferInstance
220-
221-
min_def := by sorry_proof
222-
max_def := by sorry_proof
223-
compare x y := compare x y
224-
compare_eq_compareOfLessAndEq := by sorry_proof
216+
order := {
217+
le_total := by sorry_proof
218+
decidableLE := inferInstance
219+
decidableEq := inferInstance
220+
decidableLT := inferInstance
221+
222+
min_def := by sorry_proof
223+
max_def := by sorry_proof
224+
compare x y := compare x y
225+
compare_eq_compareOfLessAndEq := by sorry_proof
226+
}
225227

226228

227229
open ComplexConjugate

SciLean/Data/DataArray/Basis.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ instance (priority:=high) : CanonicalBasis I R (R^[I]) where
1313
dualBasis i := setElem (0 : R^[I]) i 1 .intro
1414
proj i x := x[i]
1515
dualProj i x := x[i]
16-
basis_complete := by intros; ext i; simp[sum_pull]; sorry_proof
16+
basis_complete := by intros; ext i; sorry_proof
1717
proj_basis := by sorry_proof --classical intro i j; by_cases i = j <;> aesop
1818
dualProj_dualBasis := by sorry_proof --classical intro i j; by_cases i = j <;> aesop
1919
inner_basis_dualBasis := sorry_proof

SciLean/Data/DataArray/DataArray.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def DataArray.capacity (arr : DataArray α) : Squash Nat := Quot.mk _ (pd.capaci
9090
-- arr' := arr'.set ⟨i.1,sorry_proof⟩ (arr.get i)
9191
-- arr'
9292

93-
def DataArray.mkEmpty (capacity : Nat) : DataArray α := Id.run do
93+
def DataArray.emptyWithCapacity (capacity : Nat) : DataArray α := Id.run do
9494
let newBytes := pd.bytes capacity
95-
{ byteData := .mkEmpty newBytes
95+
{ byteData := .emptyWithCapacity newBytes
9696
h_size := by sorry_proof }
9797

9898
def DataArray.mkZero (n : Nat) : DataArray α := Id.run do
@@ -288,7 +288,7 @@ instance {ι α : Type*} {n} [IndexType ι n] [pd : PlainDataType α] :
288288

289289
fromByteArray := λ b i h =>
290290
let N := pd.bytes n
291-
let bi := b.copySlice (i.toNat) (ByteArray.mkEmpty N) 0 N
291+
let bi := b.copySlice (i.toNat) (ByteArray.emptyWithCapacity N) 0 N
292292
⟨⟨bi,sorry_proof⟩,sorry_proof⟩
293293
toByteArray := λ b i h c => Id.run do
294294
let N := pd.bytes n
@@ -382,7 +382,7 @@ def DataArrayN.row (x : X^[I,J]) (i : I) := x.curry[i]
382382

383383
def DataArrayN.col (x : X^[I,J]) (j : J) : X^[I] := Id.run do
384384
let xdata := x.1.1
385-
let mut data := ByteArray.mkEmpty (pd.bytes nI)
385+
let mut data := ByteArray.emptyWithCapacity (pd.bytes nI)
386386
let offset := (toIdx j).1
387387
let width := (pd.bytes 1).toUSize
388388
let stride := (pd.bytes nJ).toUSize

SciLean/Data/DataArray/TensorOperations.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ def sumMiddleR (x : R^[I,J,K]) : R^[I,K] := Id.run do
4343

4444
variable (I) in
4545
def replicateRowR (r : R^[J]) : R^[I,J] :=
46-
let data : DataArray R := DataArray.mkEmpty (nI*nJ)
46+
let data : DataArray R := DataArray.emptyWithCapacity (nI*nJ)
4747
⟨data.pushArray r.1 nI, sorry_proof⟩
4848

4949

5050
variable (J) in
5151
def replicateColR (r : R^[I]) : R^[I,J] := Id.run do
52-
let mut data : DataArray R := DataArray.mkEmpty (nI*nJ)
52+
let mut data : DataArray R := DataArray.emptyWithCapacity (nI*nJ)
5353
for i in fullRange I do
5454
data := data.push r[i] nJ
5555
⟨data, sorry_proof⟩
5656

5757
variable (J) in
5858
def replicateMiddleR (x : R^[I,K]) : R^[I,J,K] := Id.run do
59-
let mut data : DataArray R := DataArray.mkEmpty (nI*nJ*nK)
59+
let mut data : DataArray R := DataArray.emptyWithCapacity (nI*nJ*nK)
6060
for i in fullRange I do
6161
-- TODO: fix this! it is slow! we make copies of `x`'s rows
6262
data := data.pushArray (x.curry[i]).1 nJ

SciLean/Data/StructType/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ instance (priority:=low+1) instStrucTypePiSimple
123123
right_inv := by simp[Function.RightInverse, LeftInverse]
124124
structProj_structModify := by simp
125125
structProj_structModify' := by
126-
intro i i'; intros _ _ H; simp
126+
intro i i'; intros _ _ H
127127
if h: i' = i then
128128
simp [h] at H
129129
else
@@ -162,7 +162,7 @@ instance instStrucTypeArrowSimple
162162
right_inv := by simp[Function.RightInverse, LeftInverse]
163163
structProj_structModify := by simp
164164
structProj_structModify' := by
165-
intro j j' f x H; simp
165+
intro j j' f x H
166166
if h: j' = j then
167167
simp [h] at H
168168
else

SciLean/Data/Vector.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ instance [Add X] : Add (Vector X n) := ⟨fun x y => x.mapFinIdx fun i xi _ => x
4545
instance [Sub X] : Sub (Vector X n) := ⟨fun x y => x.mapFinIdx fun i xi _ => xi - y[i]⟩
4646
instance [Neg X] : Neg (Vector X n) := ⟨fun x => x.map fun xi => -xi⟩
4747
instance [SMul R X] : SMul R (Vector X n) := ⟨fun r x => x.map fun xi => r • xi⟩
48-
instance [Zero X] : Zero (Vector X n) := ⟨⟨Array.mkArray n (0:X), by simp⟩⟩
48+
instance [Zero X] : Zero (Vector X n) := ⟨⟨Array.replicate n (0:X), by simp⟩⟩
4949

5050
@[simp, simp_core]
5151
theorem Vector.getElem_add [Add X] (x y : Vector X n) (i : ℕ) (h : i < n) : (x + y)[i] = x[i] + y[i] := by

SciLean/Lean/Meta/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def mkAppNoTrailingM (constName : Name) (xs : Array Expr) : MetaM Expr := do
144144
-- number of arguments to apply
145145
let argCount := explicitArgIds[xs.size]? |>.getD n
146146

147-
let mut args : Array (Option Expr) := Array.mkArray argCount none
147+
let mut args : Array (Option Expr) := Array.replicate argCount none
148148
for i in [0:xs.size] do
149149
args := args.set! explicitArgIds[i]! (.some xs[i]!)
150150

@@ -203,7 +203,7 @@ def mkProdProj (x : Expr) (i : Nat) (n : Nat) (fst := ``Prod.fst) (snd := ``Prod
203203

204204

205205
def mkProdSplitElem (xs : Expr) (n : Nat) (fst := ``Prod.fst) (snd := ``Prod.snd) : MetaM (Array Expr) :=
206-
(Array.mkArray n 0)
206+
(Array.replicate n 0)
207207
|>.mapIdx (λ i _ => i)
208208
|>.mapM (λ i => mkProdProj xs i n fst snd)
209209

SciLean/Modules/DDG/SurfaceMesh.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ https://github.com/GeometryCollective/geometry-processing-js/blob/c7ea47ae808979
88
-/
99

1010
import SciLean.Data.DataArray.FloatN
11-
import Lean.Data.HashMap
1211

1312
open Lean Data
1413

0 commit comments

Comments
 (0)