Reuse dimensions and either transpose definition above:
multMat :: Num a => Matrix a -> Matrix a -> Matrix a
multMat a b
  | colsA /= rowsB = error "multMat: incompatible sizes"
  | otherwise = [[sum (zipWith (*) row col) | col <- columnsB]
                                           | row <- a]
  where
    (_,colsA) = dimensions a
    (rowsB,_) = dimensions b
    columnsB = transpose b
For of size and of size , every selected row and column has length . Their dot product is
The two list comprehensions place this entry in row , column of an result. The dimension guard checks exactly the compatibility condition for matrix multiplication. The shared columnsB avoids recomputing the transpose for each row; the arithmetic cost is in the unit-cost model.
For nonzero , let be its angle to the unit vector . The scalar projection on the oriented axis is . Since , the dot product identity gives . Multiplying that signed scalar by places the foot at .
The residual is perpendicular to the axis, because . An obtuse angle gives a negative scalar and a foot on the negative side of the line; has projection zero without needing an angle.
Figure 1.
Projection drops a perpendicular to a unit direction; directional stretching doubles only the parallel component
. Details.
The first panel is a constructed geometric illustration. The second illustrates the directional stretch used later in Question 6.
Use sparse dot product by merging indices: only equal coordinate indices can contribute, so merge the two increasing index streams:
def dotProduct(vec1: Node, vec2: Node): Double = {
  require(vec1 != null && vec2 != null)
  require(vec1.index == vec2.index, "dimension mismatch")
  var p = vec1.next
  var q = vec2.next
  var answer = 0.0
  while ((p ne vec1) && (q ne vec2)) {
    if (p.index < q.index) p = p.next
    else if (q.index < p.index) q = q.next
    else {
      answer += p.value * q.value
      p = p.next
      q = q.next
    }
  }
  answer
}
The loop invariant states that the accumulator contains all common-coordinate products already passed, while no unprocessed smaller coordinate can acquire a future partner. If one current index is smaller, the other list has no remaining entry at that index, so its product is zero. Equal indices add their product and advance both. Once either list ends, all remaining coordinates of the other have zero partners.
Thus the code computes the dot product in coordinate order, subject to floating-point rounding, using time and constant auxiliary storage. It does not scan implicit zeros or alter either vector, and it also handles both arguments referring to the same header.
If , then the dot product satisfies
Conversely, the assumed dot product identity gives for every . Take and from the standard basis: every entry of is zero. Hence , proving the equivalence.
Perpendicular lines 2026-10-20
Two intersecting straight lines are perpendicular if their angle is . Their direction vectors have zero dot product.
For an integrable finite-dimensional random vector , let . The displayed convex cone is open relative to . Given a bounded strictly positive , the perturbation , , changes its weighted expectation by , where
For , : otherwise almost surely. Thus is invertible on , and these perturbations give a neighborhood of every point of the cone. The hyperplane separation theorem consequently gives the alternative: either zero is a strictly positively weighted expectation, or a nonzero direction in has a nonnegative dot product with almost surely and a positive dot product with positive probability. To obtain the latter assertion, test the separating direction with and let .
Power method Created 2026-09-24 Updated 2026-10-14
Iterate . For a self-adjoint operator with a unique dominant eigenvalue separated in modulus from the others, a starting vector that is nonorthogonal to its dominant eigenvector gives convergence of the eigendirection at the spectral-ratio rate. For a general diagonalizable matrix, the condition is a nonzero coefficient in the dominant component of its eigenbasis, detected by the corresponding left eigenvector; an ordinary dot product with the right eigenvector does not generally detect that coefficient.
The power method is power iteration; its convergence depends on the dominant spectral component of the starting vector.
For example, has dominant right eigenvector and a dominant left eigenvector . The starting vector has nonzero dot product with the right eigenvector, but : it stays forever in the eigenspace for the smaller eigenvalue . Its coefficient along the dominant direction is zero, as the left eigenvector detects. An orthonormal eigenbasis makes the two tests agree in the self-adjoint case.
Poynting theorem Created 2026-09-24 Updated 2026-10-20
The Poynting theorem is the local energy balance of classical electromagnetism. For vacuum field laws, with current density , the electromagnetic energy per unit volume is
and
Thus a decrease in local electromagnetic energy can supply outward energy flux or work on electric charge. The term is power transferred to matter per unit volume. Its sign matters: positive values remove field energy, while negative values describe matter supplying the field. The magnetic part of the Lorentz force supplies no work term.
For a fixed volume , the divergence theorem gives the directly measurable balance
For example, entering a region with leaving and transferred to matter means stored electromagnetic energy increases at . In source-free vacuum only the boundary flux changes the stored energy; a nonzero local Poynting vector can still have zero net closed-surface flux.
A brief proof takes the dot product of the Ampère-Maxwell equation with and uses Faraday's law with . The identity turns the remaining terms into the divergence of the Poynting vector. [ref].
Projected area 2026-10-14
The projected area of a planar patch viewed from a direction is the area of its perpendicular shadow onto a plane normal to that direction. If and are its unit normal and viewing unit vector, then by the dot product. On the outward side, this is . For a rectangle tilted around one edge, the width perpendicular to that edge contracts by and the edge length stays fixed, proving the formula. At grazing view ; interpret the radiance definition by a limit rather than dividing by zero.
In the real projective plane, represent a projective point by a nonzero vector and a projective line by its nonzero coefficient covector, identified with a vector in chosen coordinates. The join of distinct projective points represented by has coefficient vector , using the cross product. It is nonzero because the representatives are linearly independent, and its dot product with each representative vanishes. Dually, two distinct projective lines with coefficients meet in the projective point represented by . Scaling an input scales the output and leaves the projective object unchanged. This makes joins, intersections, concurrency, and collinearity exact calculations with homogeneous coordinates.
Let be the tangential surface gradient on a sphere of radius . For smooth scalar fields, set . Its radial curl detects only :
To prove this, use the radial curl formula . The radial component never enters it. The terms cancel as by symmetry of second derivatives, while the terms give the unit-sphere Laplace-Beltrami operator. Taking the dot product with the position vector gives the displayed version. This tangential gradient decomposition does not assert that the whole vector field is solenoidal.
In geometrical optics, suppose radiation has a nonnegative radiance whose directional contributions add as power. Here is the actual propagation unit vector, is a solid angle element, and the collecting oriented surface has chosen unit normal . Assume the following integrals exist. The outward and inward radiant fluxes are
Both quantities are nonnegative; their difference is the signed net radiant flux. The dot product supplies the cosine of the angle with the unit normal, hence the projected area. For incoming radiation the outward unit normal gives a negative dot product; the minus sign makes the collected power positive. Measuring the incoming angle from a source-facing unit normal instead gives the familiar positive . The units check is .
Equivalently, the incoming surface integral is with local irradiance ; the emitted part of is with radiant exitance . For a small flat patch and a narrow accepted cone, nearly constant radiance and angle give . This approximation requires uniformity across the patch and cone. Direction-independent outgoing radiance over a whole hemisphere gives the different exact result , by Lambert's cosine law and the spherical coordinates calculation in radiant exitance. Replacing the cosine-weighted integral by the hemisphere's solid angle would double the answer.[ref]
These radiance formulas presume a description in additive directional power; they do not reconstruct arbitrary coherent wave interference from separate ray contributions. For general electromagnetic fields, the signed instantaneous power crossing an oriented surface is , using the Poynting vector ; optical measurements commonly average over many wave periods. A zero net radiant flux can conceal equal nonzero incoming and outgoing radiant fluxes.
Rank-nullity theorem Created 2026-09-24 Updated 2026-10-14
The rank-nullity theorem accounts for the input dimensions of a linear map: the number of independent invisible input directions plus the number of independent reachable output directions equals the input dimension. For over a field, with finite-dimensional domain of a function ,
Here is the nullity, and is the rank of a linear map. The kernel lives in the input vector space, while the image of a linear map lives in the output vector space. For an -by- matrix of matrix rank , the formula is : the number of columns counts input coordinates. [ref]
For a computed example over the real numbers, take
The kernel is and the image of a linear map is . Each has dimension one, so the two input dimensions split as . The vector can be written
The second summand is undetectable: . The picture uses the standard dot product to choose a visible direction perpendicular to the kernel; this is a convenient geometric choice, not an extra hypothesis of the rank-nullity theorem.
Figure 1.
Two input dimensions split into one visible direction and one kernel direction
. For , the input splits into and . Both and map to , while the kernel component maps to zero. The horizontal output line is the entire image of a linear map. Details.
This explains a practical tradeoff in a linear system. If , every other input with output is for . The nullity therefore counts independent freedom in an existing solution; the rank counts independent reachable output directions. In the example, has all solutions , while has none. The cokernel records this failure of reachability.
For an -by- matrix, injectivity requires matrix rank , and surjectivity requires matrix rank . When , these conditions differ. For example, with has rank one and nullity two, because . The input accounting is , although only one of two output directions is reached.
Proof outline: extend a basis of the kernel to a basis of . Every output is a linear combination of because the vanish under . If a linear combination of the is zero, the corresponding combination of the lies in the kernel; linear independence of the full basis forces all its coefficients to vanish. Thus the added basis vectors give a basis of the image of a linear map. Counting them proves the formula.
Rank-one matrix update 2026-10-14
A rank-one matrix update changes a matrix by an outer product . For real vectors , its action on an input vector is
The dot product reads one scalar from the input, and the correction moves the output along . All correction outputs therefore lie in one linear span. If either vector is zero, the update is zero; otherwise the correction is a rank-one matrix. The full updated matrix need not have rank one.
For example, choose
The update sends to the correction . Although all four entries change, there is only one direction of correction. Adding it to the identity matrix gives .
This special structure allows existing work to be reused. The matrix determinant lemma updates the determinant using one scalar, and the Sherman–Morrison formula updates the matrix inverse using an outer product. Such formulas are useful when a linear system changes slightly after a new observation or a parameter adjustment: the unchanged part can retain its LU decomposition. The term rank-one describes the rank of the correction, not the size of the entry changes. [ref].
In a real finite-dimensional inner product space, let two bases satisfy . Taking inner products with in gives . If also , then . Thus the Gram matrix converts the original coordinates into reciprocal basis coordinates, and converts back. With Euclidean Cartesian column basis matrices , reciprocity is , hence and . This is why dot products with nonorthogonal basis vectors are coordinates in the reciprocal basis, rather than coordinates in the original basis.
Recommender system 2026-11-05
A recommender system selects or ranks items for a particular user or context, such as choosing books from a large catalogue. Its prediction target may be a rating, a click or a purchase; these targets need not coincide with what a user ultimately values. A common architecture first retrieves a manageable candidate set, then scores and reranks it.
Content-based filtering uses similarities between items; collaborative filtering uses patterns of interactions between users and items. If two readers overlap strongly in their previous choices, a book enjoyed by one can become a candidate for the other even without matching its description. Learned vectors make this retrieval a nearest neighbor search or related similarity search. A dot product also depends on vector length, so normalizing the vectors can change rankings.[ref]
Let be a nondegenerate bilinear form on a finite-dimensional vector space . Every bilinear form on has a unique representation
by a linear map . Thus a fixed nonsingular pairing converts another two-input form into a one-input linear operator.
For each , the rule is a linear functional. Nondegeneracy of identifies every such linear functional with for a unique ; define . Bilinearity of makes linear, and uniqueness follows from the same nondegeneracy.
If and are the bilinear form matrices of and in one basis, then
For the standard dot product on and , the representing matrix is . Finally, the right radical of is exactly : annihilating every first input is equivalent to .
This surface consists of rays from a vertex whose directions make a fixed angle with a unit axis vector . The displayed equation follows from the dot product formula for that angle. For , , it gives one circular nappe; gives a plane, and gives a degenerate ray. Squaring the equation produces both nappes, so the unsquared sign distinguishes them. Generalized angular momentum in a radial monopole field confines particle directions to such a surface.
Choose , and the positive angular frequency . Then the phase velocity is and the group velocity is . Their dot product vanishes and their sum is horizontal with magnitude . Draw the group velocity from the tip of the phase velocity: the two form the perpendicular sides of a right triangle. The horizontal hypotenuse is their sum, not the horizontal phase velocity .