Skip to content

FiniteDimVectorSpace forces every type of vectors to have the same rank #84

@dingxiangfei2009

Description

@dingxiangfei2009

Recall this definition:

pub trait FiniteDimVectorSpace: VectorSpace + Index<usize, Output = Self::Field> + IndexMut<usize, Output = Self::Field> {
    fn dimension() -> usize;
    fn canonical_basis_element(i: usize) -> Self;
    fn dot(&self, other: &Self) -> Self::Field;
    unsafe fn component_unchecked(&self, i: usize) -> &Self::Field;
    unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut Self::Field;

    fn canonical_basis<F: FnMut(&Self) -> bool>(f: F) { ... }
}

Note that FiniteDimVectorSpace::dimension is independent of &self. This forces all implementors of this trait to return constant value. Therefore, Vec<T> where T: Field is not a vector over the field T.

This is an awkward definition. It might make some sense for vector space of a certain dimension known at compile time, such as Vec2 and Vec3 in the examples. However, it prohibits implementations in general.

The dimension associated method in the definition of SquareMatrix makes much less sense in this context. Recall its definition:

pub trait SquareMatrix: Matrix<Row = Self::Vector, Column = Self::Vector, Transpose = Self> + MultiplicativeMonoid {
type Vector: FiniteDimVectorSpace<Field = Self::Field>;
    fn diagonal(&self) -> Self::Vector;
    fn determinant(&self) -> Self::Field;
    fn try_inverse(&self) -> Option<Self>;

    fn dimension(&self) -> usize { ... }
    fn transpose_mut(&mut self) { ... }
}

The dimension associated method in this case takes &self, but it is in fact independent of &self once Self::Vector has constant rank at compile time.

The proposed change is to allow FiniteDimVectorSpace::dimension to accept &self.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions