Re: [fricas-devel] Re: A simple question

"Bill Page" <[email protected]>
Newsgroups gmane.comp.mathematics.axiom.user
Message-ID <[email protected]>
On 01 Feb 2008 22:59:26 +0100, Martin Rubey wrote:
>
>  Alasdair McAndrew writes:
>
> > Sorry about this; I'm a bit out of practice:
> >
> > for n in 10..30 repeat output [n, factor(2^n-1)]
>
> > This gives the first n in factored form which I don't want.
> >  How can I obtain the first n in unfactored form?
>
> ...
>  (8) -> for n in 10..13 repeat output([n, factor(2^n-1)]$List ANY)
>    [10,3 11 31]
>    [11,23 89]
>         2
>    [12,3 5 7 13]
>    [13,8191]
>                                                                    Type: Void
>
>  Just to make sure: what happens is that the interpreter sees
>  the list constructor [], and tries to find a Type as simple as
>  possible. List FR INT is simpler than List ANY.
>

Wow, the result of Alasdair's innocent command:

  for n in 10..30 repeat output [n, factor(2^n-1)]

is certainly obtuse! Even though I understand the cause as Martin
explains it, this still makes me smile :-)  - perhaps more with
embarrassment than anything else! I might have suggested another
solution:

   for n in 10..30 repeat output((n::String)." =", factor(2^n-1))

but really this is not much better and not so obvious. There should be
a better and more obvious way to do arbitrary output in Axiom - maybe
more like Aldor's << operator.

I think this is a little prettier:

(1) -> _<_< (x,y) == hconcat(x,y)$OutputForm
                                                              Type: Void

(2) -> for n in 10..30 repeat output(n << " = "::Symbol << factor(2^n-1))

   Compiling function << with type (PositiveInteger,Symbol) ->
      OutputForm

   Compiling function << with type (OutputForm,Factored Integer) ->
      OutputForm

   10 = 3 11 31
   11 = 23 89
         2
   12 = 3 5 7 13
...
   29 = 233 1103 2089
         2
   30 = 3 7 11 31 151 331
                                                                   Type: Void
(3) ->

Here, once the concept of << is understood, the only obscure notation
is probably

  " = "::Symbol

which is just a way to avoid printing the quotation marks " around the string.

Regards,
Bill Page.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.