On Thursday 03 April 2008 08:51, vgermrk wrote:
> Hi!  I want to hear your opinions about a little problem.
>
> The following bug is already reported as #2232:
> "1.digits(16,'0123456789abcdef')" returns "['1']"
> but "0.digits(16,'0123456789abcdef')" returns "[]"  (and not "['0']"
> as i wish)

Since I was the last person to touch the digits method, I'll state my case.  
Note that digits was (I think) inconsistent in this regard before my 
modifications -- I believe binary was different than other bases, but I don't 
recall which way.

I intentionally made 0.digits() return [] because that seems to me the most 
consistent mathematical thing to do.  To make 0.digits() return [0] seems 
inconsistent to me because we don't pad any other number with 0's to the 
left.  I'm sure that one could imagine use cases where you would really want 
either implementation for 0.digits().

Here's a feature I would like that you might like as well:
sage: #hypothetical code ahead
sage: 1.digits(padto=3)
[1, 0, 0]
sage: 0.digits(padto=1)
[0]
sage: 123456.digits(padto=5)  # padto is only a minimum
[6, 5, 4, 3, 2, 1]
In short, the 'padto' parameter would state the minimal length of the returned 
list and we would put sufficient zeros to make the list that length.  This 
would enable things like this (I suspect there's better ways to do this, but 
this is what I always think of when I want listings of power-set-like 
things):
sage: for i in srange(8): i.digits(base=2,padto=3)
[0, 0, 0]
[1, 0, 0]
[0, 1, 0]
[1, 1, 0]
[0, 0, 1]
[1, 0, 1]
[0, 1, 1]
[1, 1, 1]

So, the current returns are what occurs with padto=0.

--
Joel

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to