r/learnquant • • 3d ago

interview prep Quant Interview Question

Post image
46 Upvotes

34 comments sorted by

2

u/Parallel_thougts 2d ago

This is equivalent to asking how many different unit vectors can you have such that the angle between any two vectors is the same.

Clearly N=d is possible, as any orthonormal base will show you.

But you can actually do one more by placing the origin in the center of an n-simplex (e.g. an equilateral triangle in the plane) and taking vectors pointing at it's vertices.

Symmetry shows all angles are the same, so we find N=d+1. The inner product in this case is always 1/n.

You can't do better: look at the gram matrix of N unit vectors. If all inner products are the same, this matrix has rank N-1, so N-1<=d

2

u/Square_Butterfly_390 1d ago

I'm guessing the solution is just the d-simplex, so N=d+1 and c is the cosine of the angle made by a simplex (which I would give a recursive formula for absent a better method). For a proof I would say something like: the scalar product of unit vectors is exactly the cosine of the angle between them, and is entirely determined by their distance from one another, therefore we are looking for N equidistant points, which are I think a definition for the N simplex (which luckily can be placed on our spheres).

1

u/FitCardiologist2341 3d ago

Consider the matrix X whose columns are the v_i. It is a d x N matrix.

We ask that the N x N Gram matrix G = t(X) * X have ones on its diagonal and c everywhere else.

But rk(G) <= d.

Assume N > d. So (c-1)/c has to be an eigenvalue of the matrix full of ones. The only nonzero eigenvalue is N, so c = -1/(N-1).

Check that N = d+1, and c = -1/d.

1

u/Western_Gear5643 1d ago

Lost you from when you said so (c-1)/c has to..

1

u/PassAppropriate5891 3d ago

I think you can do d + 1 using a simplex as the angles and hence dot products are all the same.

Orthogonal Basis yields d 

Unsure if sth better exists

1

u/round_earther_69 2d ago

Consider the matrix A = {v_1, v_2, ... ,v_N}.
rank(A)=rank(A^T A)≤d because v_i's are d-dimensional vectors and at most d of them are independent.
AA^T is a symmetric matrix, therefore it is diagonalizable by orthogonal transformations.
AA^T has 1s on its diagonal entries and cs on every other entry (A^TA is simply a matrix with every possible scalar product in its entries).
Its eigenvectors and eigenvalues are (1,-1, 0, 0, ...)^T with \lambda_1 = 1-c; (1, 0, -1, 0, ...)^T with \lambda_2 = 1-c; (1, 0, 0, -1, ...)^T with \lambda_3 = 1-c; ... and (1,1,1,1, ... , 1) with \lambda_N = (N-1)c + 1, therefore the rank of AA^T (=# of nonzero eigenvalues) is either 1 if c=1; N-1 if c=-1/(N-1) or N for any other c. c=1 is clearly impossible if the vectors are distinct.

Therefore, for c not equal to 1 or -1/(N-1): rank(AA^T )=N≤d, and N is at most d.
For c=-1/(N-1), rank(AA^T )=N-1≤d, and N is at most d+1.

The maximum value of N and its corresonding c are thus: N=d+1 and c=-1/d.

In 1D, this gives two opposite vectors, in 2D it gives vectors on the corners of a triangle and in 3D this gives the vectors on the corners of a tetrahedron.

1

u/External_Package2787 12h ago

take a single vector v1, and ask what the set of solutions to v1.v2=c looks like, for -sqrtd <c<sqrt d this is a d-1 dimensional sphere's surface, for each of c=+- sqrt d, we get a single point, and c greater has no solution. We will discard c=+- sqrt d, since that immediately grants a maximum N of 2 and we seek more. Now our problem is, what is the largest N-1 unit vectors that fit into a d-1 dimensional sphere which satisfy our condition(they automatically satisfy the condition with v1 since they live on the sphere defined by satisfying v1's condition), and this specific sphere can be seen through looking at the constraints that v2.v2=1 and v1.v2=c, treat v1 as a basis vector and split v2 into perp and parallel parts, and it becomes that v2_parallel=c and v2_parallel2+|v2_perp|2=1, i.e a sphere of radius 1-c2 cented at a distance c along direction v1. We can repeat this question over and over, what do the solutions of v2.v3 look like on this sphere, and the answer to our problem becomes one of deciding how the dimension space of our solution shrinks. We find the solution space must be a sphere(including a 1-sphere), since we may break up the conditions into parallel and perp parts, vk.vk=1 and vi.vk=c for i<k, where by parallel I mean in the span of {vi, i<k}, which gives us |v_perp|2=1-|v_para|2, (note that v_para is variable, but for the sake of this process, we are taking it to mean that all previous vectors are decided and hence v_para in the span of these previous vectors must also be decided) this is a sphere, further it is a sphere a dimension at least one less than the previous, and so almost immediately we have our conclusion, the space of non-zero solutions decreases by 1 each time, we can do this at most N times before terminating, and we can construct a solution with c=0, and an orthnormal set of N vectors, so the N vector bound is maximal and attainable. 

As for proving that c must be 0, I suspect we need to bound |v_para|2 somehow, in a subspace with basis vectors of {v_i}, all with mutual v_i.v_j=c and v_i.v_i=1, we can imagine writing v_para in those basis vectors, and i.e v_para= a1 v_1 + a2v_2,..., and then c=v_para.v_1= a1v_1.v_1+ a2v_2.v_1+... = a1+ c*(a2+...), hence c=a1/{1-a2-...}, but v1 wasn't a special choice, we can swap a1 with any of the ajs. We want to know |v_para|2, and this is a distributed product, which comes out to a12+a22+.... +2c*(a1a2+a1a3+...) i.e every aj multiplies by itself while every pair of distinct aj multiplies together twice with a coefficient for v_j.v_i=c. Ah I see the problem comes with the final k=n, go back to our equation c=a1+ c*(a2+...), along with all the permutations of the ajs, we can add up these all and get (n-1)c=(a1+...) +c*(n-2)(a1+...), so (a1+...)(1+c(n-2))=c*(n-1). and we can then subtract c=a1+c*(a2+...) multiplied by (1+c*(n-2))/c, giving a1(1-1/c)(1+c*(n-2))=c-1, or rather a1*(1+c*(n-2))=c and by permutation symmetry, all ajs satisfy this and are hence all equal, which means that |v_para|2= (n-1)*a12+c(n-1)(n-2)*a12 = a12(n-1)(1+c(n-2)) = (n-1)*c2/(1+c(n-2)) but with c non-zero. hmmmmmm nevermind I don't see it.

1

u/Cold-Knowledge-4295 3d ago

Since vi are unitary, viT vj = cos(xij) where xij is the angle between vi and vj, so the question is how many vectors can you fit so that they al hold the same angle amongst them.

That is N=3 vectors at 120° each in d=2, N=4 at 120° again in d=3 and in general d+1 vectors at 120° for each d (these are segments from the vertices tonthe barycentrr of an n-simplex).

Thus, c=cos120=-1/2?

1

u/Artistic-Flamingo-92 3d ago edited 3d ago

I don’t think unitary is typically used to refer to unit vectors. I guess you would use “unit-length” or something.

Edit: I think that angle calculation for d ≠ 2 is also wrong.

1

u/round_earther_69 2d ago

in d=3 it cannot be 120^o , the vectors need to be at the corners of a tetrahedron, that is not the correct solution

1

u/Cold-Knowledge-4295 2d ago

Right, 120° is wrong, just checked how to compute that angle properly.

Any idea how to show thath those vectors need to form a simplex?

0

u/Crafty-Sell7325 3d ago

Um isn't there no upper bound to N? 

Like you can just use the canonical orthonormal basis in Rn

You get ei = 1 at position i and 0 elsewhere.

eiTej= 0 due to being orthonormal for all i not equal to j

Then eiTei = 1 due to being orthonormal != 0.

So c= 0 ig? And N=Infinity?

2

u/spurious_elephant 3d ago

That solution gives you n = d, but how do you get n = infinity?

1

u/7o7n7c7h7i7 3d ago

You only have d unit vectors in the base of Rd

1

u/Crafty-Sell7325 3d ago

Ah I can't read, rip

1

u/Niilldar 3d ago

N =d  in this case... But is there another solution with c <> 0?

1

u/Crafty-Sell7325 3d ago

Misread, mb

0

u/Ancient_Eggplant_123 3d ago edited 2d ago

First, ||vj-vi|| = 2 - 2c so it is constant. For d = 2 there are no more than 3 points that satisfy this condition creating an equilateral triangle. Let's place the center points at (0,0). Going from 2d to 3d we take a point along the new axis + lower the triangle so that the previous condition is satisfied. So each time perhaps we take the unit vector that is parallel to the new axis (it can be shown that it satisfies the previous condition of distance between unit vectors) while lowering the construct we created in the previous vector space, and we get N=d+1 and c=0

3

u/Equal_Veterinarian22 3d ago

I like your approach, but it does not give c=0

1

u/Deto 2d ago

This is interesting. Like the other person said, you don't get c=0, but you do get a constant c (so it satisfies the problem statement). I had assumed the answer was N=d and c=0, but with this you get N=d+1 so this is probably the correct answer. The distance between points doesn't change as the dimensionality increases so c is constant?

Some quick triangle fiddling gives the distance between points to be sqrt(3). So if 2-2c = sqrt(3), we have c = 1-sqrt(3)/2

0

u/You-Educational 3d ago

Note that $v^T u$ is the dot product $v \cdot u$, which is symmetric.

We first construct an example where $N=d+1$ for any $d$, and then show that $N \leq d+1$. To construct the example, take an orthonormalisation basis $e_1, \ldots, e_{N+1}$ in $\mathbb R^{N+1}$. As an orthonormal basis, they satisfy $e_i \cdot e_i=1$ and $e_i \cdot e_j=0$. Moreover, if $v=\sum_{j=1}^N e_j$, then for each $j$, $v \cdot e_j = 1$. Therefore the projections of each $e_i$ onto the hyperplane orthogonal to $v$ have constant length $a$ and dot product $b$. If we scale them all by $a^{-1}$, then they will have constant dot product $a^{-2}b$. Thus we $N+1$ unit vectors with constant dot product in the hyperplane, which is isomorphic to $\mathbb R^d$.

Claim: $N \leq d+1$.

Proof by induction on $d$.

Base case $d=1$. There are only two unit vectors in $\mathbb R^1$, $(-1) and (1)$, so $N \leq 2$.
Induction step suppose the claim holds for some $d \geq 1$.

Let $v_1, \ldots v_{N}$ be a set of unit vectors in $\mathbb R^{d+1}$ with constant dot product $c$. Let $J \subset \{ 1, \ldots, N+1\}$ be a subset with $\lvert J \rvert=N$, and let $v_J = \sum_{j \in J} v_j$. Then for any $k \in J$, we have

$$ v_k \cdot v_J = v_k \cdot v_k + \sum_{j \in J\setminus \{ j \}} v_k \cdot v_j = 1 + (N-1)c.$$

Therefore the projections of each $v_k$, $k \in J$ onto the plane perpendicular to $v_J$ form a set of vectors with constant length and constant dot product. By scaling as before, we obtain a set of $N-1$ unit vectors in $\mathbb R^d$ with constant dot product. By the induction hypothesis, $N-1 < d+1$. Therefore $N < (d+1) + 1$. Therefore the claim holds for $d+1$.

0

u/apu727 2d ago

I would argue the question is ambiguous. What is distinct? And what is a unit vector. For example a valid reading is distinct means V_i=/=v_j and unit means unit length. if so 2 in 2D, infinite in 3D just take one of the vectors as an axis, another different vector makes an angle and gives c=cos(theta) then rotate about the first by any angle and you have infinite distinct vectors

2

u/AttorneyGlass531 1d ago

All the vecotrs have to mutually satisfy that their pairwise dot products are equal to the constant c, which your circle of vectors in 3D fail to do

1

u/DanielShaww 2d ago

Those are literally the least ambiguous parts of the question. Distinct vectors just means they all have different directions/slopes, that is, you can't transform one into another by multiplying by a constant k.

Unit vector means their magnitude (size if you will) is 1. So in 2D, a unit vector has size √(u2 + v2 ) = 1, where u is the length in one axis and v the length in another axis.

1

u/Torebbjorn 1d ago

You cannot take all of those vectors in 3d. Yes, the first vector satisfies the condition with every other vector, but picking any two from the others, we run into problems.

-1

u/brojablen 3d ago

N = 3 and c = sqrt(3)/2

1

u/Deto 3d ago

How did you get there?

1

u/brojablen 1d ago

no i am wrong realised right after i put the answer, ill put it now,

its like you can imagine viT.vj is just the dot product of 2 unit vectors which is simply cos(theta) with theta being the angle between them

For d = 2, for them to be distinct and their dot product property to hold its theta = 120 and N = 3

for d = 3, its gotta be the 4 points of a tetrahedron so N = 4 and theta = 109.something N =4

so extrapolating N = d+1 and c = -1/d

-1

u/Fearless_Screen_4288 3d ago

Nd coordinates. N2 distinct conditions. So N2 <= Nd i.e N<=d. 

1

u/round_earther_69 2d ago

The conditions do not give a linear system of equations, the #of conditions and #of variables does not necessarilly give you the # of solutions, and in the present case, it does not (N<=d is not the correct solution)

1

u/Fearless_Screen_4288 2d ago

You are right