Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

exponent of a prime

asked 13 years ago

emiliocba gravatar image

updated 13 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

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)]

Preview: (hide)
link

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 ( 13 years ago )

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 ( 13 years ago )

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 ( 13 years ago )

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: 13 years ago

Seen: 699 times

Last updated: Jan 31 '12