Home My Page Projects Code Snippets Project Openings diderot
 Summary Activity Tracker Tasks SCM

# SCM Repository

[diderot] Diff of /branches/ein16/synth/d2/obj_coeff.py
 [diderot] / branches / ein16 / synth / d2 / obj_coeff.py # Diff of /branches/ein16/synth/d2/obj_coeff.py

revision 4455, Wed Aug 24 23:39:30 2016 UTC revision 4456, Thu Aug 25 04:03:27 2016 UTC
# Line 17  Line 17
17  # a, b*x + c*y  # a, b*x + c*y
18  # d*x*x, e*x*y,f*y*y  # d*x*x, e*x*y,f*y*y
19  # g*y*x*x, h*x*y*y, i*x*x*y*y  # g*y*x*x, h*x*y*y, i*x*x*y*y
20    zero = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
21  def mk_coeffs(c):  def mk_coeffs(c):
22      coeffs=[]      coeffs=[]
23
24      def get_int():      def get_int():
25          return random.randint(lcoeff, ucoeff)          return random.randint(lcoeff, ucoeff)
26      for i in range(c):      for i in range(c):
27          coeffs.append(random.randint(lcoeff, ucoeff))          coeffs.append(random.randint(lcoeff, ucoeff))
28  # return [random.randint(lcoeff, ucoeff),0,0,0,0,0,0,0,0]      #zero = [random.randint(lcoeff, ucoeff)]
29        #for i in range(c-1):
30        #    zero.append(0)
31        #return zero
32      return coeffs      return coeffs
33
34    def mk_CoeffSet():
35        if (coeff_style == coeff_cubic):
36            return mk_coeffs(16)
37        elif(coeff_style == coeff_quadratic):
38            return mk_coeffs(9)+[0, 0, 0, 0, 0, 0, 0]
39
40
41  def mk_multiple_coeffs(n):  def mk_multiple_coeffs(n):
42      coeffs=[]      coeffs=[]
# Line 48  Line 59
59          else:          else:
60              raise Exception("coeff style ", coeff_style, "unsupported")              raise Exception("coeff style ", coeff_style, "unsupported")
61      if (dim==2):      if (dim==2):
62          if (coeff_style == coeff_cubic):          return mk_CoeffSet()
return mk_coeffs(16)
elif(coeff_style == coeff_quadratic):
return mk_coeffs(9)+[0,0,0,0,0,0,0]
63      if (dim==3):      if (dim==3):
64          c = mk_coeffs(9)          coeffs=[]
65          return mk_multiple_coeffs(3)          for i in range(dim):
66          # print "get_coeffs c:",c              coeffs.append(mk_CoeffSet())
67          #c1= [0, 7,0,0,0,0,0,0,0]          return coeffs
68          #c2= [0, 0,0,0,0,0,0,0,0]          #return [coeffs,zero+,zero+]
#return [c,c2,c2]
69      else:      else:
70          raise "dimension is not supported"          raise "dimension is not supported"
71
72  # unravel pack of coeffs  # unravel pack of coeffs
73  def toExp_d2(coeff):  def toExp_cubic(coeff):
74      # digest coefficients      # digest coefficients
75      #print "inside to exp coeff",coeff      #print "inside to exp coeff",coeff
76        #print "len",len(coeff)
77      [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = coeff      [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = coeff
78      # transform to expression      # transform to expression
79      tA = a + b*y + c*x*y+ d*x;      tA = a + b*y + c*x*y+ d*x;
# Line 76  Line 84
84
85
86  # unravel pack of coeffs  # unravel pack of coeffs
87  def toExp(coeff, zvalue):  def toExp_quad(coeff, zvalue):
88      # digest coefficients      # digest coefficients
89      #print "inside to exp coeff",coeff      #print "inside to exp coeff",coeff
90      [a,b,c,d,e,f,g,h,i] = coeff      [a,b,c,d,e,f,g,h,i] = coeff
# Line 93  Line 101
101      #print "dim",dim      #print "dim",dim
102      if (dim==0):      if (dim==0):
103          zvalue = 1 # no z is use          zvalue = 1 # no z is use
104          return toExp(coeff, zvalue)          return toExp_quad(coeff, zvalue)
105      elif (dim==1):      elif (dim==1):
106          [a, b, c, d]=coeff          [a, b, c, d]=coeff
107          return a+b*x+c*x*x+d*x*x*x          return a+b*x+c*x*x+d*x*x*x
108      elif (dim==2):      elif (dim==2):
109          zvalue = 1 # no z is used          zvalue = 1 # no z is used
110          return toExp_d2(coeff)          return toExp_cubic(coeff)
111      elif(dim==3):      elif(dim==3):
112          #digest coefficients          #digest coefficients
113          [z0,z1,z2]= coeff          [z0,z1,z2]= coeff
114          e0=toExp(z0, 1) # no z is used          e0 = toExp_cubic(z0) # no z is used
115          e1=toExp(z1, z) # multiply with one z          e1 = toExp_cubic(z1) * z # multiply with one z
116          e2=toExp(z2, z*z) #z^2          e2 = toExp_cubic(z2) * z*z #z^2
117          exp = e0+e1+e2          exp = e0+e1+e2
118            #print "\n ******* exp\n e0:",e0,"\n e1:", e1,"\n e2:",e2
119          return exp          return exp
120      else :      else :
121          raise "unsupported field dimension"          raise "unsupported field dimension"

Legend:
 Removed from v.4455 changed lines Added in v.4456

 root@smlnj-gforge.cs.uchicago.edu ViewVC Help Powered by ViewVC 1.0.0