parse_integer()$ScanningUtilities with negative numbers

3 views
Skip to first unread message

Grégory Vanuxem

unread,
Jun 16, 2024, 1:43:33 PMJun 16
to fricas...@googlegroups.com
Hello,

Have you ever tried the function in object?
For negative integers it returns strange integers:

(1) -> parse_integer("-4")$ScanningUtilities

(1) - 26
Type: Integer
(2) -> parse_integer("4")$ScanningUtilities

(2) 4
Type: Integer

Apparently it is only used with 'ScanArabic' in outform.spad so it
does not have a lot of consequences. Grepping src/algebra:

src/algebra/outform.spad: ScanArabic s ==
qcoerce(parse_integer(s)$ScanningUtilities)

By the way, there exists the Lisp function parse-integer, although not
very satisfactory in the FriCAS sense.

It may not be what I have thought also.

- Greg

Waldek Hebisch

unread,
Jun 16, 2024, 2:05:24 PMJun 16
to fricas...@googlegroups.com
On Sun, Jun 16, 2024 at 07:42:54PM +0200, Grégory Vanuxem wrote:
> Hello,
>
> Have you ever tried the function in object?
> For negative integers it returns strange integers:
>
> (1) -> parse_integer("-4")$ScanningUtilities
>
> (1) - 26
> Type: Integer
> (2) -> parse_integer("4")$ScanningUtilities
>
> (2) 4
> Type: Integer

'parse_integer' is intended for nonnegative integers. Adding
handling for sign would be relatively easy. OTOH 'parse_integer'
assumes that it is given valid number (string of digits) and
will produce nonsense on invalid imput. To reiterate: idea
of 'parse_integer' is that lexical analyser verified correctness
of input and now task is to convert _valid_ input to a number.
For other uses we would need to add extra checks to
'parse_integer'.

> Apparently it is only used with 'ScanArabic' in outform.spad so it
> does not have a lot of consequences.

Note that 'ScanArabic' can only produce positive integers, so
valid input to 'ScanArabic' is also valid input to 'parse_integer'

> Grepping src/algebra:
>
> src/algebra/outform.spad: ScanArabic s ==
> qcoerce(parse_integer(s)$ScanningUtilities)
>
> By the way, there exists the Lisp function parse-integer, although not
> very satisfactory in the FriCAS sense.
>
> It may not be what I have thought also.

'parse_integer' is intended to be part of new FriCAS compiler and
interpreter. For large integers 'parse_integer' may be significantly
faster than Lisp 'PARSE-INTEGER', in fact slowness of 'PARSE-INTEGER'
was main motivation to develop 'parse_integer'.

--
Waldek Hebisch

Grégory Vanuxem

unread,
Jun 16, 2024, 2:46:52 PMJun 16
to fricas...@googlegroups.com
Ah ok, Thanks for the information. For non negative integers I suspected that.
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/Zm8pYbppoFIeJH4P%40fricas.org.
Reply all
Reply to author
Forward
0 new messages