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

SCM Repository

[diderot] View of /branches/ein16/synth/d2/obj_coeff.py
ViewVC logotype

View of /branches/ein16/synth/d2/obj_coeff.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4210 - (download) (as text) (annotate)
Thu Jul 14 18:01:19 2016 UTC (3 years, 8 months ago) by cchiw
File size: 2082 byte(s)
build on testing
import sys
import re
import os
from obj_apply import *
from obj_ty import *
from obj_operator import *
from obj_ex import *
from set import *
import random
import sympy
from sympy import *
#symbols
x,y,z =symbols('x y z')

#-------------------- Synthetic field --------------------
# coefficients for synthetic field
# a, b*x + c*y
# d*x*x, e*x*y,f*y*y
# g*y*x*x, h*x*y*y, i*x*x*y*y
def mk_coeffs(c):
    coeffs=[]
    def get_int():
        return random.randint(lcoeff, ucoeff)
    for i in range(c):
        coeffs.append(random.randint(lcoeff, ucoeff))
    return coeffs


def mk_multiple_coeffs(n):
    coeffs=[]
    for i in range(n):
        coeffs.append(mk_coeffs(9))
    return coeffs

#get coeffs
def get_coeffs(dim):
    if (dim==0): #tensor type
        return [random.randint(lcoeff, ucoeff),0,0,0,0,0,0,0,0]
    if (dim==1):
        return mk_coeffs(3)
    if (dim==2):
        return mk_coeffs(9)
    if (dim==3):
        return mk_multiple_coeffs(3)
    else:
        raise "dimension is not supported"

# unravel pack of coeffs
def toExp(coeff, zvalue):
    # digest coefficients
    #print "inside to exp coeff",coeff
    [a,b,c,d,e,f,g,h,i] = coeff
    # transform to expression
    t0 = b*x + c*y
    t1 = d*x*x + g*y*x*x
    t2 = f*y*y + h*x*y*y
    t3 = a + e*x*y + i*(y*y)*(x*x)
    exp = zvalue*(t0+t1+t2+t3)
    return exp

def coeffToExp(coeff, dim):
    #print "coeff",coeff
    #print "dim",dim
    if (dim==0):
        zvalue = 1 # no z is use
        return toExp(coeff, zvalue)
    elif (dim==1):
        [a,b,c]=coeff
        return a+b*x+c*x*x
    elif (dim==2):
        zvalue = 1 # no z is used
        return toExp(coeff, zvalue)
    elif(dim==3):
        #digest coefficients
        [z0,z1,z2]= coeff
        e0=toExp(z0, 1) # no z is used
        e1=toExp(z1, z) # multiply with one z
        e2=toExp(z2, z*z) #z^2
        exp = e0+e1+e2
        return exp
    else :
        raise "unsupported field dimension"

def mk_exp(dim):
    coeff1= get_coeffs(dim)
    exp1 = coeffToExp(coeff1, dim)
    # print "exp1",exp1
    return (coeff1,exp1)

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