You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
540 B

2 years ago
2 years ago
  1. load("number-theory.sage")
  2. #####
  3. # Chinese Remainder Theorem tests
  4. a_i = [5, 3, 10]
  5. m_i = [7, 11, 13]
  6. assert crt(a_i, m_i) == 894
  7. a_i = [3, 8]
  8. m_i = [13, 17]
  9. assert crt(a_i, m_i) == 42
  10. #####
  11. # gcd, using Binary Euclidean algorithm tests
  12. assert gcd(21, 12) == 3
  13. assert gcd(1_426_668_559_730, 810_653_094_756) == 1_417_082
  14. assert gcd_recursive(21, 12) == 3
  15. #####
  16. # Extended Euclidean algorithm tests
  17. assert egcd(7, 19) == (1, -8, 3)
  18. assert egcd_recursive(7, 19) == (1, -8, 3)
  19. #####
  20. # Inverse modulo N tests
  21. assert inv_mod(7, 19) == 11