3
$\begingroup$

I must be really missing something here because I've tried many things on this link: How do I save a variable or function definition to a file? but still wind up with something I don't want.

I have the result of a Series[] in two variables - make it a 2-variable polynomial, and sometimes just in 1 variable, say after Normal[]... using lots of precision, and I just want to save it to a file. Probably to read it in as a string from some other CAS.

Here is the polynomial I want to save;

TTS1=(-0.34657359027997265470861606072908828403775006718012762706034000474669681098484735780293166349820934377100074051028534286684276011787906527851633537581753798096536378541418569709786639366446475311995426-1.9999490798225873499572186535290725617099781024250342978461246900114062916135862031311494298216788359006249994404123216579864511150983969490161617124987837951065839629188567278249007541299143473027478 I)-(0.18641996229708285664019542195162844152557130406065493942415050754616191610219506142664043523837521342618527451265129914941841203426621453002990620696452165988910080754419366560541724555730827002334490+0.18641996229708285664019542195162844152557130406065493942415050754616191610219506142664043523837521342618527451265129914941841203426621453002990620696452165989143183155666136047119166445360065082436613 I) z-0.26588364455577754348090978129132716009845740076065299883126903541384366310708798232669541746563085337518300682648903891865570730360470437702365000107735034401353697661862192348845205639197833788245609 z^2-(0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469-0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469 I) z^3+0.000016878155229425973095780772549030233822284389766731101331878465003339242174148267503208672460934188081480463152243208133618131381686152802553563490827662751725383080837475230558050753737488576769337110 I z^4-(0.00016650561926470379025798449604369899193727243947570661929808588090833801490129848285680886566375793695830246152948903282480912503814821642171672689810553673424625303745602311840088893307310570006163623+0.00016650561926470379025798449604369899193727243947570661929808588090833801490129848285680886566375793695830246152948903282480912503814821642171672689810553673424625303745602311840088893307310570006163623 I) z^5+0.00020308491043521559465865295222923710257051244891324458495816519792278243295873463948472573722626834384184009296308757297724769791116268809747745777071419981753080213186220936828375612773784196024495782 z^6+(0.000055294619424072340975195610046491338776710869687468728323233348159776171357676019454502685553232584571631717486388201423124049109793100001826105382199917499175165682343371960385953949879800113639434112-0.000055294619424072340975195610046491338776710869687468728323233348159776171357676019454502685553232584571631717486388201423124049109793100001826105382199917499175165682343371960385953949879800113639434112 I) z^7-(4.1261569538346143584328689320191196722119716469713230275553082299562702136360198271581039192105083043225905278727271542492834313480112463115381582153292424542104867928823904057747851783017568281830682*10^(-6)) I z^8-(2.1254377383626516676412973457778714909434290293713270782307095352312699172409851690570109560744473780587693716359669050441338545968762076677843204287118612354025122431341412138630690479407952065829547*10^(-6)+(2.1254377383626516676412973457778714909434290293713270782307095352312699172409851690570109560744473780587693716359669050441338545968762076677843204287118612354025122431341412138630690479407952065829547*10^(-6)) I) z^9-(3.7822162375954109440887189275369318108492336439574916783065406659156848323988332058502974503544726530081061943191654200778287608331813329959006731602965409911808926991985059367277399053684532711740481*10^(-6)) z^10-(8.5983832108788477827150480859358709937882153353880739829976159062251700367410840635203743849627487402573754685945696037290292336295205908758398424520966641756050939862380445889452780758532637667815036*10^(-7)-(8.5983832108788477827150480859358709937882153353880739829976159062251700367410840635203743849627487402573754685945696037290292336295205908758398424520966641756050939862380445889452780758532637667815036*10^(-7)) I) z^11+(1.9184319783579921697186170118547138688379429046295814158135884964808479158318678348981096919386366311915112379549262368436607351706405090471643436250089135774823419204919136386416075751571227159753904*10^(-7)) I z^12+(8.7244343353343759623554455456498978024200196019323903309836865578218466883810816226241849910478048003229412874345327091644247050688403069763088697859255233485341656769685546934390740957326899277203139*10^(-8)+(8.7244343353343759623554455456498978024200196019323903309836865578218466883810816226241849910478048003229412874345327091644247050688403069763088697859255233485341656769685546934390740957326899277203139*10^(-8)) I) z^13+(8.4984738269409529651687934136167331845313453526145549826060657962647074711379769383691005260767535292532297099203056954204848896805830542863715124636723604203892981495139904512077759207151274611049115*10^(-8)) z^14+(1.9699729746253592549459372704718870559926933481881540351216734447934892477166782082657355524642524181719239075223827794679017018614521063321990448467325023991749805290218573414862266648353837399451720*10^(-8)-(1.9699729746253592549459372704718870559926933481881540351216734447934892477166782082657355524642524181719239075223827794679017018614521063321990448467325023991521664679261818567976991756541021551415712*10^(-8)) I) z^15-(7.1392995876137563033258352970276180693417190824890041057379018239502241453909778284445040095853263273965290202005322983074495035805702781581945103512302616667950935003119235391525859945151409339549575*10^(-9)) I z^16+(5.2355669932939845794434943094345302739104737971966273415769898442312954877592111523378301140052886721866634915572771798866280828318206772786415250627993895042718502243078943985705391881569826960547370*10^(-11)-(4.3526046820588036607803637280334269304734314534514469297288104574041379082596346519284771990282862250419447462405966710523984256288223900854160939356875184003175819361312582526728899060967543317807913*10^(-10)) I) z^17

What I'd really like is something like what I see when I just do this to the polynomial;

Format[TTS1, TraditionalForm]

which gives output as (I had to copy as plain text to past this in here);

0.000016878155229425973095780772549030233822284389766731101331878465003339242174148267503208672460934188081480463152243208133618131381686152802553563490827662751725383080837475230558050753737488576769337110 I z^4-(0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469-0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469 I) z^3-0.26588364455577754348090978129132716009845740076065299883126903541384366310708798232669541746563085337518300682648903891865570730360470437702365000107735034401353697661862192348845205639197833788245609 z^2-(0.18641996229708285664019542195162844152557130406065493942415050754616191610219506142664043523837521342618527451265129914941841203426621453002990620696452165988910080754419366560541724555730827002334490+0.18641996229708285664019542195162844152557130406065493942415050754616191610219506142664043523837521342618527451265129914941841203426621453002990620696452165989143183155666136047119166445360065082436613 I) z-(0.34657359027997265470861606072908828403775006718012762706034000474669681098484735780293166349820934377100074051028534286684276011787906527851633537581753798096536378541418569709786639366446475311995426+1.9999490798225873499572186535290725617099781024250342978461246900114062916135862031311494298216788359006249994404123216579864511150983969490161617124987837951065839629188567278249007541299143473027478 I)

Thanks much!

PS Sorry, I would also like to exchange "I" with "%i".

UPDATE

For the replacement, I've got it working with this: Why can't I replace I with HoldPattern@I?

uno1 = TTS1 /. HoldPattern[Complex[r_, i_]] :> r + "%i"*i

as well as writing it to a file using;

uno2 = ToString[TraditionalForm[uno1]]
$NumberMarks = False
S = OpenWrite["filenames.txt", FormatType -> InputForm, 
  PageWidth -> Infinity]
Write[S,TraditionalForm[uno2]]
Close[S]

So the only problems (two) I have now are represented by what I copy & pasted from xed editor;

    (5.23556699329398457944349430943453027391047379719662734157698984423129548775\
92111523378301140052886721866634915572771798866280828318206772786415250627993\
89504271850224307894398570539188156982696054737`200.*^-11 - 
     4.3526046820588036607803637280334269304734314534514469297288104574041379\
08259634651928477199028286225041944746240596671052398425628822390085416093935\
                                                                    17
6875184003175819361312582526728899060967543317807913`200.*^-10 %i) z   - 
  7.1392995876137563033258352970276180693417190824890041057379018239502241453\
90977828444504009585326327396529020200532298307449503580570278158194510351230\
                                                               16
2616667950935003119235391525859945151409339549575`200.*^-9 %i z   

There's a funky `200 appended to the coefficients (200 was my MinPrecision=MaxPrecision=200).

This is now my only problem, as illustrated in this one-line copy and paste from xed.

(5.235566993293984579443494309434530273910473797196627341576989844231295487759211152337830114005288672186663491557277179886628082831820677278641525062799389504271850224307894398570539188156982696054737`200.*^-11 - 4.3526046820588036607803637280334269304734314534514469297288104574041379082596346519284771990282862250419447462405966710523984256288223900854160939356875184003175819361312582526728899060967543317807913`200.*^-10 %i) z   - 7.1392995876137563033258352970276180693417190824890041057379018239502241453909778284445040095853263273965290202005322983074495035805702781581945103512302616667950935003119235391525859945151409339549575`200.*^-9 %i z   + (1.969972974625359254945937270471887055992693348188154035121673444793489247716678208265735552464252418171923907522382779467901701861452106332199044846732502399174980529021857341486226664835383739945172`200.*^-8 - 1.9699729746253592549459372704718870559926933481881540351216734447934892477166782082657355524642524181719239075223827794679017018614521063321990448467325023991521664679261818567976991756541021551415712`200.*^-8 %i) z   + (8.7244343353343759623554455456498978024200196019323903309836865578218466883810816226241849910478048003229412874345327091644247050688403069763088697859255233485341656769685546934390740957326899277203139`200.*^-8 %i + 8.7244343353343759623554455456498978024200196019323903309836865578218466883810816226241849910478048003229412874345327091644247050688403069763088697859255233485341656769685546934390740957326899277203139`200.*^-8) z   + 1.9184319783579921697186170118547138688379429046295814158135884964808479158318678348981096919386366311915112379549262368436607351706405090471643436250089135774823419204919136386416075751571227159753904`200.*^-7 %i z   + (8.5983832108788477827150480859358709937882153353880739829976159062251700367410840635203743849627487402573754685945696037290292336295205908758398424520966641756050939862380445889452780758532637667815036`200.*^-7 %i - 8.5983832108788477827150480859358709937882153353880739829976159062251700367410840635203743849627487402573754685945696037290292336295205908758398424520966641756050939862380445889452780758532637667815036`200.*^-7) z   + (-2.1254377383626516676412973457778714909434290293713270782307095352312699172409851690570109560744473780587693716359669050441338545968762076677843204287118612354025122431341412138630690479407952065829547`200.*^-6 %i - 2.1254377383626516676412973457778714909434290293713270782307095352312699172409851690570109560744473780587693716359669050441338545968762076677843204287118612354025122431341412138630690479407952065829547`200.*^-6) z  - 4.1261569538346143584328689320191196722119716469713230275553082299562702136360198271581039192105083043225905278727271542492834313480112463115381582153292424542104867928823904057747851783017568281830682`200.*^-6 %i z  + (0.000055294619424072340975195610046491338776710869687468728323233348159776171357676019454502685553232584571631717486388201423124049109793100001826105382199917499175165682343371960385953949879800113639434112`200. - 0.000055294619424072340975195610046491338776710869687468728323233348159776171357676019454502685553232584571631717486388201423124049109793100001826105382199917499175165682343371960385953949879800113639434112`200. %i) z  + (-0.00016650561926470379025798449604369899193727243947570661929808588090833801490129848285680886566375793695830246152948903282480912503814821642171672689810553673424625303745602311840088893307310570006163623`200. %i - 0.00016650561926470379025798449604369899193727243947570661929808588090833801490129848285680886566375793695830246152948903282480912503814821642171672689810553673424625303745602311840088893307310570006163623`200.) z  + 0.00001687815522942597309578077254903023382228438976673110133187846500333924217414826750320867246093418808148046315224320813361813138168615280255356349082766275172538308083747523055805075373748857676933711`200. %i z  + (0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469`200. %i - 0.013066623626319121467421041046207715480445585376182576787342586780066233103752777078395574363432271257317302496021781272242800258555788041798328430904071975337286955829148251645241835855271003762633469`200.) z  + (-0.18641996229708285664019542195162844152557130406065493942415050754616191610219506142664043523837521342618527451265129914941841203426621453002990620696452165989143183155666136047119166445360065082436613`200. %i - 0.1864199622970828566401954219516284415255713040606549394241505075461619161021950614266404352383752134261852745126512991494184120342662145300299062069645216598891008075441936656054172455573082700233449`200.) z - 1.9999490798225873499572186535290725617099781024250342978461246900114062916135862031311494298216788359006249994404123216579864511150983969490161617124987837951065839629188567278249007541299143473027478`200. %i + 8.4984738269409529651687934136167331845313453526145549826060657962647074711379769383691005260767535292532297099203056954204848896805830542863715124636723604203892981495139904512077759207151274611049115`200.*^-8 z   - 3.7822162375954109440887189275369318108492336439574916783065406659156848323988332058502974503544726530081061943191654200778287608331813329959006731602965409911808926991985059367277399053684532711740481`200.*^-6 z   + 0.00020308491043521559465865295222923710257051244891324458495816519792278243295873463948472573722626834384184009296308757297724769791116268809747745777071419981753080213186220936828375612773784196024495782`200. z  - 0.26588364455577754348090978129132716009845740076065299883126903541384366310708798232669541746563085337518300682648903891865570730360470437702365000107735034401353697661862192348845205639197833788245609`200. z  - 0.34657359027997265470861606072908828403775006718012762706034000474669681098484735780293166349820934377100074051028534286684276011787906527851633537581753798096536378541418569709786639366446475311995426`200.TraditionalForm

I also notice now a weird .TraditionalForm on the end of the line...

$\endgroup$
  • $\begingroup$ Have you read the documentation pages on NumberMarks and PageWidth? $\endgroup$ – Mr.Wizard May 14 '17 at 0:08
  • $\begingroup$ Hmmmm... Only the first one, which when used with OpenWrite[] did not work for me... I put a $NumberMarks=False just before the OpenWrite[]... reference.wolfram.com/language/ref/$NumberMarks.html I'll check the other too $\endgroup$ – nate May 14 '17 at 0:10
  • $\begingroup$ I had in mind something like ToString[expr, InputForm, NumberMarks -> False, PageWidth -> Infinity]. How does that behave for you? $\endgroup$ – Mr.Wizard May 14 '17 at 0:20
  • $\begingroup$ Well the above gives out weird things with FormBox, RowBox, and pre- and post-appended, with escaped punctuation, all wrapped in double quotes. But putting that through to OpenWrite, Write, Close gives the same result I've been having - with the narrowness back too though. $\endgroup$ – nate May 14 '17 at 0:29
  • $\begingroup$ Would you please include the actual expression you wish to save, or a suitable example that exhibits the same behavior? $\endgroup$ – Mr.Wizard May 14 '17 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.