The class GetElem coll idx elem valid implements the xs[i] notation.
Given xs[i] with xs : coll and i : idx, Lean looks for an instance of
GetElem coll idx elem valid and uses this to infer the type of return
value elem and side conditions valid required to ensure xs[i] yields
a valid value of type elem.
For example, the instance for arrays looks like
GetElem (Array α) Nat α (fun xs i => i < xs.size).
The proof side-condition valid xs i is automatically dispatched by the
get_elem_tactic tactic, which can be extended by adding more clauses to
get_elem_tactic_trivial.
- getElem : (xs : coll) → (i : idx) → valid xs i → elem
The syntax
arr[i]gets thei'th element of the collectionarr. If there are proof side conditions to the application, they will be automatically inferred by theget_elem_tactictactic.The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : αwherearr : Array αandi : Natori : USize: does array indexing with no bounds check and a proof side goali < arr.size.l[i] : αwherel : List αandi : Nat: index into a list, with proof side goali < l.length.stx[i] : Syntaxwherestx : Syntaxandi : Nat: get a syntax argument, no side goal (returns.missingout of range)
There are other variations on this syntax:
Instances
The syntax arr[i] gets the i'th element of the collection arr. If there
are proof side conditions to the application, they will be automatically
inferred by the get_elem_tactic tactic.
The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : αwherearr : Array αandi : Natori : USize: does array indexing with no bounds check and a proof side goali < arr.size.l[i] : αwherel : List αandi : Nat: index into a list, with proof side goali < l.length.stx[i] : Syntaxwherestx : Syntaxandi : Nat: get a syntax argument, no side goal (returns.missingout of range)
There are other variations on this syntax:
arr[i]!is syntax forgetElem! arr iwhich should panic and returndefault : αif the index is not valid.arr[i]?is syntax forgetElem?which should returnnoneif the index is not valid.arr[i]'his syntax forgetElem arr i hwithhan explicit proof the index is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i] gets the i'th element of the collection arr. If there
are proof side conditions to the application, they will be automatically
inferred by the get_elem_tactic tactic.
The actual behavior of this class is type-dependent, but here are some important implementations:
arr[i] : αwherearr : Array αandi : Natori : USize: does array indexing with no bounds check and a proof side goali < arr.size.l[i] : αwherel : List αandi : Nat: index into a list, with proof side goali < l.length.stx[i] : Syntaxwherestx : Syntaxandi : Nat: get a syntax argument, no side goal (returns.missingout of range)
There are other variations on this syntax:
arr[i]!is syntax forgetElem! arr iwhich should panic and returndefault : αif the index is not valid.arr[i]?is syntax forgetElem?which should returnnoneif the index is not valid.arr[i]'his syntax forgetElem arr i hwithhan explicit proof the index is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i]? gets the i'th element of the collection arr or
returns none if i is out of bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax arr[i]! gets the i'th element of the collection arr and
panics i is out of bounds.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- One or more equations did not get rendered due to their size.