# fdj815's profile - activity

2013-03-10 09:56:09 +0200 asked a question Trigonometric Equation Solving: Not Terminating

## 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?

2013-03-05 15:13:57 +0200 commented question Internal Python: No module named all

@ppurka I added some information concerning my working environment to my question. I hope this helps to solve my question.

2013-03-05 15:05:29 +0200 commented question Internal Python: No module named all

@ppurka If I heard your question right: I don't run /path/to.sage using ./to.sage - I tried to run the script using the commands described in the section "My Situation".

2013-03-05 14:43:39 +0200 asked a question Internal Python: No module named all

This is not a duplicate because the other people who've got that error message all were using an external python installation instead of sage -python /path/to.py

## My Situation

I'm not able to execute scripts the following ways:

• sage /path/to.sage (preprocessed)
• sage /path/to.spyx
• sage /path/to.py
• sage -python /path/to.py

But I'm able to run correctly without problems:

• sage \$ load 'file'

## The Traceback

When cython compiles an .spyx file:

Traceback (most recent call last):
[...]
File "_home_user_Dokumente_oak_code_sage_spyx_0.pyx", line 14, in init _home_user_Dokumente_oak_code_sage_spyx_0 (_home_user_Dokumente_oak_code_sage_spyx_0.c:754)
sg.var('a b c')
AttributeError: 'module' object has no attribute 'var'


The statement that there's no var in the loaded module seems to be true because dir(sg) wasn't able to find anything else than __doc__ and other "underscored items".

When python tries to execute file (normal handwritten .py or a sage preprocessed .sage):

Traceback (most recent call last):
File "sage2.py", line 2, in <module>
from sage.all_cmdline import *   # import sage library
File "/home/user/Dokumente/oak/code/sage.py", line 4, in <module>
import sage.all as sg
ImportError: No module named all


## The Source

#!/usr/bin/env sage -python

import sys
import sage.all as sg

print '== TESTOUTPUT =='
sg.var('a b c')


## The Environment

My system setup:

Ubuntu 12.4 LTS
743,6 MiB64
AMD Athlon(tm) II X4 620 Processor
64 Bit


My environment variables:

[...]
declare -x LD_LIBRARY_PATH="/opt/sage/local/lib"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LIBRARY_PATH="/opt/sage/local/lib/"
[...]
declare -x PATH="/opt/sage:/opt/sage/local/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
declare -x PWD="/home/jk/Dokumente/oak/code"
declare -x PYTHONHOME="/opt/sage/local"
declare -x PYTHONPATH="/opt/sage/local/lib/python"
declare -x RANLIB="ranlib"
declare -x RHOME="/opt/sage/local/lib/R"
declare -x RM="rm"
declare -x SAGE64="no"
declare -x SAGE_DATA="/opt/sage/data"
declare -x SAGE_DOC="/opt/sage/devel/sage/doc"
declare -x SAGE_EXTCODE="/opt/sage/spkg/installed/extcode-5.7"
declare -x SAGE_LOCAL="/opt/sage/local"
declare -x SAGE_ORIG_LD_LIBRARY_PATH="/opt/sage//local/lib"
declare -x SAGE_ORIG_LD_LIBRARY_PATH_SET="True"
declare -x SAGE_PACKAGES="/opt/sage/spkg"
declare -x SAGE_ROOT="/opt/sage"
declare -x SAGE_SERVER="http://www.sagemath.org/"
declare -x SAGE_SHARE="/opt/sage/local/share"
declare -x SAGE_STARTUP_FILE="/home/user/.sage//init.sage"
declare -x SAGE_TESTDIR="/home/user/.sage//tmp"
[...]
declare -x __sage__=""


## The Question

How can I get sage -python (sage's internal python) to execute the files specified as command line argument correctly? How can I get sage.all's members to get imported correctly?