Processing math: 13%

First time here? Check out the FAQ!

Ask Your Question
0

How to factor an integer apparently including irrational numbers

asked 1 year ago

Ys1123 gravatar image

updated 1 year ago

I want to do prime factorization of following a

a=sqrt(2)+6-sqrt(2)
a.factor()

But sage says simply

6

What should I do?

(I originally wanted to factor (3+8)i+(38)i2 for i in [1..40])

Preview: (hide)

Comments

Homework ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 1 year ago )

2 Answers

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

Check type(a):

a=sqrt(2)+6-sqrt(2)
print( type(a) )

which gives:

<class 'sage.symbolic.expression.expression'="">

and so a is not an integer but a symbolic expression. If you want to factor a as an integer, convert it to an integer type first:

print( ZZ(a).factor() )

which gives 2 * 3 as expected.

Preview: (hide)
link

Comments

Thank you. Then I want to move on original question:

a=((3+sqrt(8))^3+(3-sqrt(8))^3)/2
ZZ(a).factor()

But then sage put out error.

Ys1123 gravatar imageYs1123 ( 1 year ago )

You need to expand a before converting:

ZZ(a.expand()).factor()
Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

Thank you again! The problem solved by following code!

S=[((3+sqrt(8))^i+(3-sqrt(8))^i)/2 for i in [1..40]]
[ZZ(a.expand()).factor() for a in S]
Ys1123 gravatar imageYs1123 ( 1 year ago )
0

answered 1 year ago

Emmanuel Charpentier gravatar image

updated 1 year ago

What should I do?

Nothing ;-).

Let's start from the binomial formula :

sage: a, b, c, i, j = var("a, b, c, i, j")
sage: BF=(a+b)^i==sum(a^j*b^(i-j)*binomial(i, j), j, 0, i, hold=True) ; BF
(a + b)^i == sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)

( {\left(a + b\right)}^{i} = {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}}

Let's generalize it by using wildcards :

sage: w0, w1, w2 = (SR.wild(u) for u in  range(3))
sage: BFG = BF.subs({a:w0, b:w1, i:w2}) ; BFG
($1 + $0)^$2 == sum($1^($2 - j)*$0^j*binomial($2, j), j, 0, $2)

{\left(\$1 + \$0\right)}^{\$2} = {\sum_{j=0}^{\$2} \$1^{\$2 - j} \$0^{j} \binom{\$2}{j}}

and use it on a general form of your original expression :

sage: Ex=(a + b)^i + (a - b)^i ; Ex
(a + b)^i + (a - b)^i

{\left(a + b\right)}^{i} + {\left(a - b\right)}^{i}

sage: ExT=Ex.subs(BFG) ; ExT
sum(a^j*(-b)^(i - j)*binomial(i, j), j, 0, i) + sum(a^j*b^(i - j)*binomial(i, j), j, 0, i)

{\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j}} + {\sum_{j=0}^{i} a^{j} b^{i - j} \binom{i}{j}}

which can be rewritten ("contracted") as a single sum :

sage: ExTR=ExT.maxima_methods().sumcontract() ; ExTR
sum(a^j*(-b)^(i - j)*binomial(i, j) + a^j*b^(i - j)*binomial(i, j), j, 0, i)

{\sum_{j=0}^{i} a^{j} \left(-b\right)^{i - j} \binom{i}{j} + a^{j} b^{i - j} \binom{i}{j}}

whose summand can be factored as :

sage: ExTR.operands()[0].collect_common_factors()
a^j*((-b)^(i - j) + b^(i - j))*binomial(i, j)

a^{j} {\left(\left(-b\right)^{i - j} + b^{i - j}\right)} \binom{i}{j}

Now, assuming that a,b\in\mathbb{R},\,b>0 :

  • if i-j is odd, \left(\left(-b\right)^{i - j} + b^{i - j}\right)=-\left(b\right)^{i - j} + b^{i - j}=0

  • if i-j is even, \left(\left(-b\right)^{i - j} + b^{i - j}\right)=2\,b^{i - j}.

All non-zero terms of the sum are therefore products whose b factor is at an even power ; therefore, if b is a square root, these terms can all be simplified as a real without (external) radical.

That's (more or less) what Sage does when putting its computation results in its "preffered format", which has already been the cause of very many questions...

HTH,

Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 265 times

Last updated: Oct 07 '23