# dimension of quotient space

I am applying the the following theorem on dimension of quotient spaces. Let $x \neq 0$ be an element of a vector space $V$ over a field $K.$ Then

$$dim(V) = dim(Span(x)) + dim(V/Span(x)).$$

How can I write a Sage code to compute $dim(V)$ by recursively using this formula where you choose a nonzero element x until $dim(V/Span(x))$ is 1?

dim(V) = dim(Span(x1)) + dim(V/Span(x1))

= dim(Span(x1)) + [ dim(Span(x2)) + dim((V/Span(x1))/Span(x2)) ]

= ...

= dim(Span(x1)) + dim(Span(x2)) + ... + dim(Span(xn))

= 1 + 1 + .... + n

= n


Thanks.

edit retag close merge delete

Homework? What have you tried so far?

( 2023-02-14 20:49:02 +0100 )edit

@John-Palmieri, i I found the solution. Thanks. Should I close it?

( 2023-02-14 21:29:34 +0100 )edit
1

You could post your solution, in case others are interested.

( 2023-02-14 22:21:53 +0100 )edit

Sort by ยป oldest newest most voted

Another option:

sage: V = QQ^10
sage: d = 0
sage: while dim(V) > 0:
....:     for x in V:   # iterate through all elements of V
....:         if x:     # until you find a nonzero element
....:             break
....:     d += 1
....:     V = V / V.span([x])
....:
sage: d
10

more

@John-Palmieri, typo: the output is 10.

( 2023-02-15 21:49:19 +0100 )edit
1

Right, I copy-pasted and then updated the example without updating the output.

( 2023-02-16 00:28:37 +0100 )edit

Here is an example code. It answers my own question.

Sage: V = VectorSpace(GF(2),100) # example vector space

Sage: def dim_(V):
if V.dimension() == 0:
return 0
else:
#choose a nonzero element whenever it exists, for e.g. first element after 0 vector
return span([V[1]]).dimension() + dim(V.quotient(span([V[1]])))#.dimension()
Sage: dim_(V)
Sage: 100

more