Zulip Chat Archive

Stream: Is there code for X?

Topic: Linearly ordered vector spaces: spelling and linarith


Terence Tao (May 02 2025 at 20:06):

I'm interested in developing some API for linearly ordered vector spaces, in order to easily handle manipulations of asymptotic orders of magnitude (such as O(N2log3N)O(N^2 \log^3 N)) which can be viewed as belonging to such spaces (with the "logarithmic scale" interpretation of multiplication as addition, and exponentiation as scalar multiplication, while addition becomes "max" in the obvious ordering). For this I would like the ability to use a linarith type tool to immediately settle implications such as the following:

import Mathlib

example (R: Type*) [AddCommMonoid R] [Module  R] [LinearOrder R] [OrderedSMul  R] (x y z: R) (h1: x  (2:)  y) (h2: y < z) : x < (2:)  z := calc
    _  (2:)  y := h1
    _ < _ := OrderedSMul.smul_lt_smul_of_pos h2 (by norm_num)

I have two questions:

  1. Is there a better spelling for linearly ordered vector spaces than this? docs#OrderedSMul has very minimal API and states "This file is now mostly useless. We should try deleting OrderedSMul", but it is not clear what the replacement would be. There is docs#ConvexCone , which has more API, but does not have much in the way of identifying this cone with the order structure.
  2. How difficult would it be to extend linarith to be able to cover these sorts of use cases?

Yaël Dillies (May 02 2025 at 20:08):

Oh apologies, the TODO should say that the replacement is the definitions in Mathlib.Algebra.Order.Module.Defs, ie docs#PosSMulMono and friends

Terence Tao (May 02 2025 at 20:09):

Amusingly, docs#PosSMulMono states "You should usually not use this very granular typeclass directly, but rather a typeclass like OrderedSMul."

Yaël Dillies (May 02 2025 at 20:10):

Time has passed :-)

Terence Tao (May 02 2025 at 20:13):

Wait, so is the recommendation to continue using OrderedSMul, but look to docs#PosSMulMono and friends for all the actual API?

Yaël Dillies (May 02 2025 at 20:24):

No, the recommendation is to avoid using OrderedSMul as much as possible, although it is currently the most convenient option. The history is that:

  1. I encountered some use case which OrderedSMul didn't cover
  2. I added PosSMulMono and friends, with the docstring that probably you should use OrderedSMul instead
  3. I noticed that actually all OrderedSMul could do, PosSMulMono and friends could do better
  4. I generalised the OrderedSMul API to PosSMulMono and friends, and added that TODO to delete OrderedSMul
  5. The uses of OrderedSMul outside its immediate API still survive to this day, and you get confused by reading a confusing set of docstrings

Yaël Dillies (May 02 2025 at 20:25):

Of course, step 5 should have been "OrderedSMul is fully deprecated", but we all know how long my TODO list is :see_no_evil:

Ruben Van de Velde (May 02 2025 at 22:29):

Step 4.5: update the docs

Kim Morrison (Jun 18 2025 at 07:23):

grind can now prove some results about linearly ordered vector space (and give counterexamples).

open Lean.Grind

variable (R : Type) [IntModule R] [LinearOrder R] [IntModule.IsOrdered R]

example (x y z : R) (h1 : x  2 * y) (h2 : y < z) : x < 2 * z := by
  grind -- 🎉

We'll be hooking this up to Mathlib's typeclasses in the next few weeks.


Last updated: Dec 20 2025 at 21:32 UTC