What floating-point pitfalls arise in linear algebra computations, and how do you guard against them?

Quick Overview

Asks which floating-point problems appear in linear algebra code and how to prevent them. Tests whether you understand condition numbers, numerically stable ways to solve systems and least squares, and safe ways to compare computed values.

What floating-point pitfalls arise in linear algebra computations, and how do you guard against them?

Role: Data Scientist

Category: Statistics & Math

Difficulty: medium

Interview Round: Other

What floating-point pitfalls arise in linear algebra computations, and how do you guard against them? Think about the everyday work: solving linear systems, fitting least squares, checking rank or singularity, and computing norms. ```hint Start from error growth Ask how much a small relative error in the input, or in an intermediate result, can grow by the time it reaches the answer, and which choices of algorithm make that growth worse. ``` ```hint Look at comparisons and intermediate values Consider what happens when code compares a computed quantity with exactly zero, and when an intermediate value such as a sum of squares leaves the range a float can represent. ``` ### What a Strong Answer Covers - Catastrophic cancellation, with a concrete case and a reformulation that avoids it - How the condition number bounds error amplification, and why forming $A^\top A$ makes it worse - Algorithmic guards such as pivoting, orthogonal factorizations, regularization and preconditioning - Tolerance-based tests for rank, singularity and equality in place of exact comparisons - Overflow and underflow in intermediate values, plus the habit of using library routines and solving systems without forming an inverse ### Follow-up Questions - Why does solving least squares through the normal equations square the condition number, and when is that still acceptable? - How would you choose the tolerance for a numerical rank decision from the SVD? - Why is `np.linalg.solve(A, b)` preferred over `np.linalg.inv(A) @ b`, even when the matrix is well conditioned? - Which of these pitfalls get worse when a model is trained or served in float16?

Overview: Asks which floating-point problems appear in linear algebra code and how to prevent them. Tests whether you understand condition numbers, numerically stable ways to solve systems and least squares, and safe ways to compare computed values.

Nov 24, 2026
mediumData ScientistOtherStatistics & Math
0
0

What floating-point pitfalls arise in linear algebra computations, and how do you guard against them?

Think about the everyday work: solving linear systems, fitting least squares, checking rank or singularity, and computing norms.

What a Strong Answer Covers Guidance

  • Catastrophic cancellation, with a concrete case and a reformulation that avoids it
  • How the condition number bounds error amplification, and why forming A⊤AA^\top A makes it worse
  • Algorithmic guards such as pivoting, orthogonal factorizations, regularization and preconditioning
  • Tolerance-based tests for rank, singularity and equality in place of exact comparisons
  • Overflow and underflow in intermediate values, plus the habit of using library routines and solving systems without forming an inverse

Follow-up Questions Guidance

  • Why does solving least squares through the normal equations square the condition number, and when is that still acceptable?
  • How would you choose the tolerance for a numerical rank decision from the SVD?
  • Why is np.linalg.solve(A, b) preferred over np.linalg.inv(A) @ b , even when the matrix is well conditioned?
  • Which of these pitfalls get worse when a model is trained or served in float16?