Created
October 3, 2020 15:28
-
-
Save jchros/80e1b5ed09870e0941681f8fe976ac8f 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
fu! Bezout(lhs, rhs) abort | |
let r = [a:lhs, a:rhs] | |
let [u, v] = [[1, 0], [0, 1]] | |
while r[1] != 0 | |
let q = r[0] / r[1] | |
let r = [r[1], r[0] % r[1]] | |
let u = [u[1], u[0] - u[1] * q] | |
let v = [v[1], v[0] - v[1] * q] | |
endwhile | |
return #{ | |
\ coefs: [u[0], v[0]], | |
\ pgcd: r[0] | |
\ } | |
endfu | |
fu! GCD(lhs, rhs) abort | |
return Bezout(a:lhs, a:rhs).pgcd | |
endfu | |
fu! ShowBezoutOf(lhs, rhs) abort | |
const res = Bezout(a:lhs, a:rhs) | |
const coefs = res.coefs | |
const view = "Les coefficients de Bezout pour " . | |
\ a:lhs . " et " . a:rhs . " sont " . | |
\ coefs[0] . " et " . coefs[1] . ";" . | |
\ " leur PGCD est " . res.pgcd | |
call popup_notification(view, {}) | |
endfu | |
command! -nargs=+ CoefsBezout call ShowBezoutOf(<f-args>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment