List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] getting hold of exponents in ifactor
| [MUG] getting hold of exponents in ifactor |
|
Author:
Posted: Tue, 6 Aug 2002 14:01:10 +0200 (
|
>> From: "moree"
I wonder how to get hold of the primes and exponents that
one gets on applying IFACTOR.
To give an example, suppose I want to compute \sum_{p|n}(e_p(n))^2*p,
where e_p(n) denotes the exponent of the prime p in the prime
factorisation of n, how do I most efficiently program this in Maple ?
The number n is any non-zero rational number.
Regards,
Pieter Moree
|
| [MUG] Re: getting hold of exponents in ifactor |
|
Author: Maple User Group
Posted: Fri, 9 Aug 2002 17:55:12 -0400 (
|
>> From: Maple User Group "maple_gr"
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 7 Aug 2002 18:00:32 -0400 (EDT)
From: Carl Devore "devore"
To: "maple-list" "moree"
Subject: getting hold of exponents in ifactor
On Tue, 6 Aug 2002 "moree" wrote:
> I wonder how to get hold of the primes and exponents that one gets on
> applying IFACTOR.
Use ifactors.
> To give an example, suppose I want to compute \sum_{p|n}(e_p(n))^2*p,
> where e_p(n) denotes the exponent of the prime p in the prime
> factorisation of n, how do I most efficiently program this in Maple ?
With ifactors this is trivial:
sq_e:= n-> add(f[2]^2*f[1], f= ifactors(n)[2]);
> The number n is any non-zero rational number.
Don't you mean integer?
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 7 Aug 2002 16:47:27 -0700 (PDT)
From: Robert Israel "israel"
To: "maple-list"
Subject: getting hold of exponents in ifactor
It is slightly easier using ifactors rather than ifactor.
The result of ifactors is a list. The first element is the sign
of n, which doesn't concern us; the second is a list of lists [p,e]
where p is prime and p^e occurs in the factorization. So what you
want can be done as
add(op(2,t)^2*op(1,t), t=op(2,ifactors(n)));
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 7 Aug 2002 22:11:29 -0400 (EDT)
From: Edwin Clark "eclark"
To: "maple-list"
Subject: getting hold of exponents in ifactor
I guess you mean ifactor?
Do you mean n is an integer greater than 1? If I understand
your question the following procedure should work:
f:=n->add(x[2]^2*x[1],x = ifactors(n)[2]);
This uses ifactors(n)[2] which gives the prime factorization as
a list of lists [p,e_p(n)] Compare ifactor with ifactors:
> n:=3^2*5^4;
n := 5625
> ifactor(n);
2 4
(3) (5)
> ifactors(n);
[1, [[3, 2], [5, 4]]]
> ifactors(n)[2];
[[3, 2], [5, 4]]
------------------------------------------------------------
W. Edwin Clark, Math Dept, University of South Florida,
http://www.math.usf.edu/~eclark/
------------------------------------------------------------
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: Stanley J Houghton "S.J.Houghton"
Date: Fri, 9 Aug 2002 10:27:11 +0100
To: "maple-list"
Subject: getting hold of exponents in ifactor
Pieter
I expect others will produce more efficient code but if I understand
you correctly you could use the approach below.
The trick in this extraction is to recognise that the terms produced by
ifactor are of the form
``(prime)^exponent
or
``(prime) if the exponent is unity,
where `` is in invisible function (the identity function when expanded
by `expand`) used to retain the brackets in the result. You use `op`
to extract the components from the terms.
The code below turns the result of ifactor into a list of terms that
are converted (map) to the form [prime,exponent]. These may be
accessed by index and manipulated as you require.
I define p and e to make the expression for the sum more readable (note
the quotes to avoid premature evaluation, i.e. before the sum).
> n:=450;
> # elaborate the list of factors as [prime,exponent]
> # in two steps, to make it more obvious, but
> # expressions may be combined for brevity
> f:=[op(ifactor(n))]; #list of factor terms
> # now convert to list of lists of form [p,e]
> f:=map(x->
> if type(x,`^`) then # for exponent terms
> [op(op(1,x)),op(2,x)]
> else # for simple prime terms
> [op(op(x)),1] fi
> ,f);
> # now f[i][1] is the prime p
> p:='f'['i'][1];
> # and f[i][2] the exponent e
> e:='f'['i'][2];
> # thus the sum comes from for example
> sum(e^(2*p),i=1..nops(f));
Hope it helps
Regards
Stan
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 09 Aug 2002 10:30:39 -0400
From: "Douglas B. Meade" "meade"
To: "maple-list" "moree"
Subject: getting hold of exponents in ifactor
Pieter and MUG,
It is easier to use ifactors, not ifactor. The first example shows how
to use the output from ifactors. I also provide a procedure that makes
all of this automatic and makes slightly more efficient use of the
ifactors output.
> q := ifactors(1025);
q := [1, [[5, 2], [41, 1]]]
> P := map2( op, 1, q[2] );
P := [5, 41]
> E := map2( op, 2, q[2] );
E := [2, 1]
> add( E[i]^(2*P[i]), i=1..nops(P) );
1025
> S := ( n::posint ) -> add( t[2]^(2*t[1]), t=ifactors( n )[2] ):
> S( 1025 );
1025
I hope this is of use to you,
Doug
-----------------------------------------------------------------------
Prof. Douglas B. Meade Phone: (803) 777-6183 FAX: (803)
777-6527
Department of Mathematics URL: http://www.math.sc.edu/~meade/
USC, Columbia, SC 29208 E-mail: "mailto:meade"
|
Previous by date: [MUG] Re: Dirac delta, Maple User Group
Next by date: [MUG] Re: yp := (t) -> %;, Maple User Group
Previous thread: [MUG] yp := (t) -> %;, Colin Campbell - IST
Next thread: [MUG] yp := (t) -> %;, Colin Campbell - IST
|