Datasets:
Download level_10/12.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 10.4 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_10/12.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_10/12.rs
-
curl -L -o 12.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_10/12.rs
10.4 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_replace_blanks_with_chars(str1: &[u8], ch: u8) -> (result: Vec<u8>) | |
| { | |
| let mut out_str: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] == 32) { // 32 is ASCII Space as u8 | |
| out_str.push(ch); | |
| } else { | |
| out_str.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| out_str | |
| } | |
| // ASCII --> space=32, comma=44 , dot=46 , colon=58 | |
| spec fn f2_is_space_comma_dot_spec(c: u8) -> bool { | |
| (c == 32) || (c == 44) || (c == 46) | |
| } | |
| fn f2_replace_with_colon(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut result: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if ((str1[index] == 32) || (str1[index] == 44) || (str1[index] == 46)) { | |
| result.push(58); //ASCII -> colon=58 | |
| } else { | |
| result.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| result | |
| } | |
| spec fn f3_is_upper_case(c: u8) -> bool { | |
| c >= 65 && c <= 90 | |
| } | |
| spec fn f3_shift32_spec(c: u8) -> u8 { | |
| (c + 32) as u8 | |
| } | |
| spec fn f3_is_lower_case(c: u8) -> bool { | |
| c >= 97 && c <= 122 | |
| } | |
| spec fn f3_shift_minus_32_spec(c: u8) -> u8 { | |
| (c - 32) as u8 | |
| } | |
| spec fn f3_to_toggle_case_spec(s: u8) -> u8 { | |
| if f3_is_lower_case(s) { | |
| f3_shift_minus_32_spec(s) | |
| } else if f3_is_upper_case(s) { | |
| f3_shift32_spec(s) | |
| } else { | |
| s | |
| } | |
| } | |
| fn f3_to_toggle_case(str1: &[u8]) -> (toggle_case: Vec<u8>) | |
| { | |
| let mut toggle_case = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 97 && str1[index] <= 122) { | |
| toggle_case.push((str1[index] - 32) as u8); | |
| } else if (str1[index] >= 65 && str1[index] <= 90) { | |
| toggle_case.push((str1[index] + 32) as u8); | |
| } else { | |
| toggle_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| toggle_case | |
| } | |
| fn f4_replace_chars(str1: &[u8], old_char: u8, new_char: u8) -> (result: Vec<u8>) | |
| { | |
| let mut result_str = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if str1[index] == old_char { | |
| result_str.push(new_char); | |
| } else { | |
| result_str.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| result_str | |
| } | |
| // ASCII --> space=32, comma=44 , dot=46 , colon=58 | |
| spec fn f5_is_space_comma_dot_spec(c: u8) -> bool { | |
| (c == 32) || (c == 44) || (c == 46) | |
| } | |
| fn f5_replace_with_colon(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut result: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if ((str1[index] == 32) || (str1[index] == 44) || (str1[index] == 46)) { | |
| result.push(58); //ASCII -> colon=58 | |
| } else { | |
| result.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| result | |
| } | |
| spec fn f6_is_upper_case(c: u8) -> bool { | |
| c >= 65 && c <= 90 | |
| } | |
| spec fn f6_shift32_spec(c: u8) -> u8 { | |
| (c + 32) as u8 | |
| } | |
| spec fn f6_is_lower_case(c: u8) -> bool { | |
| c >= 97 && c <= 122 | |
| } | |
| spec fn f6_shift_minus_32_spec(c: u8) -> u8 { | |
| (c - 32) as u8 | |
| } | |
| spec fn f6_to_toggle_case_spec(s: u8) -> u8 { | |
| if f6_is_lower_case(s) { | |
| f6_shift_minus_32_spec(s) | |
| } else if f6_is_upper_case(s) { | |
| f6_shift32_spec(s) | |
| } else { | |
| s | |
| } | |
| } | |
| fn f6_to_toggle_case(str1: &[u8]) -> (toggle_case: Vec<u8>) | |
| { | |
| let mut toggle_case = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 97 && str1[index] <= 122) { | |
| toggle_case.push((str1[index] - 32) as u8); | |
| } else if (str1[index] >= 65 && str1[index] <= 90) { | |
| toggle_case.push((str1[index] + 32) as u8); | |
| } else { | |
| toggle_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| toggle_case | |
| } | |
| spec fn f7_is_lower_case(c: u8) -> bool { | |
| c >= 97 && c <= 122 | |
| } | |
| spec fn f7_shift_minus_32_spec(c: u8) -> u8 { | |
| (c - 32) as u8 | |
| } | |
| fn f7_to_uppercase(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut upper_case: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 97 && str1[index] <= 122) { | |
| upper_case.push((str1[index] - 32) as u8); | |
| } else { | |
| upper_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| upper_case | |
| } | |
| spec fn f8_is_upper_case(c: u8) -> bool { | |
| c >= 65 && c <= 90 | |
| } | |
| spec fn f8_shift32_spec(c: u8) -> u8 { | |
| (c + 32) as u8 | |
| } | |
| fn f8_to_lowercase(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut lower_case: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 65 && str1[index] <= 90) { | |
| lower_case.push((str1[index] + 32) as u8); | |
| } else { | |
| lower_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| lower_case | |
| } | |
| spec fn f9_is_lower_case(c: u8) -> bool { | |
| c >= 97 && c <= 122 | |
| } | |
| spec fn f9_shift_minus_32_spec(c: u8) -> u8 { | |
| (c - 32) as u8 | |
| } | |
| fn f9_to_uppercase(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut upper_case: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 97 && str1[index] <= 122) { | |
| upper_case.push((str1[index] - 32) as u8); | |
| } else { | |
| upper_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| upper_case | |
| } | |
| spec fn f10_is_upper_case(c: u8) -> bool { | |
| c >= 65 && c <= 90 | |
| } | |
| spec fn f10_shift32_spec(c: u8) -> u8 { | |
| (c + 32) as u8 | |
| } | |
| fn f10_to_lowercase(str1: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut lower_case: Vec<u8> = Vec::with_capacity(str1.len()); | |
| let mut index = 0; | |
| while index < str1.len() | |
| { | |
| if (str1[index] >= 65 && str1[index] <= 90) { | |
| lower_case.push((str1[index] + 32) as u8); | |
| } else { | |
| lower_case.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| lower_case | |
| } | |
| spec fn step1(__hp0: Seq<u8>, __hp1: u8, outp: Seq<u8>) -> bool { | |
| (__hp0.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < __hp0.len() ==> outp[i] == (if __hp0[i] == 32 { | |
| __hp1 | |
| } else { | |
| __hp0[i] | |
| })) | |
| } | |
| spec fn step2(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|k: int| | |
| 0 <= k < outp.len() ==> outp[k] == (if f2_is_space_comma_dot_spec(inp[k]) { | |
| 58 //ASCII -> colon=58 | |
| } else { | |
| inp[k] | |
| })) | |
| } | |
| spec fn step3(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> outp[i] == f3_to_toggle_case_spec( inp[i])) | |
| } | |
| spec fn step4(inp: Seq<u8>, p4_old_char: u8, p4_new_char: u8, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> outp[i] == (if inp[i] == p4_old_char { | |
| p4_new_char | |
| } else { | |
| inp[i] | |
| })) | |
| } | |
| spec fn step5(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|k: int| | |
| 0 <= k < outp.len() ==> outp[k] == (if f5_is_space_comma_dot_spec(inp[k]) { | |
| 58 //ASCII -> colon=58 | |
| } else { | |
| inp[k] | |
| })) | |
| } | |
| spec fn step6(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> outp[i] == f6_to_toggle_case_spec( inp[i])) | |
| } | |
| spec fn step7(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> (outp[i] == (if f7_is_lower_case( inp[i]) { | |
| f7_shift_minus_32_spec(inp[i]) | |
| } else { | |
| inp[i] | |
| }))) | |
| } | |
| spec fn step8(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> outp[i] == (if f8_is_upper_case( inp[i]) { | |
| f8_shift32_spec(inp[i]) | |
| } else { | |
| inp[i] | |
| })) | |
| } | |
| spec fn step9(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> (outp[i] == (if f9_is_lower_case( inp[i]) { | |
| f9_shift_minus_32_spec(inp[i]) | |
| } else { | |
| inp[i] | |
| }))) | |
| } | |
| spec fn step10(inp: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (inp.len() == outp.len()) | |
| && (forall|i: int| | |
| 0 <= i < inp.len() ==> outp[i] == (if f10_is_upper_case( inp[i]) { | |
| f10_shift32_spec(inp[i]) | |
| } else { | |
| inp[i] | |
| })) | |
| } | |
| fn chain_driver(str1: &[u8], ch: u8, p4_old_char: u8, p4_new_char: u8) -> (r_final: Vec<u8>) | |
| ensures | |
| exists|v1: Seq<u8>, v2: Seq<u8>, v3: Seq<u8>, v4: Seq<u8>, v5: Seq<u8>, v6: Seq<u8>, v7: Seq<u8>, v8: Seq<u8>, v9: Seq<u8>| step1(str1@, ch, v1) && step2(v1, v2) && step3(v2, v3) && step4(v3, p4_old_char, p4_new_char, v4) && step5(v4, v5) && step6(v5, v6) && step7(v6, v7) && step8(v7, v8) && step9(v8, v9) && step10(v9, r_final@), | |
| { | |
| let x1 = f1_replace_blanks_with_chars(str1, ch); | |
| let x2 = f2_replace_with_colon(x1.as_slice()); | |
| let x3 = f3_to_toggle_case(x2.as_slice()); | |
| let x4 = f4_replace_chars(x3.as_slice(), p4_old_char, p4_new_char); | |
| let x5 = f5_replace_with_colon(x4.as_slice()); | |
| let x6 = f6_to_toggle_case(x5.as_slice()); | |
| let x7 = f7_to_uppercase(x6.as_slice()); | |
| let x8 = f8_to_lowercase(x7.as_slice()); | |
| let x9 = f9_to_uppercase(x8.as_slice()); | |
| let x10 = f10_to_lowercase(x9.as_slice()); | |
| proof { | |
| assert(step1(str1@, ch, x1@)); | |
| assert(step2(x1@, x2@)); | |
| assert(step3(x2@, x3@)); | |
| assert(step4(x3@, p4_old_char, p4_new_char, x4@)); | |
| assert(step5(x4@, x5@)); | |
| assert(step6(x5@, x6@)); | |
| assert(step7(x6@, x7@)); | |
| assert(step8(x7@, x8@)); | |
| assert(step9(x8@, x9@)); | |
| assert(step10(x9@, x10@)); | |
| } | |
| x10 | |
| } | |
| } // verus! | |