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

Meaningful fields for Subarray #2164

Closed
1 task done
fgdorais opened this issue Mar 23, 2023 · 1 comment
Closed
1 task done

Meaningful fields for Subarray #2164

fgdorais opened this issue Mar 23, 2023 · 1 comment

Comments

@fgdorais
Copy link
Contributor

fgdorais commented Mar 23, 2023

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

The current Subarray structure has cryptic field names:

structure Subarray (α : Type u)  where
  as : Array α
  start : Nat
  stop : Nat
  h₁ : start ≤ stop
  h₂ : stop ≤ as.size

I propose the following alternative with more intuitive field names:

structure Subarray (α : Type u) extends Array α where
  start : Nat
  stop : Nat
  valid : start ≤ stop ∧ stop ≤ toArray.size

I have a potential PR candidate implementing this: https://github.com/fgdorais/lean4/tree/subarray

@fgdorais
Copy link
Contributor Author

fgdorais commented Mar 23, 2023

An alternative with a simpler validity condition would be:

structure Subarray (α : Type u) extends Array α where
  start : Nat
  size  : Nat
  valid : start + size ≤ toArray.size

abbrev Subarray.stop (as : Subarray α) : Nat := as.start + as.size

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

No branches or pull requests

1 participant