Datasets:
Download level_1/52.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/52.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/52.rs
-
curl -L -o 52.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/52.rs
1.14 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| spec fn f1_is_ascii_digit_spec(c: char) -> bool { | |
| c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' | |
| || c == '8' || c == '9' | |
| } | |
| fn f1_is_ascii_digit(c: char) -> (r: bool) | |
| { | |
| c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' | |
| || c == '8' || c == '9' | |
| } | |
| spec fn f1_all_digits_spec(s: Seq<char>) -> bool { | |
| forall|i: nat| i < s.len() ==> f1_is_ascii_digit_spec(s[i as int]) | |
| } | |
| fn f1_all_digits(s: String) -> (result: bool) | |
| requires | |
| s.is_ascii(), | |
| { | |
| let mut i = 0; | |
| while i < s.as_str().unicode_len() | |
| { | |
| if !f1_is_ascii_digit(s.as_str().get_char(i)) { | |
| return false; | |
| } | |
| i = i + 1; | |
| } | |
| true | |
| } | |
| spec fn step1(__hp0: String, outp: bool) -> bool { | |
| (f1_all_digits_spec(__hp0@) == outp) | |
| } | |
| fn chain_driver(s: String) -> (r_final: bool) | |
| requires | |
| s.is_ascii(), | |
| ensures | |
| step1(s, r_final), | |
| { | |
| let x1 = f1_all_digits(s); | |
| proof { | |
| assert(step1(s, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |