Solve, elegant way ?

asked 2018-11-29 02:31:33 -0600

ortollj gravatar image

updated 2018-11-29 04:04:07 -0600

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

edit retag flag offensive close merge delete