Skip to content

Instantly share code, notes, and snippets.

@foxqstm
Created August 9, 2021 09:11
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 foxqstm/e5c5950f663870771ba0cc3393eda1f0 to your computer and use it in GitHub Desktop.
Save foxqstm/e5c5950f663870771ba0cc3393eda1f0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['3/2']\n"
]
}
],
"source": [
"import sympy\n",
"\n",
"a=[2,-3,6,-11,1,3] #constant term is a[-1]\n",
"\n",
"pnl=sympy.ntheory.divisors(a[-1])\n",
"ml=sympy.ntheory.divisors(a[0])\n",
"\n",
"nl=[]\n",
"for div in pnl:\n",
" nl.append(div)\n",
" nl.append(-div)\n",
"\n",
"deg=len(a)-1\n",
"f=0\n",
"ans=[]\n",
"for n in nl:\n",
" for m in ml:\n",
" nd=n**deg\n",
" md=1\n",
" for c in a:\n",
" f+=nd*md*c\n",
" nd/=n\n",
" md*=m\n",
" if f==0:\n",
" ans.append((str(n)+'/'+str(m)))\n",
" f=0\n",
" \n",
"print(ans)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment