Skip to content

Instantly share code, notes, and snippets.

@jchros
Created October 3, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchros/80e1b5ed09870e0941681f8fe976ac8f to your computer and use it in GitHub Desktop.
Save jchros/80e1b5ed09870e0941681f8fe976ac8f to your computer and use it in GitHub Desktop.
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