SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Shape Safety in Tensor Programming is Easy for a
Theorem Prover
Project: https://github.com/tribbloid/shapesafe
Content: https://github.com/tribbloid/shapesafe-demo
-- Peng Cheng - tribbloid@{github | twitter}
1
About Me
Maintainer of DataPassports, Computing Engine ... 2015 ~
Only read Scala 'cause of Apache Spark
Only read type theory 'cause math seems more stable than programming
Not a Python fan, but only use PyTorch 'cause it is not TensorFlow
Maintainer of splain plugin ... 2021 ~
Partially integrated with scala compiler 2.13.6+ -Vimplicit -Vtype-diff
2
Overview
Why type-safe linear algebra?
How to push it to extreme?
Why scala?
What's next?
3
Why type-safe linear algebra?
4
5
Designed For Human (who make mistakes)
6
OR is it?
(source: https://arxiv.org/abs/2102.06599)
7
How to push it to extreme?
8
Curry-Howard(-Lambek) isomorphism
proof system
functional programming 

(since 1930)
Proposition
type P <: Any (in MLTT) 

type P <: Prop (in CiC)
Proposition type P[_ <: A] , a: {type P}
Inductive Proposition type ::[HEAD, TAIL <: P] <: P
9
... with quantiifiers
proof system functional programming (since 1970)
def p[AS <: A with Singleton](a: AS): P[AS] , 

def p[AS <: A with Singleton](a: AS): AS#P , 

def p(a: A): a.P
def p[B]: P {val b <: B, type P}
Axiom def axiom[X](.): P[X]{.}
Theorem def theorem[X](., lemma1: X => X#L1): P[X]{.}
10
... in shapesafe impl
proof system functional programming (after -expansion)
def p[AS <: A with Singleton]: AS |- P[AS] , 

def p[AS <: A with Singleton]: AS |- AS#P
def p[B]: P {val b <: B, type P}
Axiom def axiom[X]: X |- P[X]{.}
Theorem def theorem[X](lemma1: X => X#L1): X |- P[X]{.}
11
Scala 2.10 - 2015
class Matrix[A,B](val mat: DenseMatrix[Double]) {

def *[C](other: Matrix[B,C]): Matrix[A,C] = new Matrix[A,C](mat*other.mat)

}

class N

class D

class K

val x = new Matrix[N,D](DenseMatrix.rand(100,10))

val y = new Matrix[N,K](DenseMatrix.rand(100,2))

val z1 = x * x //Does not compile!

val z2 = x.t * y //Compiles! Returns a Matrix[D,K]

12
Scala 3.1 - 2021
import scala.compiletime.ops.int._

class Matrix[A, B]():

def *[C](other: Matrix[B, C]): Matrix[A, C] = new Matrix[A, C]()

def conv[C, D](other: Matrix[C, D]): Matrix[A - C + 1, B - D + 1] =

new Matrix[A - C + 1, B - D + 1]()

val x = new Matrix[100, 100]()

val y = new Matrix[3, 3]()

val w = x.conv(y)

val z1 = w * new Matrix[100, 1]() //Does not compile!

val z2 = w * new Matrix[98, 1]() //Compiles!

13
Extreme 1
Weird operands (Seriously, who is going to write compile-time type evaluation for
einsum?)
type EinSum[Matrix[N1 -> D1, N2 -> D2]] = {

if (N1 =:= N2) {

if (D1 =:= D2) {

Matrix[N1 -> D1]

}

else {

error(...)

}

}

else {

Matrix[N1 -> D1, N2 -> D2]

}

}

14
Extreme 2
Symbolic reasoning ( p.apply + =:= can only go in 1 direction)
class Matrix[A, B]():

def +(other: Matrix[A, B]): Matrix[A, B]

def transpose: Matrix[B, A]

def flatten: Matrix[A * B, 1]

type A <: Int

type B <: Int

val m = new Matrix[A, B]()

m.flatten + (m.transpose.flatten) // Oops

15
Learn from
forward mode
lemma and_is_comm (p q: Prop) (h: p ∧ q): q ∧ p := 

and.intro (h.right) (h.left)

tactic mode
lemma and_is_comm' (p q: Prop) (h: p ∧ q): q ∧ p := 

begin

apply and.intro,

exact h.right,

exact h.left,

end

(source: LEAN for Scala programmers - Part 4 - Juan Pablo Romero Méndez) 16
Full auto mode
lemma and_is_comm' (p q: Prop) (h: p ∧ q): q ∧ p := 

begin

assumption,

assumption,

assumption,

end

=:=
begin

assumption | ? => q ∧ p | .intro: (q, p)? => q ∧ p

assumption | p ∧ q => ? | .right: p ∧ q => p?

assumption | p ∧ q => ? | .left: p ∧ q => q?

end

17
... in Scala!
(source: Oron Port's response to "Principles for Implicits in Scala 3" by Odersky)
18
Curry-Howard isomorphism, rewritten
proof system functional programming (full auto!)
def p[AS <: A with Singleton]: AS |- P[AS] , 

def p[AS <: A with Singleton]: AS |- AS#P
def p[BS <: B](implicit b: BS): BS |- BS#P
Axiom def axiom[X]: X |- P[X]{.}
Theorem
def theorem[X](implicit lemma1: X => X#L1): X |-
P[X]{.}
19
<Life Coding>
20
Why Scala
-- Specifically, why scala 2?
21
Stack of AI-HPC-Hardware co-evolution
/ More Abstract
Distributed Computing --- Apache {Spark | Flink}
[ SOME Deep Learning Library? ]
IR/Multi-stage Compilation --- reflection, LMS
Hardware Design --- CHISEL / SpinalHDL
/ More Concrete
22
But try to avoid ...
Diverging implicit
Circular reference def theorem[A](using a: A): A
Expanding reference def theorem[A <: F[_], B](using a: F[A, B]): A
Summoning proof on long algebraic data type
SquashByName[ / ]#On[

SquashByName[ / ]#On[

SquashByName[ + ]#On[

SquashByName[ - ]#On[

SquashByName[ / ]#On[

SquashByName[ + ]#On[

SquashByName[ - ]#On[

SquashByName[ / ]#On[

SquashByName[ + ]#On[

SquashByName[ - ]#On[

1024 >< 1024 |<<- (i >< j) >< (3 >< 3 |<<- (i >< j))...
23
What's next?
Gradually typed ( UncheckedShape ), but still no symbolic reasoning
Fairly stable, but not released or in production
Not a computing library! Cannot empower ML engineers directly, but serve as a
bridge to get there
Need Scala 3 support!
24
Moving to Scala 3?
Pros
Implicit search tree traversal is aggressively cached
No more unpredictable diverging implicit recovery
Theoretically sound resolving of <:< and =:=
Cons
No type projection (may be added back)
No shapeless Record type

(may be integrated into Programmatic Structural Types)

(can be expressed in match type in a very inefficient way)
25
The End Game?
.

.

.

.

.

.

.

.

.

.

.

.
26
Proudly Supported By
™, the Data Privacy & Trust Company
We are hiring! Looking for a director of engineering
Splain Open-Source Team
Looking for scala compiler guru / type theorist as technical advisor
1.0.0RC is close, looking for test users
27

Más contenido relacionado

La actualidad más candente

Cs6503 theory of computation november december 2015 be cse anna university q...
Cs6503 theory of computation november december 2015  be cse anna university q...Cs6503 theory of computation november december 2015  be cse anna university q...
Cs6503 theory of computation november december 2015 be cse anna university q...appasami
 
multi threaded and distributed algorithms
multi threaded and distributed algorithms multi threaded and distributed algorithms
multi threaded and distributed algorithms Dr Shashikant Athawale
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
 
CS2303 Theory of computation April may 2015
CS2303 Theory of computation April may  2015CS2303 Theory of computation April may  2015
CS2303 Theory of computation April may 2015appasami
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming LanguageYutaka Saito
 
Cs6503 theory of computation may june 2016 be cse anna university question paper
Cs6503 theory of computation may june 2016 be cse anna university question paperCs6503 theory of computation may june 2016 be cse anna university question paper
Cs6503 theory of computation may june 2016 be cse anna university question paperappasami
 
Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015appasami
 
Cs6503 theory of computation november december 2016
Cs6503 theory of computation november december 2016Cs6503 theory of computation november december 2016
Cs6503 theory of computation november december 2016appasami
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersappasami
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005Jules Krdenas
 
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkCrystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkJivan Nepali
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaDonghwi Cha
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Piotr Paradziński
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfixSenthil Kumar
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 

La actualidad más candente (20)

Circular queues
Circular queuesCircular queues
Circular queues
 
Cs6503 theory of computation november december 2015 be cse anna university q...
Cs6503 theory of computation november december 2015  be cse anna university q...Cs6503 theory of computation november december 2015  be cse anna university q...
Cs6503 theory of computation november december 2015 be cse anna university q...
 
multi threaded and distributed algorithms
multi threaded and distributed algorithms multi threaded and distributed algorithms
multi threaded and distributed algorithms
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
CS2303 Theory of computation April may 2015
CS2303 Theory of computation April may  2015CS2303 Theory of computation April may  2015
CS2303 Theory of computation April may 2015
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming Language
 
Cs6503 theory of computation may june 2016 be cse anna university question paper
Cs6503 theory of computation may june 2016 be cse anna university question paperCs6503 theory of computation may june 2016 be cse anna university question paper
Cs6503 theory of computation may june 2016 be cse anna university question paper
 
Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015
 
Cs6503 theory of computation november december 2016
Cs6503 theory of computation november december 2016Cs6503 theory of computation november december 2016
Cs6503 theory of computation november december 2016
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005
 
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkCrystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi cha
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
 
Permute
PermutePermute
Permute
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 

Similar a Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021

Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Scalac
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013ericupnorth
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
Parallel Computing with R
Parallel Computing with RParallel Computing with R
Parallel Computing with RAbhirup Mallik
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learningMax Kleiner
 
Functional programming-advantages
Functional programming-advantagesFunctional programming-advantages
Functional programming-advantagesSergei Winitzki
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Ruslan Shevchenko
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
Basic of octave matlab programming language
Basic of octave matlab programming languageBasic of octave matlab programming language
Basic of octave matlab programming languageAulia Khalqillah
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)Eirik George Tsarpalis
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA Japan
 

Similar a Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021 (20)

Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013talk at Virginia Bioinformatics Institute, December 5, 2013
talk at Virginia Bioinformatics Institute, December 5, 2013
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
Matlab1
Matlab1Matlab1
Matlab1
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Parallel Computing with R
Parallel Computing with RParallel Computing with R
Parallel Computing with R
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
Functional programming-advantages
Functional programming-advantagesFunctional programming-advantages
Functional programming-advantages
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version]
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Basic of octave matlab programming language
Basic of octave matlab programming languageBasic of octave matlab programming language
Basic of octave matlab programming language
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)MBrace: Large-scale cloud computation with F# (CUFP 2014)
MBrace: Large-scale cloud computation with F# (CUFP 2014)
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
 

Último

Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Último (20)

Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021

  • 1. Shape Safety in Tensor Programming is Easy for a Theorem Prover Project: https://github.com/tribbloid/shapesafe Content: https://github.com/tribbloid/shapesafe-demo -- Peng Cheng - tribbloid@{github | twitter} 1
  • 2. About Me Maintainer of DataPassports, Computing Engine ... 2015 ~ Only read Scala 'cause of Apache Spark Only read type theory 'cause math seems more stable than programming Not a Python fan, but only use PyTorch 'cause it is not TensorFlow Maintainer of splain plugin ... 2021 ~ Partially integrated with scala compiler 2.13.6+ -Vimplicit -Vtype-diff 2
  • 3. Overview Why type-safe linear algebra? How to push it to extreme? Why scala? What's next? 3
  • 4. Why type-safe linear algebra? 4
  • 5. 5
  • 6. Designed For Human (who make mistakes) 6
  • 7. OR is it? (source: https://arxiv.org/abs/2102.06599) 7
  • 8. How to push it to extreme? 8
  • 9. Curry-Howard(-Lambek) isomorphism proof system functional programming (since 1930) Proposition type P <: Any (in MLTT) type P <: Prop (in CiC) Proposition type P[_ <: A] , a: {type P} Inductive Proposition type ::[HEAD, TAIL <: P] <: P 9
  • 10. ... with quantiifiers proof system functional programming (since 1970) def p[AS <: A with Singleton](a: AS): P[AS] , def p[AS <: A with Singleton](a: AS): AS#P , def p(a: A): a.P def p[B]: P {val b <: B, type P} Axiom def axiom[X](.): P[X]{.} Theorem def theorem[X](., lemma1: X => X#L1): P[X]{.} 10
  • 11. ... in shapesafe impl proof system functional programming (after -expansion) def p[AS <: A with Singleton]: AS |- P[AS] , def p[AS <: A with Singleton]: AS |- AS#P def p[B]: P {val b <: B, type P} Axiom def axiom[X]: X |- P[X]{.} Theorem def theorem[X](lemma1: X => X#L1): X |- P[X]{.} 11
  • 12. Scala 2.10 - 2015 class Matrix[A,B](val mat: DenseMatrix[Double]) { def *[C](other: Matrix[B,C]): Matrix[A,C] = new Matrix[A,C](mat*other.mat) } class N class D class K val x = new Matrix[N,D](DenseMatrix.rand(100,10)) val y = new Matrix[N,K](DenseMatrix.rand(100,2)) val z1 = x * x //Does not compile! val z2 = x.t * y //Compiles! Returns a Matrix[D,K] 12
  • 13. Scala 3.1 - 2021 import scala.compiletime.ops.int._ class Matrix[A, B](): def *[C](other: Matrix[B, C]): Matrix[A, C] = new Matrix[A, C]() def conv[C, D](other: Matrix[C, D]): Matrix[A - C + 1, B - D + 1] = new Matrix[A - C + 1, B - D + 1]() val x = new Matrix[100, 100]() val y = new Matrix[3, 3]() val w = x.conv(y) val z1 = w * new Matrix[100, 1]() //Does not compile! val z2 = w * new Matrix[98, 1]() //Compiles! 13
  • 14. Extreme 1 Weird operands (Seriously, who is going to write compile-time type evaluation for einsum?) type EinSum[Matrix[N1 -> D1, N2 -> D2]] = { if (N1 =:= N2) { if (D1 =:= D2) { Matrix[N1 -> D1] } else { error(...) } } else { Matrix[N1 -> D1, N2 -> D2] } } 14
  • 15. Extreme 2 Symbolic reasoning ( p.apply + =:= can only go in 1 direction) class Matrix[A, B](): def +(other: Matrix[A, B]): Matrix[A, B] def transpose: Matrix[B, A] def flatten: Matrix[A * B, 1] type A <: Int type B <: Int val m = new Matrix[A, B]() m.flatten + (m.transpose.flatten) // Oops 15
  • 16. Learn from forward mode lemma and_is_comm (p q: Prop) (h: p ∧ q): q ∧ p := and.intro (h.right) (h.left) tactic mode lemma and_is_comm' (p q: Prop) (h: p ∧ q): q ∧ p := begin apply and.intro, exact h.right, exact h.left, end (source: LEAN for Scala programmers - Part 4 - Juan Pablo Romero Méndez) 16
  • 17. Full auto mode lemma and_is_comm' (p q: Prop) (h: p ∧ q): q ∧ p := begin assumption, assumption, assumption, end =:= begin assumption | ? => q ∧ p | .intro: (q, p)? => q ∧ p assumption | p ∧ q => ? | .right: p ∧ q => p? assumption | p ∧ q => ? | .left: p ∧ q => q? end 17
  • 18. ... in Scala! (source: Oron Port's response to "Principles for Implicits in Scala 3" by Odersky) 18
  • 19. Curry-Howard isomorphism, rewritten proof system functional programming (full auto!) def p[AS <: A with Singleton]: AS |- P[AS] , def p[AS <: A with Singleton]: AS |- AS#P def p[BS <: B](implicit b: BS): BS |- BS#P Axiom def axiom[X]: X |- P[X]{.} Theorem def theorem[X](implicit lemma1: X => X#L1): X |- P[X]{.} 19
  • 21. Why Scala -- Specifically, why scala 2? 21
  • 22. Stack of AI-HPC-Hardware co-evolution / More Abstract Distributed Computing --- Apache {Spark | Flink} [ SOME Deep Learning Library? ] IR/Multi-stage Compilation --- reflection, LMS Hardware Design --- CHISEL / SpinalHDL / More Concrete 22
  • 23. But try to avoid ... Diverging implicit Circular reference def theorem[A](using a: A): A Expanding reference def theorem[A <: F[_], B](using a: F[A, B]): A Summoning proof on long algebraic data type SquashByName[ / ]#On[ SquashByName[ / ]#On[ SquashByName[ + ]#On[ SquashByName[ - ]#On[ SquashByName[ / ]#On[ SquashByName[ + ]#On[ SquashByName[ - ]#On[ SquashByName[ / ]#On[ SquashByName[ + ]#On[ SquashByName[ - ]#On[ 1024 >< 1024 |<<- (i >< j) >< (3 >< 3 |<<- (i >< j))... 23
  • 24. What's next? Gradually typed ( UncheckedShape ), but still no symbolic reasoning Fairly stable, but not released or in production Not a computing library! Cannot empower ML engineers directly, but serve as a bridge to get there Need Scala 3 support! 24
  • 25. Moving to Scala 3? Pros Implicit search tree traversal is aggressively cached No more unpredictable diverging implicit recovery Theoretically sound resolving of <:< and =:= Cons No type projection (may be added back) No shapeless Record type (may be integrated into Programmatic Structural Types) (can be expressed in match type in a very inefficient way) 25
  • 27. Proudly Supported By ™, the Data Privacy & Trust Company We are hiring! Looking for a director of engineering Splain Open-Source Team Looking for scala compiler guru / type theorist as technical advisor 1.0.0RC is close, looking for test users 27