Trigonometric Equation Solving: Not Terminating

asked 2013-03-10 09:56:09 +0200

fdj815 gravatar image

The Background

I want to write a script which is able to do the following:

  • INPUT: x - A list of triangle items. These items are considered as given.
  • INPUT: y - A list of triangle items. We want to know the abstract formulas of these items.
  • OUTPUT: z - A list of formulas to calculate the items from y

For example:

  • INPUT: x - [alpha, beta] (considered as given)
  • INPUT: y - [gamma] (we want to know the formula of gamma)
  • OUTPUT: z - [gamma == pi - alpha - beta]

I want to do that using sage's solve().

My Problem:

This is a simplified script. It is just able to output formulas for alpha, beta and gamma when a, b and c are considered as given:

rings = RR[('a', 'b', 'c')].gens()[:3] # considered as given
x = dict([(str(rings_), rings_) for rings_ in rings])
varbs = SR.var(['alpha', 'beta', 'gamma']) # looking for `alpha`, `beta` and `gamma`
x.update([(str(varbs_), varbs_) for varbs_ in varbs])

print solve([
        #x['a']**2 == x['b']**2 + x['c']**2 - 2*x['b']*x['c']*cos(x['alpha']),     
        #x['b']**2 == x['a']**2 + x['c']**2 - 2*x['a']*x['c']*cos(x['beta']),       
        #x['c']**2 == x['a']**2 + x['b']**2 - 2*x['a']*x['b']*cos(x['gamma']),      

        x['alpha'] == arccos((x['a']**2 - x['b']**2 - x['c']**2) / 2*x['b']*x['c']),
        x['beta']  == arccos((x['b']**2 - x['a']**2 - x['c']**2) / 2*x['a']*x['c']),
        x['gamma'] == arccos((x['c']**2 - x['a']**2 - x['b']**2) / 2*x['a']*x['b']),

        #pi == x['alpha'] + x['beta'] + x['gamma'],
], [
        x['alpha'],
        x['beta'],
        x['gamma'],
])

This script is working correctly and outputs:

[
[alpha == pi - arccos(-0.5*a^2*b*c + 0.5*b^3*c + 0.5*b*c^3), beta == pi - arccos(0.5*a^3*c - 0.5*a*b^2*c + 0.5*a*c^3), gamma == arccos(-0.5*a^3*b - 0.5*a*b^3 + 0.5*a*b*c^2)]
]

I wanted to extend solve()'s knowledge base in order to be able to solve more complicated problems later on. But when I tried to uncomment the # lines and ran the script again, solve() didn't terminate any more.

My Question:

  • Why doesn't solve() terminate when I uncomment the # lines?
  • How can I get sage to terminate? Or: How can I work around this problem?

Thanks - if anything's unclear, please leave a comment concerning that.

edit retag flag offensive close merge delete