Closed williamstein closed 16 years ago
Description changed:
---
+++
@@ -23,6 +23,8 @@
(x, y)
sage: solve_mod([x^2 + 2 == x, x^2 + y == y^2], 14)
[(2, 4), (6, 4), (9, 4), (13, 4)]
+ sage: solve_mod([x^2 == 1, 4*x == 11], 15)
+ [(14,)]
Fermat's equation modulo 3 with exponent 5:
sage: var('x,y,z')
@@ -41,11 +43,14 @@
"""
if not isinstance(eqns, (list, tuple)):
eqns = [eqns]
+ modulus = Integer(modulus)
+ if modulus < 1:
+ raise ValueError, "the modulus must be a positive integer"
vars = list(set(sum([list(e.variables()) for e in eqns], [])))
vars.sort()
n = len(vars)
R = Integers(modulus)
- S = PolynomialRing(R, vars)
+ S = MPolynomialRing(R, len(vars), vars)
eqns_mod = [S(eq) if is_SymbolicExpression(eq) else \
S(eq.lhs() - eq.rhs()) for eq in eqns]
ans = []
Attachment: trac-1500.patch.gz
This seems to be a good implementation for the toy cryptanalysis i want to play around with.
a,b = var('a,b')
solve_mod([4*a + b == 17,19*a + b == 3],26)
///
[(6, 19)]
I like the interface a little better than "Solve[{x^2 == 1, 4*x == 2, Modulus==10}, x, Mode->Modular]."
Looks good to me, is doctested, doesn't touch any existing code, so merge it.
Cheers,
Michael
Merged in 2.9.alpha7.
I've already had two requests just today to solve simple equations modulo n.
Here is code to be pasted into the notebook that can do it:
I'll incorporate this into sage as a patch in a moment.
Component: algebraic geometry
Issue created by migration from https://trac.sagemath.org/ticket/1500