forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change Array.set to take a Nat and a tactic provided bound (lea…
…nprover#5988) This PR changes the signature of `Array.set` to take a `Nat`, and a tactic-provided bound, rather than a `Fin`. Corresponding changes (but without the auto-param) for `Array.get` will arrive shortly, after which I'll go more pervasively through the Array API.
- Loading branch information
Showing
27 changed files
with
156 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ import Init.Omega | |
import Init.MacroTrace | ||
import Init.Grind | ||
import Init.While | ||
import Init.Syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/- | ||
Copyright (c) 2020 Microsoft Corporation. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura, Mario Carneiro | ||
-/ | ||
prelude | ||
import Init.Tactics | ||
|
||
|
||
/-- | ||
Set an element in an array, using a proof that the index is in bounds. | ||
(This proof can usually be omitted, and will be synthesized automatically.) | ||
This will perform the update destructively provided that `a` has a reference | ||
count of 1 when called. | ||
-/ | ||
@[extern "lean_array_fset"] | ||
def Array.set (a : Array α) (i : @& Nat) (v : α) (h : i < a.size := by get_elem_tactic) : | ||
Array α where | ||
toList := a.toList.set i v | ||
|
||
/-- | ||
Set an element in an array, or do nothing if the index is out of bounds. | ||
This will perform the update destructively provided that `a` has a reference | ||
count of 1 when called. | ||
-/ | ||
@[inline] def Array.setD (a : Array α) (i : Nat) (v : α) : Array α := | ||
dite (LT.lt i a.size) (fun h => a.set i v h) (fun _ => a) | ||
|
||
/-- | ||
Set an element in an array, or panic if the index is out of bounds. | ||
This will perform the update destructively provided that `a` has a reference | ||
count of 1 when called. | ||
-/ | ||
@[extern "lean_array_set"] | ||
def Array.set! (a : Array α) (i : @& Nat) (v : α) : Array α := | ||
Array.setD a i v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.