write!(f, Integer)

9 views
Skip to first unread message

Sid Andal

unread,
Apr 12, 2022, 4:23:59 PM4/12/22
to FriCAS - computer algebra system

Is it possible to write integers with leading zeros into output files? The write! function seems to strip the leading zeros.

Thanks

Ralf Hemmecke

unread,
Apr 12, 2022, 5:04:28 PM4/12/22
to fricas...@googlegroups.com
> Is it possible to write integers with leading zeros into output files? The
> write! function seems to strip the leading zeros.

Ehm, I do not immediately see a method. But since that obviously does
not help you, can you help me in understanding what you are trying to
achieve? And it is maybe easiest if you do this simply with GNU tools
sed, awk and the like.

Maybe a little explanation if you type an integer with leading zeros
into FriCAS, then the leading zeroes are nowhere stored in FriCAS,
because an integer is (more or less) just a string of bits (0 or 1) with
leading digit 1 (except for the number 0). So if you want leading zeros
printed (what would be a reason?) you must write a function to do this
for you.

Ralf

Sid Andal

unread,
Apr 13, 2022, 12:03:19 PM4/13/22
to FriCAS - computer algebra system
The output file type is for Integers and each solution (hundreds of thousands of them) is tagged with a six-digit integer identifier for searching and analysis purposes. Leading zeros allow to distinguish these tags from other integers (the solutions). I was thinking about converting the tags with leading zeros into strings, but, then writing them out will be a problem since output file is of type Integer.

Ralf Hemmecke

unread,
Apr 13, 2022, 12:47:27 PM4/13/22
to fricas-devel
On 13.04.22 18:03, Sid Andal wrote:
> The output file type is for Integers and each solution (hundreds of
> thousands of them) is tagged with a six-digit integer identifier for
> searching and analysis purposes. Leading zeros allow to distinguish
> these tags from other integers (the solutions).

Are you sure you want a leading zero as a distinction of the different
types of solutions?

A little example of input/output would have been very helpful.

> I was thinking about converting the tags with leading zeros into
> strings, but, then writing them out will be a problem since output
> file is of type Integer.

Hmmm... first thing that comes to my mind is add 10^50 to your tags and
then rely on the fact that a "tag" number starts with "10". ;-)
Honestly, I find the File(S) feature rather lispy, anyway. It's
seamingly not really meant for communication with other programs, but
rather with writing out and reading back into FriCAS itself.

But, Kurt has another solution. You can use the function FORMAT from the
Lisp that is present underneath FriCAS. That is not a SPAD-only
solution, but for your purpose it would probably be the simplest way to
achieve your goal.

I leave it to Kurt to post the details.

Ralf

Kurt Pagani

unread,
Apr 13, 2022, 2:59:59 PM4/13/22
to FriCAS - computer algebra system
For instance,

FORMAT('NIL,"~12,'0d",123)$Lisp
 "000000000123"

s:=s.(1..#s-1)
s:=string FORMAT('NIL,"~0,20$",123)$Lisp
"00000000000000000123"

Reply all
Reply to author
Forward
0 new messages