Zulip Chat Archive

Stream: new members

Topic: Calculating angles


Bjørn Kjos-Hanssen (Jun 13 2025 at 18:52):

How can I calculate the angle between two concrete vectors as below? The second example does not even typecheck even though it's supposed to be identical to the first.

import Mathlib

instance : Fact (Module.finrank  (EuclideanSpace  (Fin 2)) = 2) := { out := finrank_euclideanSpace_fin }
instance :  Fact (Module.finrank  (Fin (Nat.succ 1)  ) = 2) := { out := finrank_euclideanSpace_fin }

noncomputable instance (n : Type*) [Fintype n] [DecidableEq n] :
  Module.Oriented  (EuclideanSpace  n) n :=
  Basis.orientation <| Pi.basisFun _ _⟩

open EuclideanGeometry

def e₁ : EuclideanSpace  (Fin 2) := ![1,0]

example :  e₁ 0 ![0,1] = Real.pi /(2:):= by
  sorry

example :  (![1,0] : EuclideanSpace  (Fin 2)) 0 ![0,1] = Real.pi /(2:):= by
  sorry

Junyan Xu (Jun 15 2025 at 22:20):

It doesn't typecheck because you didn't use WithLp.equiv

Bjørn Kjos-Hanssen (Jun 15 2025 at 23:35):

Oh... how?

Aaron Liu (Jun 15 2025 at 23:40):

def e₁ : EuclideanSpace  (Fin 2) := !₂[1,0]

example :  e₁ 0 !₂[0,1] = Real.pi /(2:):= by
  sorry

example :  (!₂[1,0] : EuclideanSpace  (Fin 2)) 0 !₂[0,1] = Real.pi /(2:):= by
  sorry

Bjørn Kjos-Hanssen (Jun 15 2025 at 23:58):

Oh thanks @Aaron Liu & @Junyan Xu , so the point is to write !₂. But then to finish the example I feel like we need to access the orientation somehow to make sure the answer is not negative pi/2?

Bjørn Kjos-Hanssen (Jun 17 2025 at 19:10):

OK I guess I figured it out... can post if anyone is curious :sweat_smile:

Kenny Lau (Jun 17 2025 at 19:10):

@Bjørn Kjos-Hanssen yeah I'd like to see it thanks

Bjørn Kjos-Hanssen (Jun 17 2025 at 20:01):

@Kenny Lau here you go, probably not the simplest solution but it works:

import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine

instance : Fact (Module.finrank  (EuclideanSpace  (Fin 2)) = 2) :=
  { out := finrank_euclideanSpace_fin }

noncomputable instance (n : Type*) [Fintype n] [DecidableEq n] :
    Module.Oriented  (EuclideanSpace  n) n :=
  Basis.orientation <| Pi.basisFun _ _⟩

open EuclideanGeometry Orientation

theorem calculate_angle :
    (oangle (V := (WithLp 2 (Fin 2  ))) o !₂[1, 0] !₂[0, 1]).toReal
    = Real.pi / 2 := by
  simp [Orientation.oangle, Orientation.kahler, innerₛₗ]
  rw [
    Orientation.areaForm_to_volumeForm,
    Orientation.volumeForm_robust,
    Basis.det_apply, Matrix.det_fin_two]
  rw [show (EuclideanSpace.basisFun (Fin 2) ).toBasis.toMatrix
      ![!₂[1, 0], !₂[0, 1]] = ![!₂[1, 0], !₂[0, 1]] by
          ext i j;fin_cases i <;> fin_cases j <;> rfl]
  simp
  exact rfl

Bjørn Kjos-Hanssen (Jun 20 2025 at 00:37):

By the way, the docs have a confusing typo when explaining the notation !₂ so I made #26188 to fix it.


Last updated: Dec 20 2025 at 21:32 UTC