Zulip Chat Archive

Stream: Is there code for X?

Topic: Is this a valid way of defining a typeclass?


Quarrie (Jan 25 2022 at 20:22):

I want to define a parametrized typeclass. However, the axioms that define it rely on some variables that can only be defined dependent on the parameters. If I write this:

variable parameter : Type u
variable another : (some_transformation parameter)
class parametrized parameter :=
  (axiom : some_predicate another)

would it be valid Lean code? If not, how do I render this concept?

Yaël Dillies (Jan 25 2022 at 20:23):

Yes it's definitely possible :smile:. However, you will have to make another visible from the outside of the class, as Lean can't guess it from parameter alone (however it can guess parameter from another).

Yury G. Kudryashov (Jan 25 2022 at 20:24):

It would be easier to answer if you provide a complete minimal example

Yury G. Kudryashov (Jan 25 2022 at 20:25):

Your lean code is incorrect and there is more than one way to interpret it

Yakov Pechersky (Jan 25 2022 at 20:27):

One important detail is parameter is a reserved keyword, so that probably isn't the right "variable name". You can tell from the syntax highlighting here.

Reid Barton (Jan 25 2022 at 20:29):

Likewise axiom

Yakov Pechersky (Jan 25 2022 at 20:31):

Reid, you might like: https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235698.20strongly.20regular.20graphs/near/266519557

Quarrie (Jan 25 2022 at 20:36):

So in my case, assume an inductive type called strict_product_type (E : Type u) (prod : E -> E -> E) and a function called down_convert of type strict_product_type E tprod -> Type u are defined earlier in the code. I want to write something like:

variable E : Type u
variable prod : Type u -> Type u -> Type u
variables α, β, γ : strict_product_type E prod
def α' := down_convert α
def β' := down_convert β
def γ' := down_convert γ
variable prod_t : α' -> β' -> prod α' β'
class tensor_product_family E prod prod_t :=
  (product_spaces_is_associative : (x : (prod (prod α' β') γ')) : (prod α' (prod β' γ')))
  (product_elements_is_associative :  (a : α', b : β', g : γ') ((prod_t (prod_t a b) g) = (prod_t a (prod b g)))

Adam Topaz (Jan 25 2022 at 20:40):

I think you probably just need to write

class tensor_product_family (E : Type u) (prod : Type u -> Type u -> Type u) (prod_t : α' -> β' -> prod α' β') := ...

Adam Topaz (Jan 25 2022 at 20:41):

Oh, nevermind, I see now that prod_t depends on prod.

Adam Topaz (Jan 25 2022 at 20:41):

Can you provide a #mwe that will work if we paste it in a lean file?

Quarrie (Jan 25 2022 at 20:42):

I wouldn't be asking here if I could, unfortunately

Quarrie (Jan 25 2022 at 20:42):

If I managed to disentangle the element product from the space product I don't see how I could get "the kronecker product over R^n" to be accepted as an instance for example

Adam Topaz (Jan 25 2022 at 20:43):

I mean just something that includes strict_product_typeand down_convert (or some approximation of those)

Quarrie (Jan 25 2022 at 20:43):

They are currently defined thus:

universe u
variables {α β γ : Type u}

inductive strict_product_type (E : Type u) (tprod : Type u -> Type u -> Type u)
| unit : strict_product_type
| left_prod : strict_product_type -> strict_product_type

def down_convert {E : Type u} {tprod : Type u -> Type u -> Type u} : strict_product_type E tprod -> Type u
| unit := E
| left_prod χ := (tprod E (down_convert χ))

Adam Topaz (Jan 25 2022 at 20:44):

and left_prod?

Adam Topaz (Jan 25 2022 at 20:46):

I'm just looking for code that works without the problematic class declaration.

Quarrie (Jan 25 2022 at 20:47):

left_prod is a constructor of one argument, isn't it? (Basically strict_product_type is supposed to be a Peano naturals that I can unroll with down_convert to generate some type tensor'd with itself n times.) Did I define it incorrectly?

Adam Topaz (Jan 25 2022 at 20:47):

Something is off. The code you just gave does not work. Could you take a quick look at the link #mwe ?

Quarrie (Jan 25 2022 at 20:48):

Oh right the imports

Quarrie (Jan 25 2022 at 20:48):

import algebra.module.basic
import analysis.inner_product_space.basic
import linear_algebra.bilinear_form
import linear_algebra.tensor_product

Adam Topaz (Jan 25 2022 at 20:48):

Even if I add open strict_product_type it still doesn't work.

Adam Topaz (Jan 25 2022 at 20:49):

It's not just the imports, your definition of down_convert doesn't work for me.

Quarrie (Jan 25 2022 at 20:49):

That's odd, can you paste the error you're receiving?

Adam Topaz (Jan 25 2022 at 20:51):

I get a ill-formed match/equation expression.

Quarrie (Jan 25 2022 at 20:54):

Maybe if we wrap the left_prod case with parentheses?

| (left_prod χ) := (tprod E (down_convert χ))

Adam Topaz (Jan 25 2022 at 20:58):

With the parens I still get an error, that the equation compiler fails because lean can't automatically prove the recursive function terminates. This would be a lot more efficient if you could give us some code that works, not including the class declaration that you want to ask about. If that's not the only issue, then we can start with the first problem first, but it's hard to diagnose anything if we don't have a place to start.

Eric Wieser (Jan 25 2022 at 21:00):

Perhaps checking your lean version would help here

Quarrie (Jan 25 2022 at 21:01):

@Eric Wieser
leanprover-community/lean:3.38.0

Adam Topaz (Jan 25 2022 at 21:02):

I'm also on 3.38.0 with the freshest of mathlibs.

Yury G. Kudryashov (Jan 25 2022 at 21:04):

Am I right that strict_product_type does not actually depend on E and tprod and can be replaced by a natural number?

Quarrie (Jan 25 2022 at 21:06):

Yury G. Kudryashov said:

Am I right that strict_product_type does not actually depend on E and tprod and can be replaced by a natural number?

Yeah, the work is done by the down_convert function. It's only an explicit Peano because it seemed less non-obvious-error-prone, with the plan being to replace it with the naturals from the standard library once I got it working

Quarrie (Jan 25 2022 at 21:06):

The strict_product_type type does contain E and tprod information, but that can indeed be packed into down_convert

Yury G. Kudryashov (Jan 25 2022 at 21:06):

Then

def down_convert (E : Type u) (tprod : Type u -> Type u -> Type u) : nat -> Type u
| 0 := E
| (n + 1) := (tprod E (down_convert n))

Yury G. Kudryashov (Jan 25 2022 at 21:08):

which is equivalent (but not defeq because of they use recursion on different sides) to down_convert E tprod n = (tprod E)^[n] E

Quarrie (Jan 25 2022 at 21:11):

Alright, looks like I found the root error that's causing all the rest

Quarrie (Jan 25 2022 at 21:11):

/home/quarrie/Git/mathlib_testing/src/tensor_product.lean:38:18: error: type expected at
  α'
term has type
  Type ?  (Type ?  Type ?  Type ?)    Type ?

Quarrie (Jan 25 2022 at 21:12):

...how do I interpret this? that's a concerning amount of unknown universe.

Yury G. Kudryashov (Jan 25 2022 at 21:13):

I'm not sure why it depends on a natural number.

Yaël Dillies (Jan 25 2022 at 21:13):

There's an expected line just below

Yury G. Kudryashov (Jan 25 2022 at 21:13):

What are the first 38 lines of the file?

Quarrie (Jan 25 2022 at 21:13):

Yaël Dillies said:

There's an expected line just below

No, oddly. Just below is an identical error regarding β'.

Yury G. Kudryashov (Jan 25 2022 at 21:13):

Can you just copy+paste them in #backticks?

Quarrie (Jan 25 2022 at 21:14):

Yury G. Kudryashov said:

What are the first 38 lines of the file?

With the comments removed for conciseness:

/- This was lines 1-5 -/

import algebra.module.basic
import analysis.inner_product_space.basic
import linear_algebra.bilinear_form
import linear_algebra.tensor_product

/-! This was lines 12-22 -/

namespace inner_product_space

universe u

def down_convert (E : Type u) (tprod : Type u -> Type u -> Type u) : nat -> Type u
| 0 := E
| (n + 1) := (tprod E (down_convert n))

variable E : Type u
variable prod : Type u -> Type u -> Type u
variables (α β γ : nat)
def α' := (down_convert E prod) α
def β' := (down_convert E prod) β
def γ' := (down_convert E prod) γ
variable prod_t : α' -> β' -> prod α' β'

Yury G. Kudryashov (Jan 25 2022 at 21:15):

def α' defines a type that depends on E, prod, and α.

Yury G. Kudryashov (Jan 25 2022 at 21:16):

Actually, α' is defeq to β'

Yury G. Kudryashov (Jan 25 2022 at 21:16):

And both are defeq to down_convert.

Quarrie (Jan 25 2022 at 21:17):

Yury G. Kudryashov said:

def α' defines a type that depends on E, prod, and α.

That's the intended use, since α' is meant to be an arbitrary power of E so that I can reason about its tensor product.

Yaël Dillies (Jan 25 2022 at 21:17):

So the problem is that Lean doesn't know what the argument to α' is

Yury G. Kudryashov (Jan 25 2022 at 21:17):

variables α is just a way to say "if I use α in a definition/lemma and don't list it as an argument, then add it as an argument to the definition".

Yury G. Kudryashov (Jan 25 2022 at 21:18):

Probably you want to use (untested)

local notation `α'` := down_convert E prod α

Quarrie (Jan 25 2022 at 21:20):

Good idea, let me see how that works

Yury G. Kudryashov (Jan 25 2022 at 21:21):

The problem with your def is that Lean immediately looses connection between the definition α' and the variable α.

Quarrie (Jan 25 2022 at 21:21):

That makes sense!

Quarrie (Jan 25 2022 at 21:22):

Alright, that's solved and now there's a new error

Quarrie (Jan 25 2022 at 21:22):

/home/quarrie/Git/mathlib_testing/src/tensor_product.lean:39:0: error: infer type failed, sort expected
  ?m_1[E]

Quarrie (Jan 25 2022 at 21:22):

(line 39 is the typeclass declaration)

Yury G. Kudryashov (Jan 25 2022 at 21:23):

We need to see the source code, not just the error message.

Quarrie (Jan 25 2022 at 21:23):

/- Former 1-5 -/

import algebra.module.basic
import analysis.inner_product_space.basic
import linear_algebra.bilinear_form
import linear_algebra.tensor_product

/-! Formerly 12-22 -/

namespace inner_product_space

universe u

def down_convert (E : Type u) (tprod : Type u -> Type u -> Type u) : nat -> Type u
| 0 := E
| (n + 1) := (tprod E (down_convert n))

variable E : Type u
variable prod : Type u -> Type u -> Type u
variables (α β γ : nat)
local notation `α'` := down_convert E prod α
local notation `β'` := down_convert E prod β
local notation `γ'` := down_convert E prod γ
variable prod_t : α' -> β' -> prod α' β'
class tensor_product_family E prod prod_t :=
  (product_spaces_is_associative : (x : (prod (prod α' β') γ')) : (prod α' (prod β' γ')))
  (product_elements_is_associative :  (a : α', b : β', g : γ') ((prod_t (prod_t a b) g) = (prod_t a (prod b g)))

end inner_product_space

Yaël Dillies (Jan 25 2022 at 21:24):

You only need one of the notations if you make it local notation α ' := down_convert E prod α

Yury G. Kudryashov (Jan 25 2022 at 21:30):

Let's not optimize before we catch the bug.

Yury G. Kudryashov (Jan 25 2022 at 21:30):

Also, with your notation Lean will try to use down_convert for a'.

Yury G. Kudryashov (Jan 25 2022 at 21:31):

product_spaces_is_associative has no / on x.

Yury G. Kudryashov (Jan 25 2022 at 21:34):

Can you post the mathematical definition you're trying to formalize (e.g., what are prod, prod_t in some important specific case)?

Quarrie (Jan 25 2022 at 21:53):

Yury G. Kudryashov said:

Can you post the mathematical definition you're trying to formalize (e.g., what are prod, prod_t in some important specific case)?

In one extremely important specific case, prod is CnCmCnm\mathbb{C}^n \rightarrow \mathbb{C}^m \rightarrow \mathbb{C}^{n*m} and prod_t is i=0naieij=0mbjeji=0nj=0maibjeim+j\sum_{i = 0}^{n} a_ie_i \rightarrow \sum_{j = 0}^{m} b_je_j \rightarrow \sum_{i = 0}^{n} \sum_{j = 0}^{m} a_ib_je_{im+j}

Quarrie (Jan 25 2022 at 21:54):

The axiom about type product associativity is then "it makes sense to talk about an n-qubit state" and the axiom about element product associativity is then "if a state is separable, what order you separate it in doesn't change the individual qubits"

Heather Macbeth (Jan 25 2022 at 21:54):

double $ :)

Quarrie (Jan 25 2022 at 21:54):

thank you

Yury G. Kudryashov (Jan 25 2022 at 22:01):

What exactly should the first axiom say (in terms of , etc)?

Quarrie (Jan 25 2022 at 22:01):

(deleted)

Yury G. Kudryashov (Jan 25 2022 at 22:01):

Note that Lean doesn't understand that, e.g., α × (β × γ) and (α × β) × γ are "equal".

Yury G. Kudryashov (Jan 25 2022 at 22:02):

You need to insert an explicit isomorphism.

Yury G. Kudryashov (Jan 25 2022 at 22:03):

And probably you should use this isomorphism in the second axiom.

Yury G. Kudryashov (Jan 25 2022 at 22:03):

/me is away for 1-2 hrs

Quarrie (Jan 25 2022 at 22:04):

Yury G. Kudryashov said:

What exactly should the first axiom say (in terms of , etc)?

a,b,gN,Ea(EbEg)=(EaEb)Eg\forall a, b, g \in \mathbb{N}, E^{\otimes a} \otimes (E^{\otimes b} \otimes E^{\otimes g}) = (E^{\otimes a} \otimes E^{\otimes b}) \otimes E^{\otimes g}

Quarrie (Jan 25 2022 at 22:04):

They should be the same type, so putting an isomorphism there would break it.

Quarrie (Jan 25 2022 at 22:05):

More clearly, the example I'm using is let EC2,a=1,b=1,g=2E \coloneqq \mathbb{C}^2, a = 1, b = 1, g = 2.

Yury G. Kudryashov (Jan 25 2022 at 22:05):

You shouldn't use equality of types in your axioms.

Yaël Dillies (Jan 25 2022 at 22:05):

They won't ever be the same type. And even if they were, you shouldn't use this equality.

Yaël Dillies (Jan 25 2022 at 22:05):

Equality of types is evil.

Yury G. Kudryashov (Jan 25 2022 at 22:06):

You should either make them defeq (probably, impossible), or introduce explicit isomorphisms.

Quarrie (Jan 25 2022 at 22:06):

Yaël Dillies said:

They won't ever be the same type. And even if they were, you shouldn't use this equality.

For clarity, this is not a cartesian product. This is a tensor product of which Kronecker is an example

Yakov Pechersky (Jan 25 2022 at 22:06):

Maybe, one can say, you don't require the full power of "equality of types" as an axiom, even having a weaker "these types are explicitly isomorphic" will likely be powerful enough for what you want to use this structure for.

Yury G. Kudryashov (Jan 25 2022 at 22:07):

Then you'll need extra axioms about this family of isomorphisms.

Adam Topaz (Jan 25 2022 at 22:07):

I'm fairly sure @Amelia Livingston ran into similar issues when working on the tensor algebra.

Quarrie (Jan 25 2022 at 22:07):

Yaël Dillies said:

Equality of types is evil.

How should I handle this, then?

Quarrie (Jan 25 2022 at 22:07):

I cannot use an isomorphism as that would destroy the power of the axiom.

Adam Topaz (Jan 25 2022 at 22:08):

What are you trying to do, mathematically?

Yaël Dillies (Jan 25 2022 at 22:08):

The power of the axiom is that it is usually unprovable? :thinking:

Quarrie (Jan 25 2022 at 22:09):

Adam Topaz said:

What are you trying to do, mathematically?

Define a family of types endowed with a tensor product, so that I can reason about an n-qubit system.

Adam Topaz (Jan 25 2022 at 22:09):

Take a look at docs#category_theory.monoidal_category

Quarrie (Jan 25 2022 at 22:10):

404's out, which one?

Adam Topaz (Jan 25 2022 at 22:10):

Sorry, I fixed the link

Adam Topaz (Jan 25 2022 at 22:11):

Note the associator axiom, for example

Adam Topaz (Jan 25 2022 at 22:14):

I don't know how much category theory you want to use in your work, but using monoidal categories is one possible approach

Quarrie (Jan 25 2022 at 22:16):

This does look useful, though I'll have to restrict the dependent product to an independent product and the associator to the identity.

Quarrie (Jan 25 2022 at 22:16):

Thanks!

Adam Topaz (Jan 25 2022 at 22:18):

But you can't restrict them to the identity!

Adam Topaz (Jan 25 2022 at 22:20):

The tensor product A(BC)A\otimes(B\otimes C) is not equal to (AB)C(A\otimes B)\otimes C (at least for vector spaces).

Quarrie (Jan 25 2022 at 22:29):

Adam Topaz said:

The tensor product A(BC)A\otimes(B\otimes C) is not equal to (AB)C(A\otimes B)\otimes C (at least for vector spaces).

Is Kronecker product not an instance of \otimes?

Quarrie (Jan 25 2022 at 22:31):

I've been under the impression that it makes sense to write (C2C2)C4=C2(C2C4)=C16(\mathbb{C}^2 \otimes \mathbb{C}^2) \otimes \mathbb{C}^4 = \mathbb{C}^2 \otimes (\mathbb{C}^2 \otimes \mathbb{C}^4) = \mathbb{C}^{16} for instance

Kevin Buzzard (Jan 25 2022 at 22:35):

The tensor product of two vector spaces is "defined" by a universal property, so it doesn't really even make sense to ask if two tensor products are equal.

Heather Macbeth (Jan 25 2022 at 22:36):

(Of course, we agree these spaces are "canonically isomorphic".)

Adam Topaz (Jan 25 2022 at 22:36):

The equality symbol you're using there means "canonical isomorphism"

Heather Macbeth (Jan 25 2022 at 22:36):

(snap!)

Quarrie (Jan 25 2022 at 22:36):

Kevin Buzzard said:

The tensor product of two vector spaces is "defined" by a universal property, so it doesn't really even make sense to ask if two tensor products are equal.

Okay, so what's the word for the thing I want (an instance of a product that satisfies that property)?

Adam Topaz (Jan 25 2022 at 22:37):

And actually the right-hand equality (the one with C^16 on the right) should NOT be written as equality (in my opinion).

Kevin Buzzard (Jan 25 2022 at 22:37):

What do you mean by VWV\otimes W? You can't mean "any vector space satisfying the universal property" because in formalised mathematics this cannot be used as a definition. So you have to choose some explicit model, perhaps some quotient of some huge group or whatever definition you want to use in your proof that tensor products exist. And the moment you make that choice none of the things you're claiming are equalities, are in fact equalities.

Kevin Buzzard (Jan 25 2022 at 22:39):

They're canonical isomorphisms, sure. But that's not what the = symbol means in lean.

Kevin Buzzard (Jan 25 2022 at 22:40):

In fact as Adam says that last iso to C^16 isn't even canonical. We all agree that 2*2*4=16 but when you categorify the equality changes to an isomorphism

Quarrie (Jan 25 2022 at 22:41):

Kevin Buzzard said:

What do you mean by VWV\otimes W? You can't mean "any vector space satisfying the universal property" because in formalised mathematics this cannot be used as a definition. So you have to choose some explicit model, perhaps some quotient of some huge group or whatever definition you want to use in your proof that tensor products exist. And the moment you make that choice none of the things you're claiming are equalities, are in fact equalities.

My intention was that the meaning of VWV \otimes W was decided by the programmer at the moment that the programmer endowed the family of types containing VV and WW with an \otimes operation. In my case, I want to use this for quantum program verification, so I'm working on Cn\mathbb{C}^n and want to let \otimes be the Kronecker product and show that it satisfies insert axioms here.

Kevin Buzzard (Jan 25 2022 at 22:42):

The axioms you want are those of a monoidal category perhaps

Adam Topaz (Jan 25 2022 at 22:42):

Note Module \C is a category which should have a monoidal category instance :) docs#Module

Kevin Buzzard (Jan 25 2022 at 22:43):

When the programmer made the definition they did indeed make an explicit construction and that's exactly why we know that the tensor product can't be proved to be associative on the nose

Kevin Buzzard (Jan 25 2022 at 22:45):

And as for identifying it with C^16 you'll have to explicitly decide how to order your basis vectors of the tensor product -- the isomorphism here involves a genuine choice which you'll need to keep track of if you're doing mathematics rigourously

Quarrie (Jan 25 2022 at 22:46):

Kevin Buzzard said:

When the programmer made the definition they did indeed make an explicit construction and that's exactly why we know that the tensor product can't be proved to be associative on the nose

Why wouldn't a user-supplied tensor product instance be provably associative? Would CnCmCnm\mathbb{C}^n \otimes \mathbb{C}^m \coloneqq \mathbb{C}^{nm} with ei:Cn,ej:Cm,eitej=eim+je_i : \mathbb{C}^n, e_j : \mathbb{C}^m, e_i \otimes_t e_j = e_{im + j} not function as a tensor product?

Kevin Buzzard (Jan 25 2022 at 22:47):

It would function as a tensor product in that case but it's not the definition which was made in Lean

Kevin Buzzard (Jan 25 2022 at 22:48):

Your definition is isomorphic to Lean's, hence the isomorphism we're all going on about

Quarrie (Jan 25 2022 at 22:49):

The typeclass I'm building forces the user to supply their own tensor product though, by providing it as an argument (e.g. one might say "C2\mathbb{C}^2 forms a family of types endowed with the tensor product kron")

Quarrie (Jan 25 2022 at 22:50):

Is this non-idiomatic for Lean code?

Kyle Miller (Jan 25 2022 at 22:54):

Maybe the key words here are that @Quarrie wants a strictification of the monoidal category of vector spaces with tensor products

Adam Topaz (Jan 25 2022 at 22:54):

You can define a skeleton for the subcategory of Module C of f.d. spaces which has N as the type of objects. But again, associativity of multiplication of naturals is propositional equality, not definitional equality, so you will likely run into issues if you start using equality of objects in this skeletal category.

Adam Topaz (Jan 25 2022 at 22:55):

(if you also want infinite dimensional vector spaces, you can work with cardinals)

Kyle Miller (Jan 25 2022 at 22:57):

I'm not sure you can define a strictification like this with prod taking Types. This is what down_convert is presumably tying to solve?

Maybe another way is to have a function that takes List Nat and produces the corresponding vector space? Tensor product is then concatenation of lists, which is strictly associative. But then you still have these canonical isomorphisms for whether you concatenate then take the vector space or take the vector spaces and then tensor product.

Quarrie (Jan 25 2022 at 23:00):

Kyle Miller said:

I'm not sure you can define a strictification like this with prod taking Types. This is what down_convert is presumably tying to solve?

Maybe another way is to have a function that takes List Nat and produces the corresponding vector space? Tensor product is then concatenation of lists, which is strictly associative. But then you still have these canonical isomorphisms for whether you concatenate then take the vector space or take the vector spaces and then tensor product.

down_convert is meant to define a single canonical order of association so that I can (a) check if associating in a different order produces the same result, and (b) have a convenient way to induct through the powers of E. Re: Type u, I ideally want prod to only have to accept powers of E (after all, doesn't really make sense to take the Kronecker product of objects that don't even have a scalar multiple operation, and I'd rather not deal with such when instantiating the Kronecker product as this typeclass) -- is this conveniently possible in Lean?

Adam Topaz (Jan 25 2022 at 23:03):

docs#matrix.kronecker

Kyle Miller (Jan 25 2022 at 23:03):

I don't know how well this will work in practice, but what I was suggesting is trying to leave the tensor product in the list nat representation as long as possible, and then prod only takes powers of E since it's actually only taking these lists

Kyle Miller (Jan 25 2022 at 23:05):

A problem with Type is that, unlike for terms of inductive types, you can't do any sort of match expression on types. So, a way around this is to manipulate algebraic expressions (here, lists of naturals) that then get turned into types.

Quarrie (Jan 25 2022 at 23:09):

Kyle Miller said:

I don't know how well this will work in practice, but what I was suggesting is trying to leave the tensor product in the list nat representation as long as possible, and then prod only takes powers of E since it's actually only taking these lists

An issue there would seem to be that this produces the product spaces, but does not offer a way to give the product elements.

Kyle Miller (Jan 25 2022 at 23:11):

Right, that is an issue. A way around that is to have a wrapper around list nat so that it has a coercion to a Type, so you can pretend it's actually a vector space. I need to check how well this actually works in this case

Quarrie (Jan 25 2022 at 23:23):

So basically, the user would supply:

  • the base type
  • what's basically a Peano successor, but for tensor products
  • and the element tensor product
    Is this correct?

Yury G. Kudryashov (Jan 25 2022 at 23:24):

When you write a typeclass, it is useful to define at least one instance of that class.

Yury G. Kudryashov (Jan 25 2022 at 23:24):

This way you'll see whether your axioms make sense in Lean.

Yury G. Kudryashov (Jan 25 2022 at 23:25):

So, you can start with an instance.

Yury G. Kudryashov (Jan 25 2022 at 23:25):

Define some prod etc (note that prod in the root namespace is taken), then prove some lemmas about your definitions, then define a typeclass that takes these lemmas as arguments.

Quarrie (Jan 25 2022 at 23:28):

:+1:

Yakov Pechersky (Jan 26 2022 at 00:17):

Regarding a list of types, that design strategy is explored in docs#holor

Kyle Miller (Jan 26 2022 at 00:27):

I haven't succeeded really with my proposal, other than defining a function that takes lists of natural numbers to specific tensor products of spaces.

Is there a better way to recursively take tensor products of spaces? It was awkward needing to recursively create the space and passing along the necessary typeclasses for each step.

Code

Adam Topaz (Jan 26 2022 at 00:49):

@Kyle Miller you could use docs#Module with the monoidal tensor product. The correct instances will be part of the structure.

Adam Topaz (Jan 26 2022 at 00:55):

(deleted)

Adam Topaz (Jan 26 2022 at 00:55):

Thats wrong. one sec

Adam Topaz (Jan 26 2022 at 00:55):

This is better:

import algebra.category.Module.monoidal

universes u

variables (A : Type u) [comm_ring A]

def foo : list   Module.{u} A
| [] := 𝟙_ (Module.{u} A)
| (x :: xs) := Module.of A (fin x  A)  foo xs

Adam Topaz (Jan 26 2022 at 00:56):

Of course you could replace A with any A-module M, as needed.

Adam Topaz (Jan 26 2022 at 00:58):

Note that this is indeed defeq;

example (M N : Module.{u} A) : tensor_product A M N = (M  N : Module.{u} A) := rfl

Adam Topaz (Jan 26 2022 at 00:59):

but there is a clash of notations, since \otimes is used both for the unbundled tensor product (under the tensor_product locale), and for the monoidal one.

Adam Topaz (Jan 26 2022 at 02:09):

Of course, we could also use list.foldr:

import algebra.category.Module.monoidal

universes u

variables (A : Type u) [comm_ring A]

def foo : list   Module.{u} A :=
list.foldr (λ n M, Module.of A (fin n  A)  M) (𝟙_ _)

Last updated: Dec 20 2023 at 11:08 UTC