# Re: Fwd: [bdbxml] xquery puzzle

```Michael,

Thanks. i will look over you solution careful. Specifically, i will run it
through the formal semantics by hand to see if i can convince myself that it
works.

Best wishes,

--greg

On 12/10/05, Michael Dyck <jmdyck@ibiblio.org> wrote:
>
>
> "L.G. Meredith" wrote:
> >
> > Michael,
> >
> > Thanks for taking a whack at it. But, there was a slight
> > misunderstanding. The predicates hold of a (sub)collection -- not of
> > an element.
>
> Ah, right. Well, that should be even easier:
>
>   function decompose( input-set ):
>     element coll {
>        for bipartition in bipartitions( input-set, (), () )
>        where p1(bipartition/coll[0]) and p2(bipartition/coll[1])
>        return bipartition
>     }
>
>   function bipartitions( remaining-input, part1_so_far, part2_so_far ):
>     if remaining-input is empty:
>        element coll {
>          element coll {part1_so_far},
>          element coll {part2_so_far}
>        }
>     else
>           t := tail(remaining-input)
>       return
>       (
>         bipartitions( t, part1_so_far + h, part2_so_far )
>         ,
>         bipartitions( t, part1_so_far, part2_so_far + h )
>       )
>
> Or, you could push the "p1 and p2" test into bipartitions(); it would
> make the latter un-generic, but it might save space, depending on
> the XQuery implementation.
>
> -Michael
>
>
>
>
> >        function decompose( input-set ):
> >          element coll { foo( input-set, (), () ) }
> >
>   function foo( remaining-input, p1s_so_far, p2s_so_far ):
> >          if remaining-input is empty:
> >             element coll {
> >               element coll {p1s_so_far},
> >               element coll {p2s_so_far}
> >             }
> >          else
> >            let h := head(remaining-input), t :=
> >      tail(remaining-input)
> >            return
> >              if p1(h): foo( t, p1s_so_far + h, p2s_so_far ) else:
> >      ()
> >              ,
> >              if p2(h): foo( t, p1s_so_far, p2s_so_far + h ) else:
> >      ()
> >
> >      It should be fairly straightforward to translate that to
> >      proper XQuery.
> >
> >      -Michael
> >
> > --
> > L.G. Meredith
> >
> > 505 N 72nd St
> > Seattle, WA 98103
> >
> > +1 206.650.3740
>
>

--
L.G. Meredith

505 N 72nd St
Seattle, WA 98103

+1 206.650.3740
```

Received on Sunday, 11 December 2005 01:46:42 UTC