Skip to content

Commit ec55589

Browse files
authored
Include a couple of definitions in the README.md (#4)
Include the definitions of `is_char_boundary` and `floor_char_boundary` in the README.md file since the equivalence theorems refers to them. Also, update `is_char_boundary_def` to match the definition used in `RustString.lean`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 9ebeeda commit ec55589

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ In some cases, constructing a non-induction proof using the definitional version
106106
- For example, the function `is_char_boundary` has a definitional version:
107107

108108
```lean
109-
def is_char_boundary_def (s: Str) (p: Nat) := p(ListCharPos s ++ [byteSize s])
109+
def is_char_boundary_def (s: Str) (i: Nat) := i ∈ ListCharPos s ∨ i = byteSize s
110110
```
111111
112+
a recursive definition:
113+
114+
```lean
115+
def is_char_boundary (s: Str) (i: Nat) := match s with
116+
| [] => i == 0
117+
| h::t => if i = 0 then true else
118+
if i < Char.utf8Size h then false else is_char_boundary t (i - Char.utf8Size h)
119+
```
120+
121+
112122
and an equivalence theorem
113123
114124
```lean
@@ -142,7 +152,17 @@ then define the definitional version based on them.
142152
### When the Rust documentation describes properties of the return value
143153
We state and prove a soundness theorem for the function with
144154
name: `func_name_sound` and type: `x = func_name input1 input2 ... ↔ properties of x`.
145-
For example, the soundness theorem for the function `floor_char_boundary` is
155+
For example, the soundness theorem for the function `floor_char_boundary` defined as:
156+
157+
```lean
158+
def floor_char_boundary_aux (s: Str) (i: Nat) (k: Nat): Nat := match s with
159+
| [] => k
160+
| h::t => if i < Char.utf8Size h then k else floor_char_boundary_aux t (i - Char.utf8Size h) (k + Char.utf8Size h)
161+
162+
def floor_char_boundary (s: Str) (i: Nat) := floor_char_boundary_aux s i 0
163+
```
164+
165+
is
146166

147167
```lean
148168
theorem floor_char_boundary_sound: flp = floor_char_boundary s p

0 commit comments

Comments
 (0)