=================================================================== RCS file: /home/cvs/OpenXM/src/asir-contrib/packages/src/tk_fd.rr,v retrieving revision 1.3 retrieving revision 1.6 diff -u -p -r1.3 -r1.6 --- OpenXM/src/asir-contrib/packages/src/tk_fd.rr 2014/06/29 00:53:37 1.3 +++ OpenXM/src/asir-contrib/packages/src/tk_fd.rr 2014/08/09 09:27:48 1.6 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/asir-contrib/packages/src/tk_fd.rr,v 1.2 2014/06/04 23:44:17 takayama Exp $ */ +/* $OpenXM: OpenXM/src/asir-contrib/packages/src/tk_fd.rr,v 1.5 2014/07/19 01:49:31 takayama Exp $ */ /* 2015.05.23 h-mle/FD/Prog/fdpf.rr --> tk_fd.rr */ @@ -145,6 +145,28 @@ localf ygdmat_abc$ localf ygfvect_poly$ localf ygahvec$ localf ygtry15$ +localf marginal2abc$ +localf abc2marginal$ +localf ygQmat$ +localf fdA$ +localf hgpoly_fd$ +localf hgpoly_fd_beta$ +localf check21$ +localf checkahg$ +localf abc2alpha$ +localf ygNmat2$ +localf ygCmat2$ +localf ygRmat2$ +localf ygQmat2$ +localf beta2marginal$ +localf beta2abc$ +localf atofd$ +localf atofd_beta$ +localf check22$ +localf checkfd$ +localf ygDk$ +localf containNegative$ +localf check23$ #endif /* Matsumoto, page 3 */ @@ -1408,21 +1430,27 @@ def fdah_poly(A,B,C,Y) { 2014.05.15 */ /*&usage begin: - ahvec(A,B,C,Y | norecc=y, approx=n) - It returns [F,Gamma]. F*Gamma is equal to + ahvec(A,B,C,Y | norecc=n, approx=n) + It returns R=[F,Gamma]. F*Gamma is equal to (dy_21 Z, dy_22 Z, ..., dy_2p Z) at y = Y where p = length(B)+1. y = [[y_11,y_12, ..., y_1p],[y_21,y_22,...,y_2p]]. y_2* must not be 0. + When the option all=1, R[2]*R[1] is Z (normalizing constant or hg polynomial). example: A=-3; B=[-2,-5]; C=2; Yval=[[1,1/2,1/3],[1,1,1]]; ahvec(A,B,C,Yval); + example: + F=ahvec(-1,[-2],3,[[x11,x12],[x21,x22]] | all=1); + red(F[2]*F[1]); + returns hg polynomial sum(x^u/u!) (where Au=Beta). end: */ def ahvec(A,B,C,Y) { Opt=getopt(); if (type(getopt(norecc)) >0) UseRecc=0; else UseRecc=1; + if (type(getopt(all)) > 0) All=1; else All=0; M = length(B); E = newmat(2,M+1); E[0][0] = -A; E[1][0] = C-1; @@ -1448,6 +1476,7 @@ def ahvec(A,B,C,Y) { Y2j1 = Y[1][J]; E2j1 = E[1][J]; Ahvec[J] = (-Fd[J]+E2j1*Fd[0])*Ye/Y2j1; } + if (All) { Zvalue=Ye*F[0];} NoGamma = getopt(nogamma); if (type(NoGamma)<0) NoGamma=0; @@ -1460,7 +1489,9 @@ def ahvec(A,B,C,Y) { Gamma=Gamma*tk_number_invgamma(-B[I]+1); } } - return [vtol(Ahvec),Gamma]; + R=[vtol(Ahvec),Gamma]; + if (All) return append(R,[Zvalue]); + else return R; } def check17() { A=-3; @@ -1864,7 +1895,9 @@ def ah_init_value(A,B,C,Y) { return [Amat,V,BRule,0,Val,0,Base,Fexact]; } -/* 2014.06.23. Ref: @s/2014/06/24-intersection-sabun.pdf by Y.Goto , 25-my-note-fdpf-yg-funcs.pdf */ +/* 2014.06.23. Ref: @s/2014/06/24-intersection-sabun.pdf by Y.Goto , 25-my-note-fdpf-yg-funcs.pdf + 2014/07/14-fdpf-memo-ygfuncs.pdf mynote in goto's note with yg-function names. +*/ def ygNmat() { N=newmat(MM+1,MM+1); for (I=0; I0) UseRecc=0; else UseRecc=1; + if (type(getopt(all)) > 0) All=1; else All=0; M = length(B); E = newmat(2,M+1); E[0][0] = -A; E[1][0] = C-1; @@ -1972,6 +2006,7 @@ def ygahvec(A,B,C,Y) { Y2j1 = Y[1][J]; E2j1 = E[1][J]; Ahvec[J] = (-Fd[J]+E2j1*Fd[0])*Ye/Y2j1; } + if (All) { Zvalue=Ye*F[0];} NoGamma = getopt(nogamma); if (type(NoGamma)<0) NoGamma=0; @@ -1984,7 +2019,9 @@ def ygahvec(A,B,C,Y) { Gamma=Gamma*tk_number_invgamma(-B[I]+1); } } - return [vtol(Ahvec),Gamma]; + R= [vtol(Ahvec),Gamma]; + if (All) return append(R,[Zvalue]); + else return R; } @@ -2007,6 +2044,342 @@ def ygtry15(M) { T=Fam - base_replace(Dmat,[[a,Aval]])*Fa; printf("If %a is not zero vector , then there is an error.\n",T); return Dmat; +} + + +/* cf. fdah() */ +def marginal2abc(RSum,CSum) { + if (length(RSum) != 2) error("length of RSum must be 2."); + Size = length(CSum); + CSum=newvect(Size,CSum); + S = RSum[0]+RSum[1]; + if (S != base_sum(CSum,0,0,Size-1)) { + T=S-base_sum(CSum,0,0,Size-2); + printf("Warning. RSum != CSum. The last value of CSum is changed from %a to %a.\n",CSum[Size-1],T); + CSum[Size-1] = T; + if (T < 0) error("Changed value is negative."); + } + CSum = vtol(CSum); + B=vtol(-newvect(Size-1,cdr(CSum))); + C=RSum[1] + 1 + base_sum(B,0,0,Size-2); + A=-RSum[0]; + if (C < 0) printf("Warning: C=%a is negative. Exchange columns so that a big value comes to the first and Exchange rows so that a big value come to the second. \n",C); + return [A,B,C]; + +} +def abc2marginal(A,B,C) { + R2=C-1-base_sum(B,0,0,length(B)-1); + R1=-A; + RSum=[R1,R2]; + C1=-A+C-1; + CSum = -newvect(length(B),B); + CSum = cons(-A+C-1,vtol(CSum)); + return [RSum,CSum]; +} +// check20 in A-hg/Prog/hgpoly.rr + +def ygQmat(X,K) { + return ygRmat(X,K); /* Implement without global variables. */ +} + +/* 2014.08.03 from hgpoly.rr, should use hgpoly.rr with deg=... + 2 x (M+1) +*/ +def fdA(M) { + A = newmat(M+1+1,2*(M+1)); + for (I=0; I=0) Deg=eval_str(rtostr(getopt(deg))); + if (type(A) == 4) A=matrix_list_to_matrix(A); + D=size(A)[0]; + N=size(A)[1]; + Ap = matrix_transpose(A); + F=0; + Vx=[]; + for (I=0; I=1 */ + F = F+util_v(x,[I+1])*Mon; + Vx = cons(util_v(x,[I+1]),Vx); + } + Vx=reverse(Vx); + /* print(print_input_form(poly_sort(F))); */ + Fall = 1; + for (I=1; I<=Deg; I++) { + Fall += F^I; /* deg_1(each term of F^p) >= p */ + } + // printf("Fall=%a\n",Fall); + P = coef(Fall,B[0],util_v(t,[1])); + for (I=1; I R=%a\n",R); + return(G); +} + +/* 2014.08.05. Does F satisfy the system of equations for F_D? */ +def checkfd(F,A,B,C,V) { + M = length(B); + DV = []; + for (I=0; I=4) { + for (I=0; I (-B[0]) in case of C>0*/ + Fvec2=newvect(M+1); + Fvec2[0] = F2; + for (I=1; I<=M; I++) Fvec2[I] = ((V[I-1]-1)/Alp2[I])*diff(F2,V[I-1]); + R=map(red,Fvec2-(1/(-B[0]+1))*ygDk(V,1,A,B,C)*Fvec); + return R; } #if !USE_MODULE