output format

32 views
Skip to first unread message

Sid Andal

unread,
Jun 28, 2022, 2:30:44 PM6/28/22
to FriCAS - computer algebra system
Here's an example from the doc (book.pdf):


(1) -> x := solve ([[1 ,2 ,3] ,[2 ,3 ,4] ,[3 ,4 ,5]] ,[2 ,2 ,2])

   (1)  [particular = [- 2, 2, 0], basis = [[1, - 2, 1]]]
(2) -> T := typeOf x

   (2)
  Record(particular: Union(Vector(Fraction(Integer)),"failed"),basis: List(Vect
  or(Fraction(Integer))))
(3) -> f : File T := open("sols.out", "output")

   (3)  "sols.out"
(4) -> write!(f,x)

   (4)  [particular = [- 2, 2, 0], basis = [[1, - 2, 1]]]
(5) -> close! f

   (5)  "sols.out"
(6) ->


Here's the content of sols.out:

cat sols.out

((0 . #((-2 . 1) (2 . 1) (0 . 1))) #((1 . 1) (-2 . 1) (1 . 1)))


How do I get the file content look exactly as it appears on the screen:

[particular = [- 2, 2, 0], basis = [[1, - 2, 1]]]

as in line (4) above?

Thanks,
SWA

Ralf Hemmecke

unread,
Jun 28, 2022, 3:40:05 PM6/28/22
to fricas...@googlegroups.com
I would have said that this works...

Maybe not exactly what you want ...

http://fricas.github.io/faq.html#how-can-i-record-console-output

(9) -> )set message prompt none
)spool filename.txt

x

(9) [particular = [- 2, 2, 0], basis = [[1, - 2, 1]]]
Type: Record(particular:
Union(Vector(Fraction(Integer)),"failed"),basis:
List(Vector(Fraction(Integer))))
)spool )off

)set message prompt step

But strange, when I do this, I see only the input lines recorded.
Do we have a bug or is it just my system?

==================

You should forget about using "File(T)" for what you want. As you can
see File(T) only gives a Lisp-like output that you can read back into
FriCAS, but you want probably something else.

I am not completely sure about the "something else" might mean, but you
could do the following:

========
fn := filename("", "sols", "out")$FileName
f := open(fn, "output")$TextFile
x := solve ([[1 ,2 ,3] ,[2 ,3 ,4] ,[3 ,4 ,5]] ,[2 ,2 ,2])
for line in lines(formatExpression(x::OutputForm)$Format1D) repeat _
writeLine!(f,line))
close! f
========

Instead of Format1D you can also choose Format2D, FormatMathJax, or
FormatLaTeX.

Ralf


Reply all
Reply to author
Forward
0 new messages