Basis

Definition with representing vectors

Akuli	ok :)
Akuli	let's say you have some subspace
Akuli	the idea is to choose a few special basis vectors so that you can represent any vector from the subspace with them
Akuli	for example, if your subspace is the set of all 2D vectors, you could pick (1,0) and (0,1), aka i and j
adder`	what was basis vector, something similar to unit vectors?
Akuli	a basis vector is just a vector in the basis, which is a set of vectors you make up other vectors if
Akuli	of
Akuli	i'll define it precisely in a moment
Akuli	but the idea is that these are the "building block" kind of vectors that everything is made up of
adder`	ok
adder`	is 2 of them enough?
adder`	then we get the rest with + and *
adder`	all directions
adder`	we need up (or down) and right (or left)
Akuli	for the set of all 2d vectors, yes two is enough
Akuli	for all 3d vectors you could take (1,0,0), (0,1,0), (0,0,1) for example
adder`	yeah we need something to 'push' each 'axis' (?)
adder`	dimension
Akuli	right, that's the idea
Akuli	now i think we're ready to define what exactly is a basis, so we have something more than just an idea to work with
Akuli	specifically, we'll define what "a basis of a subspace" means
Akuli	a subspace can have multiple basis
Akuli	...bases
Akuli	this word is difficult
Akuli	basis is singular, bases is plural
adder	yeah
Akuli	an example of an alternative (non-standard) basis for the set of 2d vectors would be (1,1) and (1,-1)
Akuli	it goes up-right and down-right, basically rotated 45deg
Akuli	but it works just as well as (1,0) and (0,1) would
Akuli	ok?
adder	ok
Akuli	so here's our definition for what a basis of a subspace means (note that we can do this on any subspace)
Akuli	finitely many vectors from the subspace so that any vector of the subspace can be written as a linear combination of basis vectors in exactly one way
Akuli	so if your basis vectors are b1,b2,b3, then for any vector v in the subspace you can write v = a*b1 + b*b2 + c*b3
Akuli	and this must be possible with only one choice of a,b,c
Akuli	so you can't have multiple ways to choose a,b,c to make that work
Akuli	ok?
adder	ok
Akuli	for the set of all n-dimensional vectors, the basis conisting of (1,0,0,...), (0,1,0,...) etc is called standard basis
Akuli	so for the set of all 2D vectors it would be (1,0), (0,1)
Akuli	but there can be other bases too
adder	so is 'basis' just a set?
Akuli	yeah, a set of vectors
Akuli	almost
Akuli	in many contexts, the order of the basis vectors matters
Akuli	because you need to say "this coefficient corresponds to this basis vector"
Akuli	and in a set you usually don't care about the order
adder	yeah
Akuli	but in practice it's perfectly fine to think of a basis as a finite set of vectors from the subspace
Akuli	just has to have the property that you can write any subspace vector with them in only one way
Akuli	ok?
adder	so does this open some doors?
adder	as in, can we do something new and cool with this
Akuli	yeah it does, we'll explore this a bit soon
Akuli	is the concept clear, and is it clear why the standard basis is in fact a basis?
adder	let me try to repeat
Akuli	:)
adder	a basis is a collection of vectors, with which you can write any vector in a subspace using a unique combination of coefficients
Akuli	awesome :)
Akuli	that's exactly what it is
Akuli	the subspace doesn't have to be the whole set of all 3D vectors, or all 2D vectors, or whatever
Akuli	for example, the line y=x is a subspace as we discussed last time
Akuli	you can view it as span((1,1)), for example
Akuli	the vector (1,1) forms a basis for it
Akuli	so in this case just one vector is enough to make up a basis 
Akuli	ok?
adder	ok

Definition with span and linear independence

Akuli	let's rethink the definition of a basis a bit
Akuli	"every vector can be written with basis vectors" just means:   subspace = span(basis vectors)
Akuli	span(basis vectors) = all vectors that can be written with them
adder	ok
Akuli	so if we ignore the requirement to have only one unique way to do it, a basis would be just anything whose span is the subspace
Akuli	ok?
adder	ok
Akuli	let's think about the uniqueness a bit
Akuli	say we have two basis vectors, b1 and b2
Akuli	and let's say v is any vector from the subspace
Akuli	then there's some a and b so that v = a*b1 + b*b2
Akuli	what uniqueness is that you can't have some other alternative values, say x and y, that would work instead of a and vb:   v = x*b1 + y*b2
Akuli	s/vb/b/
Akuli	ok?
adder	ok
Akuli	so in other words it means:  if a*b1 + b*b2 = x*b1 + y*b2  (two ways to write v)
Akuli	then a=x and b=y   (well actually no, there's only one way)
Akuli	ok?
adder	brb phone
adder	sorry, dad
Akuli	:)
adder	anyway, does this mean that:
adder	if it weren't for the uniqueness constraint, the span would break because there would be dependent vectors?
Akuli	yeah it has to do with dependent/independent
Akuli	in the past, we have seen that "independent" means "possible to count vectors on both sides"
Akuli	which is really just a way to say "guarantees uniqueness"
Akuli	ok?
adder	ok
Akuli	so actually
Akuli	vectors form a basis if subspace = span(vectors) and the vectors are linearly independent :)
Akuli	s/if/if and only if/
Akuli	"space = span(vectors)" means you can write anything with them

Examples

adder	can we see how an example real basis looks like
Akuli	"vectors are linearly independent" means there's only one way to do it
Akuli	yeah, let's do an example
Akuli	with (1,0),(0,1) basis it's pretty obvious how this goes
Akuli	those are independent and they span all 2D vectors
Akuli	so they're a basis and we can do say (4, 5) = 4*(1,0) + 5*(0,1) and that's the only way to do it
Akuli	ok?
adder	ok, one more q
adder	don't yell :)
Akuli	:)
adder	can you explain the subspace thing on this example?
Akuli	the subspace in this example is just the set of all 2D vectors
Akuli	let me edit the example a bit
Akuli	consider XY plane as a subspace of the set of all 3D vectors
Akuli	it has a basis (1,0,0),(0,1,0) and contains a vector (4,5,0)
Akuli	the unique way to write (4,5,0) with the basis vectors is 4*(1,0,0) + 5*(0,1,0)
Akuli	ok?
adder	ok
Akuli	it also has a basis (1,-1,0),(1,1,0)
Akuli	those are independent vectors and they span the whole xy plane
Akuli	ok?
adder	ok
Akuli	so there's some unique way to write (4,5,0) with them
Akuli	we don't know an easy way to calculate it, although the theory so far guarantees that it exists! :D
adder	ok
Akuli	this is something you will surely run into later, do theorethical stuff for a bit and you realize you have a pile of existence results with no good ways to calculate :)
Akuli	so we'll shift focus to calculating stuff in a moment
Akuli	but for now we can just calculate it by hand
Akuli	we want:   x*(1,-1,0) + y*(1,1,0) = (4,5,0)
Akuli	we know this equation has a unique pair of numbers x,y satisfying it and we're trying to find it
Akuli	ok?
adder	ok
*	adder Tourette-shouts 'counting vectors'
Akuli	(x, -x, 0) + (y, y, 0) = (4, 5, 0)
Akuli	(x+y, -x+y, 0) = (4, 5, 0)
Akuli	ok?
adder	a system
Akuli	yea :)
Akuli	x+y=4, -x+y=5 :)
Akuli	i'll let you solve it from here :)
adder	<=> y = 9/2
adder	x = 4 - 9/2 = -1/2
Akuli	seems about reasonable, let's try
Akuli	-1/2  (1,-1,0) + 9/2  (1,1,0)
Akuli	= (-1/2, 1/2, 0) + (9/2, 9/2, 0)
Akuli	= (-1/2 + 9/2, 1/2 + 9/2, 0)
Akuli	ok?
adder	ok
adder	= (4, 5, 0)
Akuli	:)

Finding the coefficients

Akuli	so this totally worked
Akuli	but it involved solving a system
Akuli	ideally we would have a better/quicker/cooler way to figure out the coefficients to represent a vector in a basis
adder	I suspect systems get more complex in real life?
Akuli	yeah
Akuli	depends on what you do though
Akuli	if you do some kind of statistics, you could easily have hundreds of equations or variables
Akuli	if you do 3d graphics, you'll probably never get more than 3 or 4 equations or variables at a time
Akuli	but either way this feels like we could improve the process of finding the coefficients
Akuli	ok?
adder	ok
Akuli	we don't really need a better way to check if something is a basis
Akuli	we already have ways to calculate spans and check (in)dependentness
Akuli	ok?
adder	ok
Akuli	so next step is how to find those coefficients, easily
Akuli	here's an idea
Akuli	matrix*vector = sum(column from matrix * number from vector)
Akuli	e.g. https://akuli.github.io/mathpaste/#saved:-NA5mHWpqViWmlU9l2Xm:9569e9477e69495b23f8974f4e380e4f
Akuli	ok?
adder	ok
Akuli	doesn't this look pretty similar to what we just did?
Akuli	so [(1),(3)] and [(2),(4)] correspond to basis vectors here, and the [(x),(y)] is what we try to find
adder	o yeah indeed
Akuli	apparently we would need to make a matrix consisting of all our basis vectors as columns
Akuli	so with that matrix, the system we're solving is TheBasisMatrix*(x,y) = vector
Akuli	where the vector on the right side is what we're trying to represent as a combination of the basis vectors
Akuli	and (x,y) are the yet-unknown coefficients
Akuli	ok?
adder	right side?
Akuli	TheBasisMatrix*(x,y) = vector_we_are_trying_represent
adder	ah
Akuli	ok so far?
adder	yeah one thing 
adder	when we solve this, we get what? what is this vector?
adder	what are we doing?
Akuli	the solution (x,y) are the coefficients to write the vector in the basis
Akuli	maybe i should motivate a bit why you might be interested in doing this anyway
adder	so we're finding the basis?
adder	and apply this technique for each vector in it
Akuli	we have chosen a basis, and we're trying to "convert" the vector to be represented with that basis
Akuli	let's say you're working on a game or other physics thing where
Akuli	usually you have "world coordinates"
Akuli	like x,y,z axises that align with the map or whatever
Akuli	and then the map contains various moving/spinning objects
Akuli	ok?
adder	ok
Akuli	for physics, you typically want to switch to a basis where one vector is forward, another is left, a third one is up
Akuli	or some other thing like that where the basis makes sense from the moving object's point of view
Akuli	you want your basis vectors to make sense, basically
Akuli	and not be just some world coordinates that are irrelevant if you only care about that one object
Akuli	ok?
adder	ok
Akuli	figuring out the basis vectors is the easy part
Akuli	if you know what direction it looks etc, you can quite easily calculate vectors for "front", "left" and "up" for example
Akuli	ok?
adder	ok
Akuli	converting world coordinates to those vectors is trickier
Akuli	we want:   some_world_coords = a*front + b*left + c*up
Akuli	meaning:   FrontLeftUpMatrix*(a,b,c) = some_world_coords
Akuli	ok?
adder	ok
Akuli	so at this point you could invert the matrix
Akuli	matrix*(a,b,c) = vector
Akuli	inversematrix*matrix*(a,b,c) = inversematrix*vector
Akuli	(a,b,c) = inversematrix*vector
Akuli	so as it turns out, it's just one matrix inversion and a matrix-vector multiplication to find those coeffs
Akuli	ok?
adder	rofl
adder	how on earth can you know this come on
Akuli	:D
Akuli	i have used this quite a few times when making my game :)
Akuli	the best part is, calculating the inverse matrix is the slowest part and you only need to do it once every time the object rotates
Akuli	once you have computed that, you can transform as many vectors as you want from world coordinates to the object's coordinates using that inverse matrix
Akuli	my game caches these inverse matrices, and i have a function i have to remember to call to update them whenever i have rotated things
Akuli	ok?
adder	yeah
Akuli	i think that's about it for today :)
Akuli	so we started pretty theorethical, and ended up with something very practical
Akuli	there's still more to be covered from this, we have basically only "touched the surface" of using matrices to do basis vectors things
Akuli	but the main takeaway is that to compute basis vectors coefficients, make a matrix of basis vectors and invert it
Akuli	ok?
adder	yeah
Akuli	if you remember that, i think you automatically remember the highlights of the theory that led up to this point :) including some idea of what is a basis
adder	ok :D