Zulip Chat Archive

Stream: maths

Topic: how to define positive cones in $\mathbb{R}^n$?


Apurva Nakade (Aug 11 2022 at 13:20):

I want to define the docs#convex_cone.positive consisting of vectors of a finite size n with all coordinates non-negative. If I try

#check convex_cone.positive  (fin 2  )

I get the following error:

failed to synthesize type class instance for
𝕜 : Type u_1,
E : Type u_2,
F : Type u_3,
G : Type u_4,
_inst_1 : add_comm_group E,
_inst_2 : module  E
 ordered_smul  (fin 2  )

I'm getting really lost in the various instance hierarchies in trying to define this. Any suggestions on how to do this?

Yaël Dillies (Aug 11 2022 at 13:20):

That should be obvious.

Yaël Dillies (Aug 11 2022 at 13:20):

Are you importing docs#pi.ordered_smul?

Apurva Nakade (Aug 11 2022 at 13:22):

Didn't know about this file. Let me try.

Apurva Nakade (Aug 11 2022 at 13:23):

Same error even with the import

Yaël Dillies (Aug 11 2022 at 13:23):

Give me a MWE, I'll fix it.

Apurva Nakade (Aug 11 2022 at 13:24):

import analysis.cone.basic
import algebra.order.module

#check convex_cone.positive  (fin 2  )

Yaël Dillies (Aug 11 2022 at 13:24):

analysis.cone.basic doesn't exist

Apurva Nakade (Aug 11 2022 at 13:25):

typo, convex

Apurva Nakade (Aug 11 2022 at 13:25):

analysis.convex.basic

sorry

Yaël Dillies (Aug 11 2022 at 13:25):

file#analysis/convex/cone, actually

Apurva Nakade (Aug 11 2022 at 13:27):

my vscode is stuck, 1 min, will fix the MWE

Apurva Nakade (Aug 11 2022 at 13:30):

ok here's is the corrected mwe

import analysis.convex.cone
import algebra.order.module

#check convex_cone.positive  (fin 2  )

and the error is

failed to synthesize type class instance for
 ordered_smul  (fin 2  )

Yaël Dillies (Aug 11 2022 at 13:45):

Okay, this is really weird.

import algebra.order.module
import data.real.basic

example : ordered_smul   := infer_instance
noncomputable example : linear_ordered_field  := infer_instance
example : mul_action_with_zero   := infer_instance
example : ordered_add_comm_group  := infer_instance

example : ordered_smul  (fin 2  ) := infer_instance -- fails
example : ordered_smul  (fin 2  ) := @pi.ordered_smul'  _ (fin 2)  _ _ _ -- works

Yaël Dillies (Aug 11 2022 at 13:47):

TC inference does try unifyingpi.ordered_smul' but then it fails to find linear_ordered_field ℝ, even though it's clearly there.

Yaël Dillies (Aug 11 2022 at 13:49):

Looking at the trace, it might be because it finds a huge term for ordered_add_comm_monoid (fin 2 → ℝ). Maybe it would also help if docs#ordered_smul only assumed docs#has_smul, not docs#smul_with_zero.

Apurva Nakade (Aug 11 2022 at 14:08):

Should I try removing it? I don't think my laptop can handle this deep a change though lol. I can only push this change to mathlib and wait for CI.

Eric Wieser (Aug 11 2022 at 14:16):

Is docs#pi.ordered_smul true more generally without needing linear_ordered_field?

Apurva Nakade (Aug 11 2022 at 15:15):

But this shouldn't cause problems for modules, no?

Yaël Dillies (Aug 11 2022 at 15:19):

Yes it should be. Looks like everything got dumped into the same section by accident.

Apurva Nakade (Aug 12 2022 at 05:29):

Should I create an Issue for now?

Yaël Dillies (Aug 12 2022 at 05:36):

Am still trying to fix it, fwiw

Apurva Nakade (Aug 12 2022 at 05:46):

Oh, oops, thank you so much! I saw your reply one min after I posted #16021

Yaël Dillies (Aug 18 2022 at 15:01):

I cleaned up algebra.order.smul and algebra.order.module, but that still didn't the error, so in # I am adding yet another redundant instance.

import algebra.order.module
import data.real.basic

variables {ι : Type*}

example : ordered_smul   := infer_instance
noncomputable example : linear_ordered_field  := infer_instance
example : mul_action_with_zero   := infer_instance
example : ordered_add_comm_group  := infer_instance

example : ordered_smul  (ι  ) := infer_instance -- fails
example : ordered_smul  (ι  ) := @pi.ordered_smul' ι   _ _ _ _ -- works

(MWE on #16131 when removing pi.ordered_smul'')
cc @Apurva Nakade

Apurva Nakade (Aug 19 2022 at 07:17):

Thank you! Do you have a general sense of why this is happening? Are there some diamonds being created which prevents lean from infering the correct instance?

Yaël Dillies (Aug 19 2022 at 07:21):

No, I don't understand why Lean fails to find linear_ordered_field ℝ within the search for ordered_smul ℝ (ι → ℝ).

Yaël Dillies (Aug 19 2022 at 07:24):

Maybe @Anne Baanen will have an idea?

Eric Wieser (Aug 19 2022 at 07:47):

It's the standard pi typeclass issue for dependent type classes

Yaël Dillies (Aug 19 2022 at 07:56):

Yes, but why is it failing given that we have docs#pi.ordered_smul'?

Eric Wieser (Aug 19 2022 at 08:06):

Because that's about @module (ring.to_semiring) or similar, but here you need @module (comm_semiring.to_semiring) or similar

Eric Wieser (Aug 19 2022 at 08:07):

(or more likely, the same problem but for the add_comm_monoid argument since that's about a pi type)

Yaël Dillies (Aug 19 2022 at 08:10):

But surely that doesn't matter? This kind of mismatch happens all over the place.

Eric Wieser (Aug 19 2022 at 13:55):

Yeah, and it causes problems all over the place too

Eric Wieser (Aug 19 2022 at 13:56):

See for instance these lines which provide docs#function.algebra_ring and friends

Eric Wieser (Aug 19 2022 at 13:57):

It's possible having a function.module_ring shortcut instance would solve the ordered_smul problem being faced here.


Last updated: Dec 20 2023 at 11:08 UTC