Mathematica 6.0 for Linux x86 (64-bit)
Copyright 1988-2008 Wolfram Research, Inc.

In[1]:= 
In[2]:= 
In[3]:= 
In[4]:= 
In[4]:= frankGenFun[x_] := -Log[(Exp[-alpha*x] - 1)/(Exp[-alpha] - 1)];

In[5]:= frankGenInv[s_] := -1/alpha*Log[1 + Exp[-s]*(Exp[-alpha] - 1)];

In[6]:= 
In[6]:= claytonGenFun[x_] := x^(-alpha) - 1;

In[7]:= claytonGenInv[s_] := (1 + s)^(-1/alpha);

In[8]:= 
In[8]:= gumbelGenFun[x_] := ( - Log[x] )^alpha;

In[9]:= gumbelGenInv[s_] := Exp[-s ^(1 / alpha)];

In[10]:= 
In[10]:= amhGenFun[x_] := Log[ (1 - alpha (1 - x) ) / x ];

In[11]:= amhGenInv[s_] := (1 - alpha) / (Exp[s] - alpha);

In[12]:= 
In[12]:= myD[f_, x_, n_] := Module[
  {df, i},
  df[0] = f; 
  For[i = 1, i <= n, i++,
      df[i] = Simplify[D[df[i - 1], x]];
      ];
  Table[df[i], {i, 1, n}]
  ];

In[13]:= 
In[13]:= uu = List[u1, u2, u3, u4, u5, u6, u7, u8, u9, u10];

In[14]:= 
In[14]:= mypdf[gfun_, ginv_, n_] := Module[
  {di, df, ss, part1, part2, val},
  di[s_] = Simplify[D[ginv[s], {s, n}]];
  df[u_] = Simplify[D[gfun[u], u]];
  ss = Sum[gfun[uu[[i]]], {i, 1, n}];
  part1 = Simplify[di[ss]];
  part2 = Simplify[Product[df[uu[[i]]], {i, 1, n}]];
  val = Simplify[part1 * part2];
  val
  ];

In[15]:= 
In[15]:= mycdf[gfun_, ginv_, n_] := Module[
  {ss},
  ss = Sum[gfun[uu[[i]]], {i, 1, n}];
  Simplify[ginv[ss]]
  ];

In[16]:= 
In[16]:= 
In[16]:= 
In[16]:= myGenExpr[GenFun_, GenInv_, n_, m_, cname_] := Module[
(* 
 n: The maximum dimension for the pdf expression (n = 1 is nuissance)
 m: The maximum dimension for pdfDer (m = 1 is nuissance)
*)						       
  {Cdf, CdfDerWrtArg, CdfDerWrtPar, 
   Pdf, PdfDerWrtArg, PdfDerWrtPar},
  Cdf = Table[mycdf[GenFun, GenInv, i], {i, 1, n}];
  Export[cname <> "Copula.cdf.expr", FortranForm /@ Cdf, "Table"];

  CdfDerWrtArg = Table[Simplify[D[Cdf[[i]], u1]], {i, 1, m}];
  Export[cname <> "Copula.cdfDerWrtArg.expr", FortranForm /@ CdfDerWrtArg, "Table"];
  CdfDerWrtPar = Table[Simplify[D[Cdf[[i]], alpha]], {i, 1, m}];
  Export[cname <> "Copula.cdfDerWrtPar.expr", FortranForm /@ CdfDerWrtPar, "Table"]; 

  Pdf = Table[mypdf[GenFun, GenInv, i], {i, 1, n}];
  Export[cname <> "Copula.pdf.expr", FortranForm /@ Pdf, "Table"];
(* 
 PdfDerWrtArg = Table[Simplify[Simplify[D[Pdf[[i]], u1]] / Pdf[[i]]], {i, 1, m}];
 *)
  PdfDerWrtArg = Table[Simplify[D[Pdf[[i]], u1]], {i, 1, m}];
  Export[cname <> "Copula.pdfDerWrtArg.expr", FortranForm /@ PdfDerWrtArg, "Table"];
(*
  PdfDerWrtPar = Table[Simplify[Simplify[D[Pdf[[i]], alpha]] / Pdf[[i]]], {i, 1, m}];
 *)
  PdfDerWrtPar = Table[Simplify[D[Pdf[[i]], alpha]], {i, 1, m}];
  Export[cname <> "Copula.pdfDerWrtPar.expr", FortranForm /@ PdfDerWrtPar, "Table"];  

  Export[cname <> "Copula.genfunDer.expr", FortranForm /@ myD[GenFun[u], u, 2], "Table"];
  True
  ];

In[17]:= 
In[17]:= 
In[17]:= myGenExpr[claytonGenFun, claytonGenInv, 10, 5, "clayton"];

In[18]:= myGenExpr[gumbelGenFun, gumbelGenInv, 10, 5, "gumbel"];

Simplify::time: 
   Time spent on a transformation exceeded 300
     seconds, and the transformation was aborted. Increasing the value of
     TimeConstraint option may improve the result of simplification.

Simplify::time: 
   Time spent on a transformation exceeded 300
     seconds, and the transformation was aborted. Increasing the value of
     TimeConstraint option may improve the result of simplification.

In[19]:= myGenExpr[frankGenFun, frankGenInv, 6, 4, "frank"];

In[20]:= myGenExpr[amhGenFun, amhGenInv, 2, 2, "amh"];

In[21]:= 
