Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DepArray #166

Closed

Conversation

JamesGallicchio
Copy link
Collaborator

Dependent array -- the types of each element can depend on the index.

This is a very minimal proof of concept implementation, but a DepArray would fit nicely in a hierarchy of array primitives "lower" than the built-in Array. It is a generalization of SciLean.Data.ArrayN and LeanColls.ArrayUninit.

It is also useful for caching dependent functions over FinEnum domains, which is my use case.

@digama0 digama0 requested a review from gebner June 26, 2023 08:20
proj_inj (a : α) : proj (inj a) = cast (type_inj a).symm a

/-- States that `Intf.TypeErased` is a safe interface. -/
axiom InftSafe.{u} : Nonempty (TypeErased.Intf.{u})
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, axiom is forbidden in std, it can't be merged as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Understandable. I'd rather push for Erased to be supported in core; perhaps for now we replace it with a sigma type and pretend it has no overhead? :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps only Inhabited types should be erasable, that way you can use partial instead of axiom.

Copy link
Member

Choose a reason for hiding this comment

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

Here's a proof that this axiom is false:

import Mathlib.SetTheory.Cardinal.Ordinal

namespace Std.TypeErased

structure Intf.{u} where
  TypeErased : Type u
  type : TypeErased → Type u
  proj (t : TypeErased) : type t
  inj : α → TypeErased
  type_inj (a : α) : type (inj a) = α
  proj_inj (a : α) : proj (inj a) = cast (type_inj a).symm a

open Order Cardinal Function in
example : ¬ Nonempty (TypeErased.Intf.{u})
  | ⟨{ TypeErased, type, inj, type_inj, .. }⟩ => by
    have a (c : Cardinal.{u}) : (succ c).out :=
      (mk_ne_zero_iff.1 (mk_out _ ▸ succ_ne_zero _)).some
    let F (c) := inj (a c)
    have {c} : (#type (F c)) = succ c := type_inj _ ▸ mk_out _
    have : Injective F := fun a b h => succ_injective <|
      this.symm.trans <| (congrArg (#type ·) h).trans this
    have := lift_mk_le.{u+1}.2 ⟨⟨_, this⟩⟩
    rw [lift_id, mk_cardinal, ← not_lt] at this
    exact this (lift_lt_univ _)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants