Skip to content

Commit 8c919ec

Browse files
committed
...
1 parent 612daaa commit 8c919ec

14 files changed

Lines changed: 245 additions & 240 deletions

SciLean.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import SciLean.AD.HasVecFwdFDeriv
77
import SciLean.AD.HasVecRevFDeriv
88
import SciLean.AD.RevFDeriv
99
import SciLean.AD.Rules.Common
10+
import SciLean.AD.Rules.DataArrayN.Det
1011
import SciLean.AD.Rules.DataArrayN.FromRn
1112
import SciLean.AD.Rules.DataArrayN.Logsumexp
13+
import SciLean.AD.Rules.DataArrayN.Minor
1214
import SciLean.AD.Rules.DataArrayN.RSum
1315
import SciLean.AD.Rules.DataArrayN.Reshape
1416
import SciLean.AD.Rules.DataArrayN.ScalAdd
@@ -32,14 +34,17 @@ import SciLean.Algebra.IsAddGroupHom
3234
import SciLean.Algebra.IsAffineMap
3335
import SciLean.Algebra.IsLinearMap
3436
import SciLean.Algebra.MatrixType.Basic
37+
import SciLean.Algebra.TensorProduct.Assoc
3538
import SciLean.Algebra.TensorProduct.Basic
39+
import SciLean.Algebra.TensorProduct.Curry
3640
import SciLean.Algebra.TensorProduct.MatMul
3741
import SciLean.Algebra.TensorProduct.Pi
3842
import SciLean.Algebra.TensorProduct.Prod
3943
import SciLean.Algebra.TensorProduct.ProdMatrix
4044
import SciLean.Algebra.TensorProduct.ProdMatrixCol
4145
import SciLean.Algebra.TensorProduct.ProdMatrixRow
4246
import SciLean.Algebra.TensorProduct.Self
47+
import SciLean.Algebra.TensorProduct.Swap
4348
import SciLean.Algebra.TensorProduct.Transpose
4449
import SciLean.Algebra.TensorProduct.Util
4550
import SciLean.Algebra.VectorOptimize.Basic
@@ -381,6 +386,7 @@ import SciLean.Data.DataArray.TensorProduct
381386
import SciLean.Data.FinProd
382387
import SciLean.Data.Float
383388
import SciLean.Data.FloatArray
389+
import SciLean.Data.FloatExtern
384390
import SciLean.Data.Function
385391
import SciLean.Data.Idx
386392
import SciLean.Data.Idx.Basic
@@ -399,6 +405,7 @@ import SciLean.Data.IndexType.TensorIndex
399405
import SciLean.Data.Instances.Sigma
400406
import SciLean.Data.Int64
401407
import SciLean.Data.ListN
408+
import SciLean.Data.Nat
402409
import SciLean.Data.Prod
403410
import SciLean.Data.Random
404411
import SciLean.Data.SparseMatrix.Basic
@@ -431,12 +438,17 @@ import SciLean.Data.VectorType.Base
431438
-- import SciLean.Data.VectorType.VectorType_old.Scalar
432439
-- import SciLean.Data.VectorType.VectorType_old.Subvector
433440
-- import SciLean.Doodle
441+
-- import SciLean.Doodle14
434442
-- import SciLean.Examples.GMM.Main
435443
-- import SciLean.Examples.GMM.Objective
436444
-- import SciLean.Examples.GMM.ObjectiveDirect
437445
-- import SciLean.Examples.GMM.Simps
438446
-- import SciLean.Examples.GMM.SumSimproc
439447
-- import SciLean.Examples.GMM.Util
448+
import SciLean.FFI
449+
import SciLean.FFI.ByteArray
450+
import SciLean.FFI.Float
451+
import SciLean.FFI.FloatArray
440452
-- import SciLean.Geometry.Bezier
441453
import SciLean.Geometry.BoundingBall
442454
import SciLean.Geometry.FrontierSpeed

SciLean/Algebra/TensorProduct/Assoc.lean

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,71 @@ import SciLean.Algebra.TensorProduct.Basic
33

44
namespace SciLean
55

6-
#exit
7-
class TensorProductAssoc
8-
(R X Y Z : Type*) {XY YZ XY_Z X_YZ : Type*} [RCLike R]
9-
[NormedAddCommGroup X] [AdjointSpace R X]
10-
[NormedAddCommGroup Y] [AdjointSpace R Y]
11-
[NormedAddCommGroup Z] [AdjointSpace R Z]
12-
[NormedAddCommGroup XY] [AdjointSpace R XY]
13-
[NormedAddCommGroup YZ] [AdjointSpace R YZ]
14-
[NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
15-
[NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
16-
[TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
17-
[TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
18-
where
19-
tmulAssoc : XY_Z ≃L[R] X_YZ
20-
21-
assoc_tmul_tmul (x : X) (y : Y) (z : Z):
22-
tmulAssoc ((x ⊗[R] y) ⊗[R] z)
23-
=
24-
x ⊗[R] (y ⊗[R] z)
25-
26-
27-
variable
28-
(R X Y Z XY YZ XY_Z X_YZ : Type*) [RCLike R]
29-
[NormedAddCommGroup X] [AdjointSpace R X]
30-
[NormedAddCommGroup Y] [AdjointSpace R Y]
31-
[NormedAddCommGroup Z] [AdjointSpace R Z]
32-
[NormedAddCommGroup XY] [AdjointSpace R XY]
33-
[NormedAddCommGroup YZ] [AdjointSpace R YZ]
34-
[NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
35-
[NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
36-
[TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
37-
[TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
38-
39-
[TensorProductGetRXY R XY Z XY_Z]
40-
[TensorProductGetRXY R X Y XY]
41-
42-
[TensorProductAssoc R X Y Z]
43-
44-
45-
set_default_scalar R
46-
47-
48-
def tmulAssoc {R X Y Z XY YZ XY_Z X_YZ : Type*} [RCLike R]
49-
[NormedAddCommGroup X] [AdjointSpace R X]
50-
[NormedAddCommGroup Y] [AdjointSpace R Y]
51-
[NormedAddCommGroup Z] [AdjointSpace R Z]
52-
[NormedAddCommGroup XY] [AdjointSpace R XY]
53-
[NormedAddCommGroup YZ] [AdjointSpace R YZ]
54-
[NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
55-
[NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
56-
[TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
57-
[TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
58-
59-
[TensorProductGetRXY R XY Z XY_Z]
60-
[TensorProductGetRXY R X Y XY]
61-
62-
[TensorProductAssoc R X Y Z]:
63-
XY_Z ≃L[R] X_YZ :=
64-
TensorProductAssoc.tmulAssoc X Y Z XY YZ
65-
66-
67-
68-
@[simp, simp_core]
69-
theorem tmul_assoc (x : X) (y : Y) (z : Z) :
70-
tmulAssoc ((x ⊗ y) ⊗ z) = (x ⊗ (y ⊗ z)) := sorry_proof
71-
72-
@[simp, simp_core]
73-
theorem tmul_assoc_symm (x : X) (y : Y) (z : Z) :
74-
tmulAssoc.symm (x ⊗ (y ⊗ z)) = (x ⊗ y) ⊗ z := sorry_proof
6+
-- class TensorProductAssoc
7+
-- (R X Y Z : Type*) {XY YZ XY_Z X_YZ : Type*} [RCLike R]
8+
-- [NormedAddCommGroup X] [AdjointSpace R X]
9+
-- [NormedAddCommGroup Y] [AdjointSpace R Y]
10+
-- [NormedAddCommGroup Z] [AdjointSpace R Z]
11+
-- [NormedAddCommGroup XY] [AdjointSpace R XY]
12+
-- [NormedAddCommGroup YZ] [AdjointSpace R YZ]
13+
-- [NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
14+
-- [NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
15+
-- [TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
16+
-- [TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
17+
-- where
18+
-- tmulAssoc : XY_Z ≃L[R] X_YZ
19+
20+
-- assoc_tmul_tmul (x : X) (y : Y) (z : Z):
21+
-- tmulAssoc ((x ⊗[R] y) ⊗[R] z)
22+
-- =
23+
-- x ⊗[R] (y ⊗[R] z)
24+
25+
26+
-- variable
27+
-- (R X Y Z XY YZ XY_Z X_YZ : Type*) [RCLike R]
28+
-- [NormedAddCommGroup X] [AdjointSpace R X]
29+
-- [NormedAddCommGroup Y] [AdjointSpace R Y]
30+
-- [NormedAddCommGroup Z] [AdjointSpace R Z]
31+
-- [NormedAddCommGroup XY] [AdjointSpace R XY]
32+
-- [NormedAddCommGroup YZ] [AdjointSpace R YZ]
33+
-- [NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
34+
-- [NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
35+
-- [TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
36+
-- [TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
37+
38+
-- [TensorProductGetRXY R XY Z XY_Z]
39+
-- [TensorProductGetRXY R X Y XY]
40+
41+
-- [TensorProductAssoc R X Y Z]
42+
43+
44+
-- set_default_scalar R
45+
46+
47+
-- def tmulAssoc {R X Y Z XY YZ XY_Z X_YZ : Type*} [RCLike R]
48+
-- [NormedAddCommGroup X] [AdjointSpace R X]
49+
-- [NormedAddCommGroup Y] [AdjointSpace R Y]
50+
-- [NormedAddCommGroup Z] [AdjointSpace R Z]
51+
-- [NormedAddCommGroup XY] [AdjointSpace R XY]
52+
-- [NormedAddCommGroup YZ] [AdjointSpace R YZ]
53+
-- [NormedAddCommGroup XY_Z] [AdjointSpace R XY_Z]
54+
-- [NormedAddCommGroup X_YZ] [AdjointSpace R X_YZ]
55+
-- [TensorProductType R X Y XY] [TensorProductType R Y Z YZ]
56+
-- [TensorProductType R XY Z XY_Z] [TensorProductType R X YZ X_YZ]
57+
58+
-- [TensorProductGetRXY R XY Z XY_Z]
59+
-- [TensorProductGetRXY R X Y XY]
60+
61+
-- [TensorProductAssoc R X Y Z]:
62+
-- XY_Z ≃L[R] X_YZ :=
63+
-- TensorProductAssoc.tmulAssoc X Y Z XY YZ
64+
65+
66+
67+
-- @[simp, simp_core]
68+
-- theorem tmul_assoc (x : X) (y : Y) (z : Z) :
69+
-- tmulAssoc ((x ⊗ y) ⊗ z) = (x ⊗ (y ⊗ z)) := sorry_proof
70+
71+
-- @[simp, simp_core]
72+
-- theorem tmul_assoc_symm (x : X) (y : Y) (z : Z) :
73+
-- tmulAssoc.symm (x ⊗ (y ⊗ z)) = (x ⊗ y) ⊗ z := sorry_proof

SciLean/Algebra/TensorProduct/Curry.lean

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,82 @@ import SciLean.Analysis.AdjointSpace.CanonicalBasis
33

44
namespace SciLean
55

6-
#exit
7-
class TensorProductCurry (𝕜 X Y Z : Type*)
8-
[RCLike 𝕜]
9-
[NormedAddCommGroup X] [AdjointSpace 𝕜 X]
10-
[NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
11-
[NormedAddCommGroup Z] [AdjointSpace 𝕜 Z]
12-
{XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY]
13-
[TensorProductType 𝕜 X Y XY]
14-
where
15-
tcurry : (X ⊗[𝕜] Y →L[𝕜] Z) ≃L[𝕜] (X →L[𝕜] Y →L[𝕜] Z)
16-
17-
export TensorProductCurry (tcurry)
18-
19-
class TensorBasis (𝕜 X Y XY : Type*)
20-
[RCLike 𝕜] [NormedAddCommGroup X] [AdjointSpace 𝕜 X]
21-
[NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
22-
{XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY] [TensorProductType 𝕜 X Y XY]
23-
{I} [Fintype I] [CanonicalBasis I 𝕜 X]
24-
{J} [Fintype J] [CanonicalBasis J 𝕜 Y]
25-
[CanonicalBasis (I×J) 𝕜 XY] : Prop where
26-
basis_eq_tmul_basis : ∀ i j, ⅇ[𝕜,XY,(i,j)] = ⅇ[𝕜,X,i] ⊗[𝕜] ⅇ[𝕜,Y,j]
27-
28-
29-
variable
30-
{𝕜 X Y Z W : Type*}
31-
[RCLike 𝕜]
32-
[NormedAddCommGroup X] [AdjointSpace 𝕜 X]
33-
[NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
34-
[NormedAddCommGroup Z] [AdjointSpace 𝕜 Z]
35-
[NormedAddCommGroup W] [AdjointSpace 𝕜 W]
36-
{XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY] [TensorProductType 𝕜 X Y XY]
37-
{YX : Type*} [NormedAddCommGroup YX] [AdjointSpace 𝕜 YX] [TensorProductType 𝕜 Y X YX]
38-
{ZW : Type*} [NormedAddCommGroup ZW] [AdjointSpace 𝕜 ZW] [TensorProductType 𝕜 Z W ZW]
39-
{I} [Fintype I] [CanonicalBasis I 𝕜 X]
40-
{J} [Fintype J] [CanonicalBasis J 𝕜 Y]
41-
[CanonicalBasis (I×J) 𝕜 XY] [TensorBasis 𝕜 X Y XY]
42-
43-
44-
@[fun_prop]
45-
theorem tmul.arg_xy.Continuous_rule : Continuous (fun xy : X×Y => xy.1⊗[𝕜]xy.2) := sorry_proof
46-
@[fun_prop]
47-
theorem tmul.arg_x.IsContinuousLinearMap_rule (y : Y) : IsContinuousLinearMap 𝕜 (fun x : X => x⊗[𝕜]y) := sorry_proof
48-
@[fun_prop]
49-
theorem tmul.arg_y.IsContinuousLinearMap_rule (x : X) : IsContinuousLinearMap 𝕜 (fun y : Y => x⊗[𝕜]y) := sorry_proof
50-
51-
52-
set_default_scalar 𝕜
53-
6+
-- class TensorProductCurry (𝕜 X Y Z : Type*)
7+
-- [RCLike 𝕜]
8+
-- [NormedAddCommGroup X] [AdjointSpace 𝕜 X]
9+
-- [NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
10+
-- [NormedAddCommGroup Z] [AdjointSpace 𝕜 Z]
11+
-- {XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY]
12+
-- [TensorProductType 𝕜 X Y XY]
13+
-- where
14+
-- tcurry : (X ⊗[𝕜] Y →L[𝕜] Z) ≃L[𝕜] (X →L[𝕜] Y →L[𝕜] Z)
15+
16+
-- export TensorProductCurry (tcurry)
17+
18+
-- class TensorBasis (𝕜 X Y XY : Type*)
19+
-- [RCLike 𝕜] [NormedAddCommGroup X] [AdjointSpace 𝕜 X]
20+
-- [NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
21+
-- {XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY] [TensorProductType 𝕜 X Y XY]
22+
-- {I} [Fintype I] [CanonicalBasis I 𝕜 X]
23+
-- {J} [Fintype J] [CanonicalBasis J 𝕜 Y]
24+
-- [CanonicalBasis (I×J) 𝕜 XY] : Prop where
25+
-- basis_eq_tmul_basis : ∀ i j, ⅇ[𝕜,XY,(i,j)] = ⅇ[𝕜,X,i][𝕜][𝕜,Y,j]
26+
27+
28+
-- variable
29+
-- {𝕜 X Y Z W : Type*}
30+
-- [RCLike 𝕜]
31+
-- [NormedAddCommGroup X] [AdjointSpace 𝕜 X]
32+
-- [NormedAddCommGroup Y] [AdjointSpace 𝕜 Y]
33+
-- [NormedAddCommGroup Z] [AdjointSpace 𝕜 Z]
34+
-- [NormedAddCommGroup W] [AdjointSpace 𝕜 W]
35+
-- {XY : Type*} [NormedAddCommGroup XY] [AdjointSpace 𝕜 XY] [TensorProductType 𝕜 X Y XY]
36+
-- {YX : Type*} [NormedAddCommGroup YX] [AdjointSpace 𝕜 YX] [TensorProductType 𝕜 Y X YX]
37+
-- {ZW : Type*} [NormedAddCommGroup ZW] [AdjointSpace 𝕜 ZW] [TensorProductType 𝕜 Z W ZW]
38+
-- {I} [Fintype I] [CanonicalBasis I 𝕜 X]
39+
-- {J} [Fintype J] [CanonicalBasis J 𝕜 Y]
40+
-- [CanonicalBasis (I×J) 𝕜 XY] [TensorBasis 𝕜 X Y XY]
41+
42+
43+
-- @[fun_prop]
44+
-- theorem tmul.arg_xy.Continuous_rule : Continuous (fun xy : X×Y => xy.1⊗[𝕜]xy.2) := sorry_proof
45+
-- @[fun_prop]
46+
-- theorem tmul.arg_x.IsContinuousLinearMap_rule (y : Y) : IsContinuousLinearMap 𝕜 (fun x : X => x⊗[𝕜]y) := sorry_proof
47+
-- @[fun_prop]
48+
-- theorem tmul.arg_y.IsContinuousLinearMap_rule (x : X) : IsContinuousLinearMap 𝕜 (fun y : Y => x⊗[𝕜]y) := sorry_proof
49+
50+
51+
-- set_default_scalar 𝕜
52+
53+
-- -- noncomputable
54+
-- -- def tcurry : (X ⊗[𝕜] Y →L[𝕜] Z) ≃L[𝕜] (X →L[𝕜] Y →L[𝕜] Z) where
55+
-- -- toFun := fun f => fun x =>L[𝕜] fun y =>L[𝕜] f (x⊗y)
56+
-- -- invFun := fun f => fun xy =>L[𝕜] ∑ (i : I) (j : J), ⟪ⅇ'[X,i]⊗ⅇ'[Y,j], xy⟫ • f ⅇ[X,i][Y,j]
57+
-- -- map_add' := sorry_proof
58+
-- -- map_smul' := sorry_proof
59+
-- -- left_inv := sorry_proof
60+
-- -- right_inv := sorry_proof
61+
-- -- continuous_toFun := by sorry_proof
62+
-- -- continuous_invFun := by sorry_proof
63+
64+
65+
66+
-- def tcurry (f : X ⊗[𝕜] Y → Z) (x : X) (y : Y) : Z := f (x⊗y)
67+
68+
69+
-- /--
70+
-- Uncurry bilinear map `f : X → Y → Z` to a linear map over tensor product `X ⊗ Y`
71+
72+
-- It is marker as noncomputable as it is too slow to compute.
73+
-- -/
5474
-- noncomputable
55-
-- def tcurry : (X ⊗[𝕜] Y →L[𝕜] Z) ≃L[𝕜] (X →L[𝕜] Y →L[𝕜] Z) where
56-
-- toFun := fun f => fun x =>L[𝕜] fun y =>L[𝕜] f (x⊗y)
57-
-- invFun := fun f => fun xy =>L[𝕜] ∑ (i : I) (j : J), ⟪ⅇ'[X,i]⊗ⅇ'[Y,j], xy⟫ • f ⅇ[X,i][Y,j]
58-
-- map_add' := sorry_proof
59-
-- map_smul' := sorry_proof
60-
-- left_inv := sorry_proof
61-
-- right_inv := sorry_proof
62-
-- continuous_toFun := by sorry_proof
63-
-- continuous_invFun := by sorry_proof
64-
65-
66-
67-
def tcurry (f : X ⊗[𝕜] Y → Z) (x : X) (y : Y) : Z := f (x⊗y)
75+
-- def tuncurry (f : X → Y → Z) (xy : X⊗Y) : Z := ∑ (i : I) (j : J), ⟪ⅇ[X,i]⊗ⅇ[Y,j], xy⟫ • f ⅇ[X,i][Y,j]
6876

77+
-- /--
78+
-- Combine two linear maps to a single linear map over the tensor product of its domains and codomains.
6979

70-
/--
71-
Uncurry bilinear map `f : X → Y → Z` to a linear map over tensor product `X ⊗ Y`
72-
73-
It is marker as noncomputable as it is too slow to compute.
74-
-/
75-
noncomputable
76-
def tuncurry (f : X → Y → Z) (xy : X⊗Y) : Z := ∑ (i : I) (j : J), ⟪ⅇ[X,i]⊗ⅇ[Y,j], xy⟫ • f ⅇ[X,i] ⅇ[Y,j]
77-
78-
/--
79-
Combine two linear maps to a single linear map over the tensor product of its domains and codomains.
80-
81-
It is marker as noncomputable as it is too slow to compute.
82-
-/
83-
noncomputable
84-
def tmap (f : X → Z) (g : Y → W) (xy : X⊗Y) : Z⊗W :=
85-
∑ (i : I) (j : J), ⟪ⅇ'[X,i]⊗ⅇ'[Y,j], xy⟫ • (f ⅇ[X,i] ⊗ g ⅇ[Y,j])
80+
-- It is marker as noncomputable as it is too slow to compute.
81+
-- -/
82+
-- noncomputable
83+
-- def tmap (f : X → Z) (g : Y → W) (xy : X⊗Y) : Z⊗W :=
84+
-- ∑ (i : I) (j : J), ⟪ⅇ'[X,i]⊗ⅇ'[Y,j], xy⟫ • (f ⅇ[X,i] ⊗ g ⅇ[Y,j])

0 commit comments

Comments
 (0)