Ratio of huge products

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ratio of huge products

Alberto Magni
Hello everybody,

I have to compute something in this form:

x = prod(a:b) / prod(c:d),    where: a < c and b < d and obviously: a
< b and c < d

I cannot make assumptions on the relative position of c,b and a,d.

The problem is that a,b,c,d are large and the products are huge (R return Inf).
Their ratio is less than 1 but significantly higher than 0: it is a
non-tiny probability.

I need to find a way to simplify this ratio.
The only way to solve this that I see is to decompose into prime
factors all the
numbers in the numerator and the denominator and to remove the ones in common

Do you know a better way to do this ?

Thank you,
Alberto

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Ratio of huge products

Michael Weylandt
Use logs?

Michael

On Thu, Dec 15, 2011 at 1:35 PM, Alberto Magni
<[hidden email]> wrote:

> Hello everybody,
>
> I have to compute something in this form:
>
> x = prod(a:b) / prod(c:d),    where: a < c and b < d and obviously: a
> < b and c < d
>
> I cannot make assumptions on the relative position of c,b and a,d.
>
> The problem is that a,b,c,d are large and the products are huge (R return Inf).
> Their ratio is less than 1 but significantly higher than 0: it is a
> non-tiny probability.
>
> I need to find a way to simplify this ratio.
> The only way to solve this that I see is to decompose into prime
> factors all the
> numbers in the numerator and the denominator and to remove the ones in common
>
> Do you know a better way to do this ?
>
> Thank you,
> Alberto
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Ratio of huge products

plangfelder
In reply to this post by Alberto Magni
On Thu, Dec 15, 2011 at 10:35 AM, Alberto Magni
<[hidden email]> wrote:

> Hello everybody,
>
> I have to compute something in this form:
>
> x = prod(a:b) / prod(c:d),    where: a < c and b < d and obviously: a
> < b and c < d
>
> I cannot make assumptions on the relative position of c,b and a,d.
>
> The problem is that a,b,c,d are large and the products are huge (R return Inf).
> Their ratio is less than 1 but significantly higher than 0: it is a
> non-tiny probability.
>
> I need to find a way to simplify this ratio.
> The only way to solve this that I see is to decompose into prime
> factors all the
> numbers in the numerator and the denominator and to remove the ones in common
>
> Do you know a better way to do this ?

Yes, exp( sum(log(a:c))-sum(log(b:d)) ), which is mathematically
exactly equivalent, unless I made a typo.
Remeber that log of a product is a sum of the logs of the arguments.

Peter.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Ratio of huge products

David Winsemius
In reply to this post by Alberto Magni

On Dec 15, 2011, at 1:35 PM, Alberto Magni wrote:

> Hello everybody,
>
> I have to compute something in this form:
>
> x = prod(a:b) / prod(c:d),    where: a < c and b < d and obviously: a
> < b and c < d
>
> I cannot make assumptions on the relative position of c,b and a,d.
>
> The problem is that a,b,c,d are large and the products are huge (R  
> return Inf).

Well, R does have some limitations.

> Their ratio is less than 1 but significantly higher than 0: it is a
> non-tiny probability.
>
> I need to find a way to simplify this ratio.

x <- exp( sum(log(a:b)) -sum(log(c:d)) )

> The only way to solve this that I see is to decompose into prime
> factors all the
> numbers in the numerator and the denominator and to remove the ones  
> in common

Ewww. That does sound painful.

--

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.