PerIntIt[str_String] := Module[{dum,OS}, OS = OpenWrite["fromMMA.txt"]; WriteString[OS,str]; Close[OS]; Run["rm -f toMMA.txt"]; Run["./perint7-dyn"]; OS = OpenRead["toMMA.txt"]; dum = Read[OS,String]; Close[OS]; Pari2Mma[dum] ] MakePariNumber[num_] := If[Im[num] == 0,Re[num],If[Re[num] == 0,I*Im[num],num]]; MakePariNumber[num_,pres_] := SetPrecision[If[Im[num] == 0,Re[num],If[Re[num] == 0,I*Im[num],num]]*(1+10^(-(pres+20))),pres+10] Mma2Pari[exp_] := MakeExactString[StringReplace[ToString[InputForm[exp]],{"PMod" -> "Mod","{" -> "[","}" -> "]","[" -> "(","]" -> ")"}]] (* This takes out the Mathematica 3.0 Precision and Accuracy indicators in numbers contained in ToString[InputForm'd expressions *) (* This should probably now (4.0) be replaced by using $NumberMarks ? *) MakeExactString[thestr_String] := Module[{str = thestr,pos,j}, While[(pos = StringPosition[str,{".`","0`","1`","2`","3`","4`","5`","6`","7`","8`","9`"}]) =!= {}, pos = pos[[1,1]]+1; If[StringTake[str,{pos+1}] === "`", j = pos+2, j = pos+1]; While[j <= StringLength[str] && MemberQ[{".","0","1","2","3","4","5","6","7","8","9"},StringTake[str,{j}]],j = j+1]; str = StringDrop[str,{pos,j-1}]]; StringReplace[str,{"*^" -> "*10^"}]] Pari2Mma[str_String] := ToExpression[ToMMaString[str]]; Pari2Mma[$Failed] = $Failed; (* This only works if the output from pari is in the format "e-1". E.g if the output function is brute(ans,'e',-1); *) ToMMaString[str_String] := Module[{msmbls,dum,outstr}, msmbls = {"{","{{","}","}}","},{"}; dum = replst[strpos[str,"["],strpos[str,"]"],strpos[str,";"]]; dum = Sort[Flatten[Table[Map[{#,i} &,dum[[i]]],{i,1,5}],1]]; If[dum == {},outstr = str, outstr = StringTake[str,{1,dum[[1,1]]-1}]; Do[ outstr = outstr <> msmbls[[dum[[i,2]]]] <> StringTake[str,{dum[[i,1]]+1,dum[[i+1,1]]-1}] ,{i,1,Length[dum]-1}]; outstr = outstr <> msmbls[[Last[dum][[2]]]] <> StringTake[str,{Last[dum][[1]]+1,StringLength[str]}]]; ToMMaNumbers[StringReplace[outstr,{"Mod"->"PMod","(" -> "[",")" -> "]"}]]] ToMMaNumbers[str_String] := Module[{DigitCount,DPoint,clst,dum,ans}, DigitCount = 0; DPoint = False; clst = {}; Do[ dum = StringTake[str,{i}]; If[MemberQ[{"0","1","2","3","4","5","6","7","8","9","."},dum], If[dum == ".", DPoint = True, DigitCount++], If[(DigitCount > 0) && DPoint, If[dum == "E", PrependTo[clst,{i,i+1,0}], PrependTo[clst,{i,i+2,DigitCount}]]]; DigitCount = 0; DPoint = False], {i,1,StringLength[str]}]; ans = str; Do[ ans = StringTake[ans,{1,clst[[i,1]]-1}]<>"`"<>ToString[clst[[i,3]]]<>"*^"<>StringTake[ans,{clst[[i,2]],StringLength[ans]}], {i,1,Length[clst]}]; ans ] (* This function returns a list of length 5. position 1: All positions where a [ should be replaced by a { position 2: All positions where a ] should be replaced by a {{ position 3: All positions where a [ should be replaced by a } position 4: All positions where a ] should be replaced by a }} position 5: All positions where a ; should be replaced by a },{ *) replst[opbrlst_,clbrlst_,sclst_] := Module[{dum}, dum = nextchar[{opbrlst,clbrlst,sclst},1]; If[dum[[1]] != 1, If[dum[[2]] == Infinity, {{},{},{},{},{}}, Print["Syntax error!"]], replst1[{opbrlst,clbrlst,sclst},dum[[2]]][[1]]]]; nextchar[lst_,n_] := Module[{dum}, dum = Min[Select[Apply[Join,lst],(# >= n) &]]; If[dum == Infinity, {Infinity,Infinity}, {Position[lst,dum][[1,1]],dum}]] replst1[lst_,n_] := Module[{olst = {{},{},{},{},{}},scpos = {},dum}, dum = nextchar[lst,n+1]; While[dum[[1]] != 2, If[dum[[1]] == 3, AppendTo[scpos,dum[[2]]]; dum = nextchar[lst,dum[[2]]+1], dum = replst1[lst,dum[[2]]]; olst = JF[olst,dum[[1]]]; dum = nextchar[lst,dum[[2]]+1]]]; If[Length[scpos] != 0, {JF[olst,{{},{n},{},{dum[[2]]},scpos}],dum[[2]]}, {JF[olst,{{n},{},{dum[[2]]},{},{}}],dum[[2]]}]] JF[lst1_,lst2_] := Table[Join[lst1[[i]],lst2[[i]]],{i,1,5}] strpos[str_,char_] := Module[{dum}, dum = StringPosition[str,char]; If[dum == {},dum,Transpose[dum][[1]]]]; ToPariMatrix[mat_] := Module[{str}, str = "["; Do[ Do[ str = str <> Mma2Pari[mat[[i,j]]] <> ",", {j,1,Length[mat[[1]]]}]; str = StringDrop[str,-1] <> ";", {i,1,Length[mat]}]; StringDrop[str,-1]<>"]"]