| Karim Belabas on Wed, 10 Dec 2014 18:12:42 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: extremal case of component extraction |
* Bill Allombert [2013-05-20 17:08]:
> In PARI 2.6.0 we have:
>
> ? [1,2][2..-2]
> *** at top-level: [1,2][2..-2]
> *** ^------------
> *** _[_.._]: inconsistent dimensions in _[..].
>
> ? [1,2][2..1]
> *** at top-level: [1,2][2..1]
> *** ^-----------
> *** _[_.._]: inconsistent dimensions in _[..].
>
> I think a case could be made to return [] in both case.
>
> On the other hand
>
> ? [1,2][3..1]
>
> should probably fail.
OK. In v[a..b], assume a and b encode indices ia and ib, that is
* ia = a if a > 0,
* ia = #v+1 + a if a < 0.
Then v[a..b] would
- fail with e_DIM if either ia or ib is outside [1,#v]
- else return [] if ia > ib
- else return [v[ia], ..., v[ib]].
And similarly for matrices.
K.B.
P.S. In the above correspondence a --> ia, I didn't state what a = 0
encodes: it's undefined. It *should* raise an exception but the
implementation currently uses
v[0..b]
as an alias for
v[^b] \\ remove index=b entry
And
v[a..0]
as an alias for
[v[a]]
I'm not sure about the reason for the final one...
--
Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation http://www.math.u-bordeaux1.fr/~kbelabas/
F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP]
`