Download benchmarks/Algorithms/modular_power/lean/solution_annotated.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/modular_power/lean/solution_annotated.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/modular_power/lean/solution_annotated.c
-
curl -L -o solution_annotated.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/modular_power/lean/solution_annotated.c
1.18 kB
| /*@ Import Lean | |
| import Algorithms.modular_power.lean.helper_lib | |
| open scoped SimpleC | |
| */ | |
| /*@ Extern Coq | |
| (ModularPower : Z -> Z -> Z -> Z -> Prop) | |
| (ModularPowerProgress : Z -> Z -> Z -> Z -> Z -> Z -> Prop) | |
| */ | |
| int modular_power(int a, int b, int modulus) | |
| /*@ Require | |
| 0 <= a && a < modulus && | |
| 0 <= b && | |
| 2 <= modulus && modulus <= 46341 && emp | |
| Ensure | |
| 0 <= __return && __return < modulus && | |
| ModularPower(a, b, modulus, __return) && emp | |
| */ | |
| { | |
| int result = 1; | |
| /*@ Inv Assert | |
| 0 <= a@pre && a@pre < modulus@pre && | |
| 0 <= b@pre && | |
| modulus == modulus@pre && | |
| 2 <= modulus@pre && modulus@pre <= 46341 && | |
| 0 <= a && a < modulus@pre && | |
| 0 <= b && b <= b@pre && | |
| 0 <= result && result < modulus@pre && | |
| 0 <= a * a && a * a <= INT_MAX && | |
| 0 <= result * a && result * a <= INT_MAX && | |
| ModularPowerProgress(a@pre, b@pre, modulus@pre, | |
| a, b, result) && emp | |
| */ | |
| while (b > 0) { | |
| if (b % 2 == 1) { | |
| result = result * a % modulus; | |
| } | |
| a = a * a % modulus; | |
| b /= 2; | |
| } | |
| return result; | |
| } | |