# Re: How to multiply 2 sequences ?

 Subject: Re: How to multiply 2 sequences ? From: "Dimitre Novatchev" Date: Wed, 7 Nov 2007 08:17:45 -0800
```> If that is indeed the requirement (and I wasn't able to work it out from the
> posting) then it can be done in XPath 2.0 (without any help from FXSL) as
>
> sum(for \$i in 1 to count(\$x) return \$x[\$i] * \$y[\$i])

Probably I am a little bit biased  :-), but comparing

sum(f:zipWith(f:mult(), \$vect1, \$vect2))

to

sum(for \$i in 1 to count(\$x) return \$x[\$i] * \$y[\$i])

the former seems slightly more readable/elegant.

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play

On Nov 7, 2007 6:45 AM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> >
> > It seems that you are trying to obtain the scalar product of
> > two vectors:
> >
> > X = {x1, x2, ... , xn}
> >
> > Y = {y1, y2, ... , yn}
> >
> > X.Y = x1.y1 + x2.y2 + ... + xn.yn
> >
>
> If that is indeed the requirement (and I wasn't able to work it out from the
> posting) then it can be done in XPath 2.0 (without any help from FXSL) as
>
> sum(for \$i in 1 to count(\$x) return \$x[\$i] * \$y[\$i])
>
> Michael Kay
> http://www.saxonica.com/

```

### PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!