Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solve, elegant way ?

Solve, elegant way ? Hi

SageMath version: 8.4, OS:W10

to solve this little problem, first I tried this code:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m = age of Maxime a = age of Albane, x = age difference   
forget()
var(' a_0 m_0 a_1 m_1 x')
assume(a_0,'real')
eq0=m_0==m_1/2
eq1=2*(a_0)==m_0
S_0=solve([eq0.substitute(m_1=32),eq1],a_0)
S_1=solve([eq0.substitute(m_1=32),eq1],a_0,m_0)
show("S_0 : ",S_0,"S_1 : ",S_1)

question 1 : in the code above what is wrong , why S_0 does not give a solution ?

afterward I tried this code below, which gives the good answer:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m_i = age of Maxime  a_i = age of Albane, x = age difference 
forget()
var(' a_0 m_0  x')
m_1=32
m_0=m_1/2
eq1=2*(a_0)==m_0
a_0=solve([eq1],a_0)[0].rhs()
x=m_0-a_0
a_1=m_1-x
show(" actual age of Albane : ",a_1)

question 2 : in order to serve as an example, could someone show me the most elegant way to solve this little PB with SageMath ?

Solve, elegant way ?

Solve, elegant way ? Hi

SageMath version: 8.4, OS:W10

to solve this little problem, first I tried this code:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m = age of Maxime a = age of Albane, x = age difference   
forget()
var(' a_0 m_0 a_1 m_1 x')
assume(a_0,'real')
eq0=m_0==m_1/2
eq1=2*(a_0)==m_0
S_0=solve([eq0.substitute(m_1=32),eq1],a_0)
S_1=solve([eq0.substitute(m_1=32),eq1],a_0,m_0)
show("S_0 : ",S_0,"S_1 : ",S_1)

question 1 : in the code above what is wrong , why S_0 does not give a solution ?

afterward I tried this code below, which gives the good answer:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m_i = age of Maxime  a_i = age of Albane, x = age difference 
forget()
var(' a_0 m_0  x')
m_1=32
m_0=m_1/2
eq1=2*(a_0)==m_0
a_0=solve([eq1],a_0)[0].rhs()
x=m_0-a_0
a_1=m_1-x
show(" actual age of Albane : ",a_1)

question 2 : in order to serve as an example, could someone show me the a most elegant way to solve this little PB with SageMath ?

Solve, elegant way ?

Solve, elegant way ? Hi

SageMath version: 8.4, OS:W10

to solve this little problem, first I tried this code:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m = age of Maxime a = age of Albane, x = age difference   
forget()
var(' a_0 m_0 a_1 m_1 x')
assume(a_0,'real')
eq0=m_0==m_1/2
eq1=2*(a_0)==m_0
S_0=solve([eq0.substitute(m_1=32),eq1],a_0)
S_1=solve([eq0.substitute(m_1=32),eq1],a_0,m_0)
show("S_0 : ",S_0,"S_1 : ",S_1)

question 1 : in the code above what is wrong , why S_0 does not give a solution ?

afterward I tried this code below, which gives the good answer:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m_i = age of Maxime  a_i = age of Albane, x = age difference 
forget()
var(' a_0 m_0  x')
m_1=32
m_0=m_1/2
eq1=2*(a_0)==m_0
a_0=solve([eq1],a_0)[0].rhs()
x=m_0-a_0
a_1=m_1-x
show(" actual age of Albane : ",a_1)

question 2 : in order to serve me as an example, could someone show me a most elegant way to solve this little PB with SageMath ?

Solve, elegant way ?

Hi

SageMath version: 8.4, OS:W10

to solve this little problem, first I tried this code:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m = age of Maxime a = age of Albane, x = age difference   
forget()
var(' a_0 m_0 a_1 m_1 x')
assume(a_0,'real')
eq0=m_0==m_1/2
eq1=2*(a_0)==m_0
S_0=solve([eq0.substitute(m_1=32),eq1],a_0)
S_1=solve([eq0.substitute(m_1=32),eq1],a_0,m_0)
show("S_0 : ",S_0,"S_1 : ",S_1)

question 1 : in the code above what is wrong , why S_0 does not give a solution ?

afterward I tried this code below, which gives the good answer:

#PB: Maxime is 32 years old.
#It is twice as old as Albane was when he was the age Albane has now.
#What is Albane's age?
# m_i = age of Maxime  a_i = age of Albane, x = age difference 
forget()
var(' a_0 m_0  x')
m_1=32
m_0=m_1/2
eq1=2*(a_0)==m_0
a_0=solve([eq1],a_0)[0].rhs()
x=m_0-a_0
a_1=m_1-x
show(" actual age of Albane : ",a_1)

question 2 : in order to serve me as an example, could someone show me a most elegant way to solve this little PB with SageMath ?

problem source