[plt-scheme] re: the fastest way to calc a cartesian product

From: John Clements (clements at brinckerhoff.org)
Date: Thu Sep 21 00:10:34 EDT 2006

On Sep 19, 2006, at 10:02 AM, Barland, Ian wrote:

> This is NOT the answer you were looking for...
>
> But if you want to allow *infinite* sets, and take "element-of" as  
> your only
> primitive (and forgo being able to iterate over elements of the set),
> you can represent sets as their element-of (indicator) function.
> Then Cartesian-product (and union and intersection) are O(1)  :-)
>
> An uncommented example:
> ===========
> (define cars  (lambda (elt) (memq elt '(vw saab bmw audi))))
> (define evens (lambda (elt) (and (number? elt) (even? elt))))
>
> (define (element-of? elt set) (set elt))
>
> (define (cartesian-product A B)
>   (lambda (elt)
>      (and (length=2? elt)
>           (element-of? (first elt) A)
>           (element-of? (first elt) B))))

ITYM "second" ?

John

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060920/1f883479/attachment.p7s>

Posted on the users mailing list.