Skip to content

Instantly share code, notes, and snippets.

@hvesalai
Last active March 11, 2018 09:16
Show Gist options
  • Save hvesalai/650a0f1668db955df8fcb0567fa81c4d to your computer and use it in GitHub Desktop.
Save hvesalai/650a0f1668db955df8fcb0567fa81c4d to your computer and use it in GitHub Desktop.
trait VectorSpace[A] { } // isomorphisms
trait Iso[A, B] {
def to(a: A): B
def from(b: B): A
}
trait TensorAlgebra {
type * [V]
type ⨂ [V, W]
type ⨁ [V, W]
type Z
type I
implicit def dual[V](implicit V: VectorSpace[V]): VectorSpace[*[V]]
implicit def sum[V, W](implicit V: VectorSpace[V], W: VectorSpace[W]): VectorSpace[V ⨁ W]
implicit def product[V, W](implicit V: VectorSpace[V], W: VectorSpace[W]): VectorSpace[V ⨂ W]
// add implicit VectorSpace's everywhere
def zero[V]: Iso[V, V ⨁ Z]
def unit[V]: Iso[V, V ⨂ I]
def commuteSum[V, W]: Iso[V ⨁ W, W ⨁ V]
def commuteProd[V, W]: Iso[V ⨂ W, W ⨂ V]
def directSum[V, W](v: V, w: W): V ⨁ W
def inner[V, U, W](v: V ⨂ *[U], w: U ⨂ W): V ⨂ W
def outerProduct[V, W](v: V, w: W): V ⨂ W
def differentiate[V, W](f: V => W): W ⨂ *[V]
}
trait Module {
val T: TensorAlgebra
import T._
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment