Ask Your Question
0

exponent of a prime

asked 2012-01-31 17:00:19 +0100

emiliocba gravatar image

updated 2012-01-31 17:07:45 +0100

I am newbie in SAGE and here. My apologies for any mistake. This is an easy question.

Is there a command that for an integer $m$ and a prime number $p$ returns the exponent of $p$ in $m$?

If not, I would like if the following definition can be improved.

def exponent(p,m):
    v=m
    sol=0
    while v%p==0:
        v=v/p
        sol=sol+1
    return sol

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-01-31 17:38:08 +0100

achrzesz gravatar image

sage: m=240

sage: m.valuation(2)
4

sage: m.valuation(3)

1

sage: m.valuation(5)

1

sage: [x for x in factor(m)]

[(2, 4), (3, 1), (5, 1)]

edit flag offensive delete link more

Comments

This works but is absurdly obscure. You shouldn't need to know to search for "p-adic valuation" to get the right answer. We should come up with a good name and make an alias as an Integer method.

DSM gravatar imageDSM ( 2012-01-31 17:47:04 +0100 )edit

Maybe an alias? But I have to say that the way I would do it is the last one. I suppose you could open a ticket to do this.

kcrisman gravatar imagekcrisman ( 2012-01-31 20:36:21 +0100 )edit

Do you mean the factor approach? Sure, but then if you have (2^10)*p*q for big p,q you'l spend all your time factoring. I've actually needed this in the past for OEIS stuff and wound up taking log(n/n.prime_part_to_m(p),p) or whatever the prime_part method is called.

DSM gravatar imageDSM ( 2012-01-31 20:52:12 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-01-31 17:00:19 +0100

Seen: 678 times

Last updated: Jan 31 '12