Skip to content

What nat-dependent Vector & Matrix operations should be implemented? #201

Closed

Description

@cannorin

Related: #178, #192

I'm currently trying to add type-safe vector & matrix types to F#+ but I'm not sure what to implement.

Here are the ones I can think of:

  • Basic collection operations (such as map and filter) in a type-safe manner (e.g. item indexed with type-level natural).
  • Addition and subtraction
  • Scalar multiplication
  • dot product and 3D cross product for vectors
  • matrix product for matrices
  • constants such as zero, one, unit vectors, identity matrix

but I can imagine many other necessary operations are missing.

Can anyone provide me a list of other operations which can take advantage of type-level naturals and/or should be implemented?

Activity

  1. gusty commented on Sep 25, 2019

    @gusty
    Member

    It might be possible to make them applicatives but we'll need a way to express an infinite vector for the pure operation.

  2. n1lr4d1c4l commented on Sep 26, 2019

    @n1lr4d1c4l

    @cannorin, in addition to what you mentioned, I think these operations could be valuable:

    Transpose: Mat<n,m> -> Mat<m,n>
    Tensor (Kronecker) product: Mat<n1,m1> -> Mat<n2,m2> -> Mat<n1 * n2, m1 * m2>
    Direct sum:   Mat<n1,m1> -> Mat<n2,m2> -> Mat<n1 + n2, m1 + m2>
    Vertical block sum: Mat<n1,m> -> Mat<n2,m> -> Mat<n1 + n2, m>
    Horizontal block sum: Mat<n,m1> -> Mat<n,m2> -> Mat<n, m1 + m2>
    Hadamard (element-wise) product: Mat<n,m> -> Mat<n,m> -> Mat<n, m>
    

    I prefer to think of vectors as either (n,1) matrices or (1,n) matrices (covectors); this simplifies things as the vector operations are then special cases of the matrix ones. I think MATLAB adopts this philosophy but I’m not certain.

  3. cannorin commented on Oct 14, 2019

    @cannorin
    MemberAuthor

    @nasosev After some experiments, I decided not to merge matrix and vector into one type: the conversion between 1D array and 2D array is expensive and the implementation of pretty printer and other type classes becomes much complicated (e.g. vectors are foldable but matrices are not).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions