1

I want diophantine convert (t_0 ---> n)

from sympy import *
var('x y t_0 n')
def myDiophantine(myf):
    myf_diox = list(diophantine(myf))[0][0]
    myf_dioy = list(diophantine(myf))[0][1]
    print("#1#",type(myf_diox),myf_diox)
    myf_diox = myf_diox.subs({t_0:n})
    print("#2#",type(myf_diox),myf_diox)
    return myf_diox,myf_dioy
myf=5**4*x-2**4*y-1
print("#3#",myDiophantine(myf))

var('z')
print("#4#",type(myf),myf)
print("#5#",type(myf.subs({x:z})),myf.subs({x:z}))
#1# <class 'sympy.core.add.Add'> 16*t_0 + 1
#2# <class 'sympy.core.add.Add'> 16*t_0 + 1
#3# (16*t_0 + 1, 625*t_0 + 39)
#4# <class 'sympy.core.add.Add'> 625*x - 16*y - 1
#5# <class 'sympy.core.add.Add'> -16*y + 625*z - 1

i used subs? It could not be replaced. Is there a better way?

i want

#2# <class 'sympy.core.add.Add'> 16*n + 1

ref

I want function convert from xy to cells

20220401

from sympy import *
var('x y t_0 n')
def myDiophantine(myf):
    d=diophantine(myf)
    params = Tuple(*d).free_symbols - myf.free_symbols;
    d=Tuple(*d).xreplace(dict(zip(params, [n])))
    myf_diox = list(d)[0][0]
    myf_dioy = list(d)[0][1]
    return myf_diox,myf_dioy
myf=5**4*x-2**4*y-1
myg=myDiophantine(myf)
print("#",myg[0],myg[1])
# 16*n + 1 625*n + 39

https://www.wolframalpha.com/input?i=5%5E4*x-2%5E4*y%3D1

5^4x-2^4y=1

Integer solution

x = 16 n + 1, y = 625 n + 39, n element Z

mrrclb46z
  • 89
  • 6

1 Answers1

2
>>> myf = 5**4*x-2**4*y-1
>>> d = diophantine(myf)

Get a list of parameters that were used for the solution (converting set-of-tuples solution to Tuple-of-Tuples):

>>> params = Tuple(*d).free_symbols - myf.free_symbols; params
{t_0}

Create a replacement dictionary with desired replacements

>>> Tuple(*d).xreplace(dict(zip(params, [n])))
((16*n + 1, 625*n + 39),)

Why didn't your approach work?

>>> Symbol('t_0') in params
False
>>> Symbol('t_0',integer=True) in params
True

Symbols are matched based on name and assumptions, not name alone.

As to getting smaller coefficients for Diophantine equations: this is a known issue.

smichr
  • 16,948
  • 2
  • 27
  • 34