#Execute from command line as #python 'Csearch_writer.py' n mu1 d #in which n is replaced by the desired number of terms #and mu1,d are replaced by the eigenvalue and the degree #returns lower bound for C(mu1,d) #and spherical coordinates of Chebyshev coefficients for bound polynomial import sys args=sys.argv n=int(args[1]) mu1=args[2] d=args[3] f=open('searchprogram.py','w') f.write('from numpy import *\n') f.write('import copy\n') #Maxfunc f.write('def maxfunc(g,a,b,n):\n'+' if (g(a)>0 or g(b)>0):\n'+' return 0\n'+' N=int(5*(b-a))\n'+' M=4\n'+' iternum=3\n'+' deltax=(b-a)/N\n'+' Dnext=g(a+deltax/1000)-g(a)\n'+' index=[]\n'+' for i in range(1,N+1):\n'+' Dprev=Dnext\n'+' Dnext=g(a+deltax*(i+1.0/1000.0))-g(a+deltax*(i-1.0/1000.0))\n'+' val=a+(i-1)*deltax\n'+' if (g(val)>0):\n'+' return 0\n'+' if (Dprev >= 0 and Dnext < 0):\n'+' index.append(val)\n'+' count=0\n'+' while (count < iternum):\n'+' deltax=deltax/M\n'+' altindex=[]\n'+' for j in index:\n'+' Dnext=g(j+deltax/1000)-g(j)\n'+' for i in range(1,M+1):\n'+' Dprev=Dnext\n'+' Dnext=g(j+deltax*(i+1.0/1000.0))-g(j+deltax*(i-1.0/1000.0))\n'+' if (Dnext < 0):\n'+' altindex.append(j+(i-1)*deltax)\n'+' break\n'+' index=altindex\n'+' count +=1\n'+' value=max(g(a),g(b))\n'+' for i in index:\n'+' if (g(i)> value):\n'+' value=g(i)\n'+' return value\n') #Basis Polynomials f.write('def V0(x):\n') f.write(' return(1)\n') f.write('def V1(x):\n') f.write(' return(x)\n') for i in range(n-1): f.write('def V'+str(i+2)+'(x):\n') f.write(' return(x*V'+str(i+1)+'(x)-V'+str(i)+'(x))\n') #Coordinate TF f.write('def polyfloat(smaxarray):\n') for i in range(n-1): f.write(' theta'+str(i)+'=smaxarray['+str(i)+']\n') f.write(' core0=sin(theta0)\n') for i in range(n-3): f.write(' core'+str(i+1)+'=core'+str(i)+'*sin(theta'+str(i+1)+')\n') f.write(' c1=float(cos(theta0))\n') for i in range(n-2): f.write(' c'+str(i+2)+'=float(cos(theta'+str(i+1)+')*core'+str(i)+')\n') f.write(' c'+str(n)+'=float(sin(theta'+str(n-2)+')*core'+str(n-3)+')\n') f.write(' return([c1') for i in range(n-1): f.write(',c'+str(i+2)) f.write('])\n') #Calculate C f.write('def C(theta0') for i in range(n-2): f.write(',theta'+str(i+1)) f.write(',L,epsilon):\n') f.write(' coeff=polyfloat([theta0') for i in range(n-2): f.write(',theta'+str(i+1)) f.write('])\n') for i in range(n): f.write(' c'+str(i+1)+'=coeff['+str(i)+']\n') f.write(' def F(x):\n') f.write(' return(c1*V1(x)') for i in range(n-1): f.write('+c'+str(i+2)+'*V'+str(i+2)+'(x)') f.write(')\n') f.write(' if(F(2-epsilon)<0 and F(-L)searchresult['+str(n-1)+']):\n') f.write(' searchresult=copy.deepcopy(check)\n') f.write(' del check[-1]\n') f.write(' pti=copy.deepcopy(check)\n') f.write(' print(\'loop \'+str(i+1)+\'; arc error +/- \'+str(windr))\n'+' print(\'current maximum bound:\')\n'+' print(searchresult)\n'+' print(\'___________\')\n') f.write(' print(\'search complete:\')\n') f.write(' print(\'coefficients:\')\n') f.write(' print(polyfloat(pti))\n') f.write(' print(\'searchresult:\')\n') #f.write(' print(searchresult)\n') f.write(' return searchresult\n') f.write('res=msearch('+mu1+','+d+')\n') f.write('print(res)\n') f.write('print(\' C lower bound: \')\n') f.write('print res['+str(n-1)+']\n') f.close() execfile('searchprogram.py')