On 04/16/2011 11:46 PM, Prof. Dr. Johannes Grabmeier wrote:
Am 16.04.2011 um 23:03 schrieb Ralf Hemmecke:
On 04/16/2011 10:04 PM, Prof. Dr. Johannes Grabmeier wrote:
can anybody explain the meaning of the length function in Integer? I
thought that should be the length of the binary expansion, at least
for i>= 0:
Thank you for reporting.
I consider this a bug.
that is what I think as well, but I disagree with your "solution" to fix only
the documentation, not the bug on which we agree!
Just for comparison...
aldor -gloop
Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
Release: Aldor(C) version 1.1.0 (trunk-23 AXL_EDIT_1_1_13_18=0) for
LINUX(glibc2.3)
Type "#int help" for more details.
%1 >> #include "aldor"
%2 >> #include "aldorinterp"
%3 >> #include "aldorio"
%4 >> i: Integer := 0
0 @ AldorInteger
%5 >> length(i)
1 @ MachineInteger
%8 >> m:MachineInteger:=0
0 @ MachineInteger
%9 >> bit?(i,m)
F @ Boolean
%10 >> bit?(i,m-1)
F @ Boolean
%11 >> bit?(i,m+1)
F @ Boolean
So length(0)=1, but it doesn't match it's specification. :-(
https://svn.origo.ethz.ch/algebraist/trunk/aldor/lib/aldor/src/arith/sal_intcat.as
length: % -> Z;
#if ALDOC
\alpage{length}
\Usage{\name~a}
\Signature{\%}{\altype{MachineInteger}}
\Params{ {\em a} & \% & an integer\\ }
\Retval{Returns the number of binary bits of a, \ie n such that
\alexp{bit?}$(a, n-1)$ is \true and \alexp{bit?}$(a, m)$
is \false for $m \ge n$.}
#endif
At least, the implementation seems to be like you suggested.
%12 >> length(i+1)
1 @ MachineInteger
%13 >> length(i+2)
2 @ MachineInteger
%14 >> length(i-1)
1 @ MachineInteger
%15 >> length(i-2)
2 @ MachineInteger
I actually was suggesting to fix the documentation only, because of
speed. But I somehow agree, one would want a function that is useful for
the end user and not something that is easy to implement (i.e. just
directly relying on a similar LISP function).
Ralf
--
You received this message because you are subscribed to the Google Groups "FriCAS -
computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.