Aleksej Saushev | 1 Feb 17:29
Picon

Re: Pre-Release Checklist for v5.2.1, second call

  Hello!

Aleksej Saushev <asau@...> writes:

> I'm testing racket-5.2.0.901 on NetBSD 5.99.59 i386.
>
> After applying patch as attached

Will the patch be applied at least to trunk?
It would be nice to have it applied to (pre)release branch too,
or is it too late?

--

-- 
HE CE3OH...

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Neil Toronto | 1 Feb 17:58
Picon
Gravatar

Re: [plt] Push #24227: master branch updated

On 02/01/2012 09:55 AM, ntoronto <at> racket-lang.org wrote:
> ntoronto has updated `master' from e4b1ef1b6e to 950f034936.
> ~~~~~~~~~~
> | Pushing unfinished but stable flomap transforms so Matthew can debug a segfault
> :
>    M collects/images/icons/misc.rkt               |  123 ++++++++++++++++++++++-
>    M collects/images/logos.rkt                    |  124 ++++++++++++++++++++++-
>    M collects/images/private/flomap-transform.rkt |   75 ++++++++++++++-

Just so nobody freaks out: the segfault is not in the code I pushed. 
It's in a file on my hard drive outside of the collects.

Neil ⊥
_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Ryan Culpepper | 1 Feb 18:10
Picon
Favicon

Re: [plt] Push #24227: master branch updated

On 02/01/2012 09:55 AM, ntoronto@... wrote:
> collects/unstable/contract.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/unstable/contract.rkt
> +++ NEW/collects/unstable/contract.rkt
> @@ -171,6 +171,14 @@
>                    (lambda (idx . elems) #t)))))))
>        sequence?)))
>
> +;; Added by ntoronto
> +
> +(define contract/c (or/c contract? (any/c . ->  . any/c)))
> +
> +(define (treeof elem-contract)
> +  (or/c elem-contract
> +        (listof (recursive-contract (treeof elem-contract) #:flat))))

'contract/c' is not useful: 'contract?' already recognizes predicates, 
and due to the way 'or/c' handles mixed flat and higher-order contracts, 
the arrow contract's checks *never apply*.

 > (contract? even?)
#t

 > (define/contract ev (or/c contract? (-> any/c any/c)) even?)
 > (ev 5 6 7) ;; You might think this would be a contract error... nope!
even?: expects 1 argument, given 3: 5 6 7

 > (define/contract vv (or/c contract? (-> any/c any/c)) vector->values)
 > (vv '#(1 2 3)) ;; Likewise... but not a contract error.
(Continue reading)

Neil Toronto | 1 Feb 18:12
Picon
Gravatar

Re: [plt] Push #24227: master branch updated

On 02/01/2012 10:10 AM, Ryan Culpepper wrote:
> On 02/01/2012 09:55 AM, ntoronto@... wrote:
>> collects/unstable/contract.rkt
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> --- OLD/collects/unstable/contract.rkt
>> +++ NEW/collects/unstable/contract.rkt
>> @@ -171,6 +171,14 @@
>> (lambda (idx . elems) #t)))))))
>> sequence?)))
>>
>> +;; Added by ntoronto
>> +
>> +(define contract/c (or/c contract? (any/c . -> . any/c)))
>> +
>> +(define (treeof elem-contract)
>> + (or/c elem-contract
>> + (listof (recursive-contract (treeof elem-contract) #:flat))))
>
> 'contract/c' is not useful: 'contract?' already recognizes predicates,
> and due to the way 'or/c' handles mixed flat and higher-order contracts,
> the arrow contract's checks *never apply*.
>
>  > (contract? even?)
> #t
>
>  > (define/contract ev (or/c contract? (-> any/c any/c)) even?)
>  > (ev 5 6 7) ;; You might think this would be a contract error... nope!
> even?: expects 1 argument, given 3: 5 6 7
>
>  > (define/contract vv (or/c contract? (-> any/c any/c)) vector->values)
(Continue reading)

John Boyle | 2 Feb 01:58
Picon

floor-log/base, ceiling-log/base, from Neil Toronto's recent commit

I happened to observe this commit from today by Neil Toronto:

http://git.racket-lang.org/plt/commitdiff/47fcdd4916a2d33ee5c28eb833397ce1d2a515e2

I may have some useful input on this, having dealt with similar problems myself.

The problem: Given b and x, you want to find the largest integer n such that b^n <= x (or, for the ceiling problem, the smallest integer n such that b^n ≥ x).  This can profitably be viewed as a case of a more general problem: given a monotonically increasing but otherwise opaque function f, find the largest integer n such that f(n) ≤ x.  The previous algorithm to solve this can now be viewed as a linear search, taking n steps.  This took too long, and Neil Toronto replaced it with an algorithm that depended on floating-point numbers; but I hate to see that happen, because floats will screw up when the numbers get too large; careful reasoning may prove that floats will be sufficiently accurate for a given application, but it would be nice to have an exact algorithm so that one didn't have to do that.

I come here to present such an algorithm.  Simply put: Use a binary search rather than a linear search.  How do we do binary search on "the nonnegative integers"?  Well, start with 0 and 1 as your bounds, and keep doubling the 1 until you get something that's actually too high; then you have a real lower and upper bound.  This will take log(n) steps to find the upper bound, and then a further log(n) steps to tighten the bounds to a single integer.  Thus, this takes roughly 2*log(n) steps, where each step involves calculating (expt b n) plus a comparison.  It might be possible to do slightly better by not treating b^n as a black box (e.g. by using old results of b^n to compute new ones rather than calling "expt" from scratch, or by using "integer-length" plus some arithmetic to get some good initial bounds), but I suspect this is good enough and further complexity is not worth it.

Note that this algorithm should work perfectly with any nonnegative rational arguments [other than 0 for b or x, and 1 for b], and should give as good an answer as any with floating-point arguments.  Also, "integer-finverse", as I called it, might be useful for many other "floor"-type computations with exact numbers (I have so used it myself in an ad hoc Arc math library).

;Finds n such that n >= 0 and f(n) <= x < f(n+1) in about 2*log(n) steps.
;Assumes f is monotonically increasing.
(define (integer-finverse f x)
  (define upper-bound
    (let loop ((n 1))
      (if (> (f n) x)
          n
          (loop (* n 2)))))
  (define (search a b) ;b is too big, a is not too big
    (let ((d (- b a)))
      (if (= d 1)
          a
          (let ((m (+ a (quotient d 2))))
            (if (> (f m) x)
                (search a m)
                (search m b))))))
  (search (quotient upper-bound 2) upper-bound))

(define (floor-log/base b x)
  (cond ((< b 1) (- (ceiling-log/base (/ b) x)))
        ((= b 1) (error "Base shouldn't be 1."))
        ((< x 1) (- (ceiling-log/base b (/ x))))
        (else (integer-finverse (lambda (n) (expt b n)) x))))

(define (ceiling-log/base b x)
  (cond ((< b 1) (- (floor-log/base (/ b) x)))
        ((= b 1) (error "Base shouldn't be 1."))
        ((< x 1) (- (floor-log/base b (/ x))))
        (else
         (let ((u (floor-log/base b x)))
           (if (= x (expt b u))
               u
               (+ u 1))))))


Testing:

> (floor-log/base 10 3)
0
> (floor-log/base 3 10)
2
> (ceiling-log/base 3 10)
3
> (ceiling-log/base 1/3 10)
-2
> (floor-log/base 1/3 10)
-3
> (floor-log/base 2/3 10)
-6
> (ceiling-log/base 2/3 10)
-5
> (exact->inexact (expt 3/2 6))
11.390625
> (exact->inexact (expt 3/2 5))
7.59375

I might add, by the way, that I'm inclined to expect the base to be a second, optional argument (perhaps defaulting to 10) to a function called simply "floor-log" or "ceiling-log".  I don't know if that fits with desired conventions, though.
--John Boyle

Science is what we understand well enough to explain to a computer. Art is everything else we do. --Knuth

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Robby Findler | 2 Feb 03:10

Re: Pre-Release Checklist for v5.2.1, second call

Hi. Sorry-- we didn't get that in time to make it into the release,
but I've just pushed it to master. Thanks for the reminder.

Robby

On Wed, Feb 1, 2012 at 10:29 AM, Aleksej Saushev <asau <at> inbox.ru> wrote:
>  Hello!
>
> Aleksej Saushev <asau <at> inbox.ru> writes:
>
>> I'm testing racket-5.2.0.901 on NetBSD 5.99.59 i386.
>>
>> After applying patch as attached
>
> Will the patch be applied at least to trunk?
> It would be nice to have it applied to (pre)release branch too,
> or is it too late?
>
>
> --
> HE CE3OH...
>
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Neil Toronto | 2 Feb 05:10
Picon
Gravatar

Re: floor-log/base, ceiling-log/base, from Neil Toronto's recent commit

On 02/01/2012 05:58 PM, John Boyle wrote:
> I happened to observe this commit from today by Neil Toronto:
>
> http://git.racket-lang.org/plt/commitdiff/47fcdd4916a2d33ee5c28eb833397ce1d2a515e2
>
> I may have some useful input on this, having dealt with similar problems
> myself.
>
> The problem: Given b and x, you want to find the largest integer n such
> that b^n <= x (or, for the ceiling problem, the smallest integer n such
> that b^n ≥ x).  This can profitably be viewed as a case of a more
> general problem: given a monotonically increasing but otherwise opaque
> function f, find the largest integer n such that f(n) ≤ x.  The previous
> algorithm to solve this can now be viewed as a linear search, taking n
> steps.  This took too long, and Neil Toronto replaced it with an
> algorithm that depended on floating-point numbers; but I hate to see
> that happen, because floats will screw up when the numbers get too
> large; careful reasoning may prove that floats will be sufficiently
> accurate for a given application, but it would be nice to have an exact
> algorithm so that one didn't have to do that.
>
> I come here to present such an algorithm.  Simply put: Use a binary
> search rather than a linear search.  How do we do binary search on "the
> nonnegative integers"?  Well, start with 0 and 1 as your bounds, and
> keep doubling the 1 until you get something that's actually too high;
> then you have a real lower and upper bound.  This will take log(n) steps
> to find the upper bound, and then a further log(n) steps to tighten the
> bounds to a single integer.  Thus, this takes roughly 2*log(n) steps,
> where each step involves calculating (expt b n) plus a comparison.  It
> might be possible to do slightly better by not treating b^n as a black
> box (e.g. by using old results of b^n to compute new ones rather than
> calling "expt" from scratch, or by using "integer-length" plus some
> arithmetic to get some good initial bounds), but I suspect this is good
> enough and further complexity is not worth it.
>
> Note that this algorithm should work perfectly with any nonnegative
> rational arguments [other than 0 for b or x, and 1 for b], and should
> give as good an answer as any with floating-point arguments.  Also,
> "integer-finverse", as I called it, might be useful for many other
> "floor"-type computations with exact numbers (I have so used it myself
> in an ad hoc Arc math library).
>
> ;Finds n such that n >= 0 and f(n) <= x < f(n+1) in about 2*log(n) steps.
> ;Assumes f is monotonically increasing.
> (define (integer-finverse f x)
>    (define upper-bound
>      (let loop ((n 1))
>        (if (> (f n) x)
>            n
>            (loop (* n 2)))))
>    (define (search a b) ;b is too big, a is not too big
>      (let ((d (- b a)))
>        (if (= d 1)
>            a
>            (let ((m (+ a (quotient d 2))))
>              (if (> (f m) x)
>                  (search a m)
>                  (search m b))))))
>    (search (quotient upper-bound 2) upper-bound))
>
> (define (floor-log/base b x)
>    (cond ((< b 1) (- (ceiling-log/base (/ b) x)))
>          ((= b 1) (error "Base shouldn't be 1."))
>          ((< x 1) (- (ceiling-log/base b (/ x))))
>          (else (integer-finverse (lambda (n) (expt b n)) x))))
>
> (define (ceiling-log/base b x)
>    (cond ((< b 1) (- (floor-log/base (/ b) x)))
>          ((= b 1) (error "Base shouldn't be 1."))
>          ((< x 1) (- (floor-log/base b (/ x))))
>          (else
>           (let ((u (floor-log/base b x)))
>             (if (= x (expt b u))
>                 u
>                 (+ u 1))))))
>
>
> Testing:
>
>  > (floor-log/base 10 3)
> 0
>  > (floor-log/base 3 10)
> 2
>  > (ceiling-log/base 3 10)
> 3
>  > (ceiling-log/base 1/3 10)
> -2
>  > (floor-log/base 1/3 10)
> -3
>  > (floor-log/base 2/3 10)
> -6
>  > (ceiling-log/base 2/3 10)
> -5
>  > (exact->inexact (expt 3/2 6))
> 11.390625
>  > (exact->inexact (expt 3/2 5))
> 7.59375

Neet! I'll have to do some timing tests.

The functions are used to format plot labels for numbers outside 
floating-point range. As it is, the iterations will fix any under- or 
overestimate. Floating-point math is no problem: I just use it to get an 
initial estimate.

Also, I was surprised to find that the `log' function works on numbers 
well outside floating-point range. (Big ones, not small ones, which is 
why I subtract the logs of the numerator and denominator.) It works by 
taking successive integer square roots to reduce the argument first. If 
it stops working at some number size, that number is probably too large 
to fit in memory.

But for some large numbers that aren't too huge - say, megabyte-sized - 
reducing the argument takes a *long time*. I'll be interested to try 
switching to your solution for that case to see if it works out better.

Also, I'ma keep this code around for other stuff.

> I might add, by the way, that I'm inclined to expect the base to be a
> second, optional argument (perhaps defaulting to 10) to a function
> called simply "floor-log" or "ceiling-log".  I don't know if that fits
> with desired conventions, though.

The most consistent default is the natural base, but the discontinuity 
of floor/ceiling makes using transcendental bases pretty much 
impossible. :/ Next best would be 2 or 10, but I couldn't decide between 
them.

Neil ⊥
_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Matthias Felleisen | 2 Feb 16:32
Favicon

Re: floor-log/base, ceiling-log/base, from Neil Toronto's recent commit


Thank you for this neat example. It is good for ho contracts and, if you don't mind, I may use it with
attribution of course, in HtDP/2e. -- Matthias

On Feb 1, 2012, at 7:58 PM, John Boyle wrote:

> I happened to observe this commit from today by Neil Toronto:
> 
> http://git.racket-lang.org/plt/commitdiff/47fcdd4916a2d33ee5c28eb833397ce1d2a515e2
> 
> I may have some useful input on this, having dealt with similar problems myself.
> 
> The problem: Given b and x, you want to find the largest integer n such that b^n <= x (or, for the ceiling
problem, the smallest integer n such that b^n ≥ x).  This can profitably be viewed as a case of a more
general problem: given a monotonically increasing but otherwise opaque function f, find the largest
integer n such that f(n) ≤ x.  The previous algorithm to solve this can now be viewed as a linear search,
taking n steps.  This took too long, and Neil Toronto replaced it with an algorithm that depended on
floating-point numbers; but I hate to see that happen, because floats will screw up when the numbers get
too large; careful reasoning may prove that floats will be sufficiently accurate for a given
application, but it would be nice to have an exact algorithm so that one didn't have to do that.
> 
> I come here to present such an algorithm.  Simply put: Use a binary search rather than a linear search.  How do
we do binary search on "the nonnegative integers"?  Well, start with 0 and 1 as your bounds, and keep
doubling the 1 until you get something that's actually too high; then you have a real lower and upper bound. 
This will take log(n) steps to find the upper bound, and then a further log(n) steps to tighten the bounds to
a single integer.  Thus, this takes roughly 2*log(n) steps, where each step involves calculating (expt b
n) plus a comparison.  It might be possible to do slightly better by not treating b^n as a black box (e.g. by
using old results of b^n to compute new ones rather than calling "expt" from scratch, or by using
"integer-length" plus some arithmetic to get some good initial bounds), but I suspect this is good enough
and further complexity is not worth it.
> 
> Note that this algorithm should work perfectly with any nonnegative rational arguments [other than 0 for
b or x, and 1 for b], and should give as good an answer as any with floating-point arguments.  Also,
"integer-finverse", as I called it, might be useful for many other "floor"-type computations with exact
numbers (I have so used it myself in an ad hoc Arc math library).
> 
> ;Finds n such that n >= 0 and f(n) <= x < f(n+1) in about 2*log(n) steps.
> ;Assumes f is monotonically increasing.
> (define (integer-finverse f x)
>   (define upper-bound
>     (let loop ((n 1))
>       (if (> (f n) x)
>           n
>           (loop (* n 2)))))
>   (define (search a b) ;b is too big, a is not too big
>     (let ((d (- b a)))
>       (if (= d 1)
>           a
>           (let ((m (+ a (quotient d 2))))
>             (if (> (f m) x)
>                 (search a m)
>                 (search m b))))))
>   (search (quotient upper-bound 2) upper-bound))
> 
> (define (floor-log/base b x)
>   (cond ((< b 1) (- (ceiling-log/base (/ b) x)))
>         ((= b 1) (error "Base shouldn't be 1."))
>         ((< x 1) (- (ceiling-log/base b (/ x))))
>         (else (integer-finverse (lambda (n) (expt b n)) x))))
> 
> (define (ceiling-log/base b x)
>   (cond ((< b 1) (- (floor-log/base (/ b) x)))
>         ((= b 1) (error "Base shouldn't be 1."))
>         ((< x 1) (- (floor-log/base b (/ x))))
>         (else
>          (let ((u (floor-log/base b x)))
>            (if (= x (expt b u))
>                u
>                (+ u 1))))))
> 
> 
> Testing:
> 
> > (floor-log/base 10 3)
> 0
> > (floor-log/base 3 10)
> 2
> > (ceiling-log/base 3 10)
> 3
> > (ceiling-log/base 1/3 10)
> -2
> > (floor-log/base 1/3 10)
> -3
> > (floor-log/base 2/3 10)
> -6
> > (ceiling-log/base 2/3 10)
> -5
> > (exact->inexact (expt 3/2 6))
> 11.390625
> > (exact->inexact (expt 3/2 5))
> 7.59375
> 
> I might add, by the way, that I'm inclined to expect the base to be a second, optional argument (perhaps
defaulting to 10) to a function called simply "floor-log" or "ceiling-log".  I don't know if that fits with
desired conventions, though.
> --John Boyle
> Science is what we understand well enough to explain to a computer. Art is everything else we do. --Knuth
> 
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Stephen Chang | 3 Feb 08:06
Favicon

"bookmarks" in drracket?

When using Dr Racket, I use the right-click "Jump to definition of" a
lot but I frequently find that I also want an easy way to get back to
the code I was previously looking at. Does anyone else think this
would be a useful feature to have? I've implemented something that
adds this functionality.

If anyone wants to try it out, I've included both modified source
files (from drracket/private) and a patch.

With the code I added, a "bookmark" automatically gets saved when
jumping to a definition from the right-click menu and when choosing a
definition from the "(define ...)" menu. Multiple bookmarks accumulate
on a stack. You can also add your own bookmarks with the right click
menu.

To go back to the most recent bookmark, either use the right-click
menu, or press C-x r (is this an appropriate key binding? I chose it
because emacs similarly uses C-x r to do bookmark-related stuff).

Since I'm not very familiar with drracket code, I'm not sure I put
stuff in the right place. Would anyone mind reviewing my code? It's
only a few lines.

Also, would something like this be better as a plugin in the future?
Attachment (bookmarks.rkt): application/octet-stream, 1070 bytes
Attachment (rep.rkt): application/octet-stream, 90 KiB
Attachment (unit.rkt): application/octet-stream, 229 KiB
Attachment (bookmarks.patch): application/octet-stream, 6453 bytes
_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev
Robby Findler | 3 Feb 15:36

Re: "bookmarks" in drracket?

I like the idea. Some comments:

- the bookmarks should probably be saved in a text% object, not in a
module top-level variable (alternatively, the bookmarks would have to
record a frame and an editor, and then jumping to a bookmark might
send you to another frame/tab).

- it would be good if there was some graphical representation of the
current bookmarks state.

- did you consider just having an (unordered) list of bookmarks? Then,
adding a book mark would be a keystroke that'd be separate from
jumping around, so you'd have to set them yourself, but you could
iterate around in the set bookmarks, instead of having to keep track
of which things are on top of the stack.

I think the first one probably has to be fixed before we a release
could contain this feature. (The second one seems important, but not
as much as the first.)

Robby

On Fri, Feb 3, 2012 at 1:06 AM, Stephen Chang <stchang <at> ccs.neu.edu> wrote:
> When using Dr Racket, I use the right-click "Jump to definition of" a
> lot but I frequently find that I also want an easy way to get back to
> the code I was previously looking at. Does anyone else think this
> would be a useful feature to have? I've implemented something that
> adds this functionality.
>
> If anyone wants to try it out, I've included both modified source
> files (from drracket/private) and a patch.
>
> With the code I added, a "bookmark" automatically gets saved when
> jumping to a definition from the right-click menu and when choosing a
> definition from the "(define ...)" menu. Multiple bookmarks accumulate
> on a stack. You can also add your own bookmarks with the right click
> menu.
>
> To go back to the most recent bookmark, either use the right-click
> menu, or press C-x r (is this an appropriate key binding? I chose it
> because emacs similarly uses C-x r to do bookmark-related stuff).
>
> Since I'm not very familiar with drracket code, I'm not sure I put
> stuff in the right place. Would anyone mind reviewing my code? It's
> only a few lines.
>
> Also, would something like this be better as a plugin in the future?
>
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev
>

_________________________
  Racket Developers list:
  http://lists.racket-lang.org/dev

Gmane