Created
February 6, 2024 22:47
-
-
Save mukeshtiwari/9eb81c4224a540dae77e22c660f82c0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| Section Gcd. | |
| Fixpoint gcd_rec (a b : nat) (acc : Acc lt b) {struct acc} : nat := | |
| match Nat.eq_dec b 0 with | |
| | left _ => a | |
| | right Ha => gcd_rec b (Nat.modulo a b) | |
| (Acc_inv acc (Nat.mod_upper_bound a b Ha)) | |
| end. | |
| Definition gcd (a b : nat) : nat. | |
| refine | |
| match b <=? a with | |
| | true => gcd_rec a b (lt_wf b) | |
| | _ => gcd_rec b a (lt_wf a) | |
| end. | |
| Defined. | |
| Eval compute in gcd 1 2. | |
| End Gcd. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment