Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

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

Search email archive for  

[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



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055