Exercises Notebook
Converted from
exercises.ipynbfor web reading.
Normed Spaces - Exercises
8 exercises covering norm axioms, non-norm counterexamples, unit balls, norm equivalence, completeness, operator norms, dual norms, and contraction mappings.
| Format | Description |
|---|---|
| Problem | Markdown cell with task description |
| Your Solution | Runnable scaffold with placeholders |
| Solution | Reference implementation with checks |
Difficulty Levels
| Level | Exercises | Focus |
|---|---|---|
| Easy | 1-3 | Core definitions and geometry |
| Medium | 4-6 | Convergence and operators |
| Hard | 7-8 | Duality and fixed points |
Code cell 2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
try:
import seaborn as sns
sns.set_theme(style="whitegrid", palette="colorblind")
HAS_SNS = True
except ImportError:
plt.style.use("seaborn-v0_8-whitegrid")
HAS_SNS = False
mpl.rcParams.update({
"figure.figsize": (10, 6),
"figure.dpi": 120,
"font.size": 13,
"axes.titlesize": 15,
"axes.labelsize": 13,
"xtick.labelsize": 11,
"ytick.labelsize": 11,
"legend.fontsize": 11,
"legend.framealpha": 0.85,
"lines.linewidth": 2.0,
"axes.spines.top": False,
"axes.spines.right": False,
"savefig.bbox": "tight",
"savefig.dpi": 150,
})
np.random.seed(42)
print("Plot setup complete.")
Code cell 3
import numpy as np
import numpy.linalg as la
try:
import matplotlib.pyplot as plt
HAS_MPL = True
except ImportError:
HAS_MPL = False
np.set_printoptions(precision=6, suppress=True)
np.random.seed(42)
def p_norm(x, p):
x = np.asarray(x, dtype=float)
if p == np.inf:
return float(np.max(np.abs(x)))
return float(np.sum(np.abs(x) ** p) ** (1 / p))
def header(title):
print("\n" + "=" * len(title))
print(title)
print("=" * len(title))
def check_close(name, got, expected, tol=1e-8):
ok = np.allclose(got, expected, atol=tol, rtol=tol)
print(f"{'PASS' if ok else 'FAIL'} - {name}")
if not ok:
print(" expected:", expected)
print(" got :", got)
return ok
def check_true(name, cond):
print(f"{'PASS' if cond else 'FAIL'} - {name}")
return cond
print("Exercise setup complete.")
Exercise 1 (Easy) - Verify Norm Axioms
Check positivity, homogeneity, and triangle inequality for common norms.
Code cell 5
# Your Solution - Exercise 1: Verify Norm Axioms
answer = None
print("answer:", answer)
Code cell 6
# Solution
header("Exercise 1: Verify Norm Axioms")
x = np.array([1.0, -2.0, 3.0])
y = np.array([-1.0, 4.0, 0.5])
alpha = -3.0
for p in [1, 2, np.inf]:
positivity = p_norm(x, p) >= 0 and p_norm(np.zeros_like(x), p) == 0
homogeneity = np.isclose(p_norm(alpha*x, p), abs(alpha)*p_norm(x, p))
triangle = p_norm(x+y, p) <= p_norm(x, p) + p_norm(y, p) + 1e-10
print(f"p={p}: positivity={positivity}, homogeneity={homogeneity}, triangle={triangle}")
check_true(f"axioms hold for p={p}", positivity and homogeneity and triangle)
print("\nTakeaway: the standard p-norms with p >= 1 satisfy the norm axioms.")
Exercise 2 (Easy) - Find Non-Norm Counterexamples
Show why and quasi-norms fail.
Code cell 8
# Your Solution - Exercise 2: Find Non-Norm Counterexamples
answer = None
print("answer:", answer)
Code cell 9
# Solution
header("Exercise 2: Non-Norm Counterexamples")
x = np.array([1.0, 0.0])
alpha = 2.0
l0_fails = np.count_nonzero(alpha*x) != abs(alpha)*np.count_nonzero(x)
u = np.array([1.0, 0.0])
v = np.array([0.0, 1.0])
p = 0.5
triangle_fails = p_norm(u+v, p) > p_norm(u, p) + p_norm(v, p)
print("l0 homogeneity fails:", l0_fails)
print("p<1 triangle fails:", triangle_fails)
check_true("l0 is not homogeneous", l0_fails)
check_true("p<1 violates triangle", triangle_fails)
print("\nTakeaway: useful sparsity penalties are not automatically valid norms.")
Exercise 3 (Easy) - Unit Ball Geometry
Interpret , , and unit balls.
Code cell 11
# Your Solution - Exercise 3: Unit Ball Geometry
answer = None
print("answer:", answer)
Code cell 12
# Solution
header("Exercise 3: Unit Ball Geometry")
theta = np.linspace(0, 2*np.pi, 200)
circle = np.c_[np.cos(theta), np.sin(theta)]
l1 = circle / (np.abs(circle[:, :1]) + np.abs(circle[:, 1:2]))
linf = circle / np.max(np.abs(circle), axis=1, keepdims=True)
print("l1 corner example:", np.array([1.0, 0.0]))
print("linf corner example:", np.array([1.0, 1.0]))
check_close("l1 corner norm", p_norm([1, 0], 1), 1.0)
check_close("linf corner norm", p_norm([1, 1], np.inf), 1.0)
print("\nTakeaway: unit-ball shape explains sparsity, energy, and worst-coordinate perturbation models.")
Exercise 4 (Medium) - Norm Equivalence Constants
Verify finite-dimensional norm inequalities.
Code cell 14
# Your Solution - Exercise 4: Norm Equivalence Constants
answer = None
print("answer:", answer)
Code cell 15
# Solution
header("Exercise 4: Norm Equivalence Constants")
x = np.array([1.0, -2.0, 2.0, -1.0])
n = len(x)
check_true("linf <= l2", p_norm(x, np.inf) <= p_norm(x, 2))
check_true("l2 <= l1", p_norm(x, 2) <= p_norm(x, 1))
check_true("l1 <= sqrt(n) l2", p_norm(x, 1) <= np.sqrt(n)*p_norm(x, 2) + 1e-10)
check_true("l2 <= sqrt(n) linf", p_norm(x, 2) <= np.sqrt(n)*p_norm(x, np.inf) + 1e-10)
print("\nTakeaway: finite-dimensional norms define the same convergence, but constants depend on dimension.")
Exercise 5 (Medium) - Cauchy and Completeness
Study rational approximations to an irrational limit.
Code cell 17
# Your Solution - Exercise 5: Cauchy and Completeness
answer = None
print("answer:", answer)
Code cell 18
# Solution
header("Exercise 5: Cauchy and Completeness")
terms = np.array([round(np.sqrt(2), k) for k in range(1, 8)])
tail_gap = np.max(np.abs(terms[-3:, None] - terms[-3:]))
print("rational decimal approximations:", terms)
print("tail gap:", tail_gap)
check_true("decimal approximations become Cauchy-like", tail_gap < 1e-5)
check_true("limit is not rational in Q", not float(np.sqrt(2)).is_integer())
print("\nTakeaway: a Cauchy sequence can point to a limit outside an incomplete space.")
Exercise 6 (Medium) - Operator Norm
Compute and sample-check a matrix spectral norm.
Code cell 20
# Your Solution - Exercise 6: Operator Norm
answer = None
print("answer:", answer)
Code cell 21
# Solution
header("Exercise 6: Operator Norm")
A = np.array([[3.0, 1.0], [0.0, 2.0]])
spec = la.svd(A, compute_uv=False)[0]
samples = np.random.normal(size=(2000, 2))
ratios = np.array([la.norm(A@x)/la.norm(x) for x in samples if la.norm(x) > 0])
print("spectral norm:", spec)
print("sample max ratio:", ratios.max())
check_true("sample ratios bounded by spectral norm", ratios.max() <= spec + 1e-8)
print("\nTakeaway: the spectral norm is the largest stretch of a matrix under Euclidean norm.")
Exercise 7 (Hard) - Dual Norms and Holder
Verify dual norm inequalities numerically.
Code cell 23
# Your Solution - Exercise 7: Dual Norms and Holder
answer = None
print("answer:", answer)
Code cell 24
# Solution
header("Exercise 7: Dual Norms and Holder")
x = np.array([1.0, -2.0, 0.5])
y = np.array([3.0, 1.0, -4.0])
lhs = abs(np.dot(x, y))
rhs_1_inf = p_norm(x, 1) * p_norm(y, np.inf)
rhs_2_2 = p_norm(x, 2) * p_norm(y, 2)
print("|<x,y>|:", lhs)
print("l1/linf bound:", rhs_1_inf)
print("l2/l2 bound:", rhs_2_2)
check_true("Holder l1-linf", lhs <= rhs_1_inf + 1e-10)
check_true("Cauchy-Schwarz", lhs <= rhs_2_2 + 1e-10)
print("\nTakeaway: dual norms control worst-case linear response.")
Exercise 8 (Hard) - Contraction Mapping
Implement a contraction and find its fixed point.
Code cell 26
# Your Solution - Exercise 8: Contraction Mapping
answer = None
print("answer:", answer)
Code cell 27
# Solution
header("Exercise 8: Contraction Mapping")
gamma = 0.6
b = -1.0
x = 10.0
history = []
for _ in range(40):
x = gamma*x + b
history.append(x)
fixed = b / (1-gamma)
print("iteration result:", x)
print("fixed point:", fixed)
check_close("converges to fixed point", x, fixed, tol=1e-6)
print("\nTakeaway: contractions on complete spaces have unique fixed points reached by iteration.")
Exercise 9: Lipschitz Constants Across Norms
Estimate the operator size of a matrix under several vector norms, then explain why the chosen norm changes the certified Lipschitz constant.
Code cell 29
# Your Solution
A = np.array([[1.0, -2.0], [0.5, 1.5]])
print("Compute norm-dependent operator summaries for A.")
Code cell 30
# Solution
header("Exercise 9: Lipschitz Constants Across Norms")
A = np.array([[1.0, -2.0], [0.5, 1.5]])
# Exact induced 1- and infinity-norms are max column and row absolute sums.
op_1 = np.max(np.sum(np.abs(A), axis=0))
op_inf = np.max(np.sum(np.abs(A), axis=1))
# Spectral norm is the induced 2-norm.
op_2 = la.norm(A, 2)
print("||A||_1 =", round(float(op_1), 6))
print("||A||_2 =", round(float(op_2), 6))
print("||A||_inf =", round(float(op_inf), 6))
check_true("all constants are positive", min(op_1, op_2, op_inf) > 0)
print("Takeaway: stability certificates depend on the geometry used to measure perturbations.")
Exercise 10: Contraction Rate in a Complete Normed Space
Iterate an affine contraction and estimate the observed error ratio. Connect the numerical behavior to the Banach fixed-point theorem.
Code cell 32
# Your Solution
q = 0.65
b = 1.0
print("Simulate x_{k+1} = q x_k + b and inspect convergence.")
Code cell 33
# Solution
header("Exercise 10: Contraction Rate")
q = 0.65
b = 1.0
fixed_point = b / (1 - q)
x = 0.0
errors = []
for _ in range(12):
errors.append(abs(x - fixed_point))
x = q * x + b
ratios = np.array(errors[1:]) / np.array(errors[:-1])
print("fixed point:", round(float(fixed_point), 6))
print("last iterate:", round(float(x), 6))
print("mean observed ratio:", round(float(np.mean(ratios[-5:])), 6))
check_close("observed contraction ratio", np.mean(ratios[-5:]), q, tol=1e-10)
print("Takeaway: completeness plus q < 1 turns local shrinkage into convergence.")