Skip to content

feat: metric connections#36299

Open
grunweg wants to merge 36 commits intoleanprover-community:masterfrom
grunweg:covariant-derivatives-metric
Open

feat: metric connections#36299
grunweg wants to merge 36 commits intoleanprover-community:masterfrom
grunweg:covariant-derivatives-metric

Conversation

@grunweg
Copy link
Copy Markdown
Contributor

@grunweg grunweg commented Mar 6, 2026

This file defines what it means for a connection on a Riemannian vector bundle (V, g) to be compatible with the metric g. Namely, the differentiated metric tensor ∇ g (defined by (X, σ, τ) ↦ X g(σ, τ) - g(∇_X σ, τ) - g(σ, ∇_X τ)) should vanish on all differentiable vector fields X and differentiable sections σ, τ.

From the path towards the the Levi-Civita connection and Riemannian geometry.

Co-authored-by: Heather Macbeth 25316162+hrmacbeth@users.noreply.github.com
Co-authored-by: Patrick Massot patrickmassot@free.fr


WIP: some API issues need to be decided, some slow proofs need to be diagnosed, some documentation needs to be improved, and may adjust variable names/ theorem names/notation.

Open in Gitpod

@grunweg grunweg added WIP Work in progress t-differential-geometry Manifolds etc labels Mar 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2026

PR summary de8a06c8fd

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Geometry.Manifold.VectorBundle.CovariantDerivative.Metric (new file) 2273

Declarations diff

+ IsCompatible
+ compatibilityTensor
+ compatibilityTensorAux
+ compatibilityTensorAux_apply
+ compatibilityTensorAux_tensorial₁
+ compatibilityTensorAux_tensorial₂
+ compatibilityTensor_apply
+ compatibilityTensor_apply_eq_extend
+ fromTangentSpace_mfderiv_add
+ fromTangentSpace_mfderiv_add_apply
+ isCompatible_iff
+ product
+ product_add_left
+ product_add_left_apply
+ product_add_right
+ product_add_right_apply
+ product_apply
+ product_congr_left
+ product_congr_left₂
+ product_congr_right
+ product_congr_right₂
+ product_neg_left
+ product_neg_right
+ product_smul_const_left
+ product_smul_const_right
+ product_smul_left
+ product_smul_right
+ product_sub_left
+ product_sub_right
+ product_swap
+ product_zero_left
+ product_zero_right

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@mathlib-dependent-issues mathlib-dependent-issues bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Mar 6, 2026
@hrmacbeth hrmacbeth changed the title feat: metric connections on the tangent bundle feat: metric connections Mar 7, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 11, 2026
@mathlib-merge-conflicts
Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-dependent-issues mathlib-dependent-issues bot removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Mar 12, 2026
@mathlib-dependent-issues
Copy link
Copy Markdown

@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 12, 2026
grunweg added a commit to grunweg/mathlib4 that referenced this pull request Mar 19, 2026
We never unbundled the normed and algebra hierarchies, and this is causing
performance problems in leanprover-community#36299 and friends. Try if lowering the respective
instance priorities helps.
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 19, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Mar 19, 2026

Benchmark results for 49bf82d against de8a06c are in. There are no significant changes. @grunweg

  • 🟥 build//instructions: +634.1G (+0.36%)

Small changes (2🟥)

  • 🟥 build//instructions: +634.1G (+0.36%)
  • 🟥 build//wall-clock: +7s (+1.17%)

and 1 hidden

@grunweg grunweg added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Mar 19, 2026
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 19, 2026

Let's try the effect of the commit I just pushed. (I know locally that it helps, let's see how much.)

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 19, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Mar 19, 2026

Benchmark results for 2f1bbfe against de8a06c are in. There are no significant changes. @grunweg

  • 🟥 build//instructions: +467.6G (+0.26%)

Small changes (2🟥)

  • 🟥 build//instructions: +467.6G (+0.26%)
  • 🟥 build/module/Mathlib.Analysis.InnerProductSpace.Harmonic.HarmonicContOnCl//instructions: +343.1M (+3.01%)

and 1 hidden

@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Mar 19, 2026
@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 19, 2026

26% faster, not bad!


## Main definitions and results

* `CovariantDerivative.compatibilityTensor`: the tensor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced by this name, because nothing says it's about metrics. Compatibility of covariant derivatives and other objects can make sense, so the name should be more specific.

## Main definitions and results

* `CovariantDerivative.compatibilityTensor`: the tensor
`(X, σ, τ) ↦ X g(σ, τ) - g(∇_X σ, τ) - g(σ, ∇_X τ)` defining when a connection `∇` on a Riemannian
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're writing the first derivative as X ..., 6 lines above you write it as ∇_X. You could also use L_X to emphasize it's the usual derivative of a genuine function with respect to the vector field, no bundles or connections involved.


A connection on `V` is compatible with the metric on `V` iff `X ⟨σ, τ⟩ = ⟨∇_X σ, τ⟩ + ⟨σ, ∇_X τ⟩`
holds for all sufficiently nice vector fields `X` on `M` and sections `σ`, `τ` of `V`.
The left hand side is the pushforward of the function `⟨σ, τ⟩` along the vector field `X`:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushforward sounds strange to me here.

-- set_option profiler.threshold 500

/-- The scalar product of two sections. -/
noncomputable abbrev product (σ τ : Π x : M, V x) : M → ℝ :=
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to introduce a new definition, that will then be available throughout Mathlib for everyone? Wouldn't a notation local to the file make more sense?

@sgouezel
Copy link
Copy Markdown
Contributor

I've just pushed a change with the correct variable lines. This solves the performance issue as far as I can tell.

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 29, 2026

Thanks a lot! Let's see what the benchmark says, for posterity.

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 29, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Mar 29, 2026

Benchmark results for a2e9ee1 against de8a06c are in. There are no significant changes. @grunweg

  • build//instructions: -822.1M (-0.00%)

Small changes (3✅, 1🟥)

  • build/module/Mathlib.Data.Bracket//instructions: -123.3M (-5.03%)
  • 🟥 build/module/Mathlib.Lean.Elab.InfoTree//instructions: +118.2M (+4.75%)
  • build/module/Mathlib.Tactic.SuppressCompilation//instructions: -288.6M (-4.25%)
  • build/module/Mathlib.Util.TransImports//instructions: -129.5M (-4.69%)

The left hand side is the pushforward of the function `⟨σ, τ⟩` along the vector field `X`:
the left hand side at `x` is `df(X x)`, where `f := ⟨σ, τ⟩` (ie. `X` is seen a derivation on
the algebra of function on the base manifold acting on the function `⟨σ, τ⟩`).
In our definition, we ask for this identity to at each `x : M`, whenever `X`, `σ` and `τ` are
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In our definition, we ask for this identity to at each `x : M`, whenever `X`, ` and ` are
In our definition, we ask for this identity to hold at each `x : M`, whenever `X`, ` and ` are

@grunweg
Copy link
Copy Markdown
Contributor Author

grunweg commented Mar 29, 2026

Metric.lean is down to 55G instructions, nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-differential-geometry Manifolds etc WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants