All problems
Cauchy-Schwarz Gap
Problem
Return the non-negative gap in the Cauchy-Schwarz inequality:
gap = ||a||_2 * ||b||_2 - |a . b|
A gap of 0 means the vectors are linearly dependent (parallel).
Hint
The gap is zero exactly when one vector is a scalar multiple of the other.
Test cases
case 1
in: [[3,4],[6,8]]
expected: 0
case 2
in: [[1,0],[0,1]]
expected: 1
case 3
in: [[1,2],[2,1]]
expected: 1
case 4
in: [[0,0],[1,2]]
expected: 0
Starter codePython
def cauchy_schwarz_gap(a, b):
# Your code here
pass4 test cases · run your code against them in the editor