如何在没有换行符的情况下打印到 GAP 中的文本文件?

How do you print to a text file in GAP without linebreaks?

最小工作示例:

x:=Indeterminate(Rationals,"x");
f:=Sum([1..1000],i->x^i);
PrintTo("~/temp.txt",f);

它向 temp.txt 打印以下内容:

x^1000+x^999+x^998+x^997+x^996+x^995+x^994+x^993+x^992+x^991+x^990+x^989+x^988\
+x^987+x^986+x^985+x^984+x^983+x^982+x^981+x^980+x^979+x^978+x^977+x^976+x^975\
+x^974+x^973+x^972+x^971+x^970+x^969+x^968+x^967+x^966+x^965+x^964+x^963+x^962\
+x^961+x^960+x^959+x^958+x^957+x^956+x^955+x^954+x^953+x^952+x^951+x^950+x^949\

[snip]

我怎样才能让它在文本文件中打印在一行上?

这是一个普遍的需求,解决方案称为SetPrintFormattingStatus。参见 its documentation online 或者只需在 GAP 提示中键入 ?SetPrintFormattingStatus 即可查看文档。

请注意,在这种情况下您将不得不使用流,它不起作用 直接使用文本文件。 OutputTextFile(紧接着记录 SetPrintFormattingStatus) 是你需要使用的。

在上面的例子中,使用

x:=Indeterminate(Rationals,"x");
f:=Sum([1..1000],i->x^i);
output := OutputTextFile( "poly", false );;
SetPrintFormattingStatus(output, false);
PrintTo(output,f);