Ask Your Question

dgulotta's profile - activity

2016-06-21 09:10:59 +0200 received badge  Teacher (source)
2016-06-21 01:55:49 +0200 answered a question Executing Sage with arguments from C with exec family

The -c needs to be a separate argument from the code:


            sprintf(args[0],"sage");
            sprintf(args[1],"-c");
            sprintf(args[2],"\"taskId=%d;taskArgs=[%s];load('%s');\"",taskNumber,arguments,inp_programFile);
            args[3] = NULL;
2016-06-16 01:56:46 +0200 answered a question exec(func()) not the same as func() ?

The exec() function interprets its argument as pure Python code rather than Sage code. In Python 2, the code '4752/8677' rounds the ratio down to the nearest integer.

In any case, I would not recommend using the exec() command to read data from a file, as it could be a security risk and it may give confusing error messages if the data are not in the format that you expect. You might consider using pickle/csv/json instead.

2016-06-15 00:20:20 +0200 received badge  Supporter (source)
2016-06-15 00:16:37 +0200 received badge  Scholar (source)
2016-06-14 21:40:13 +0200 received badge  Student (source)
2016-06-14 20:26:04 +0200 asked a question quaternions not hashable?

If I try to take the hash of a quaternion, I get an error:

sage: D.<i,j,k>=QuaternionAlgebra(QQ,-1,-3)
sage: hash(i)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-037418ebb374> in <module>()
----> 1 hash(i)

TypeError: unhashable type: 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_rational_field'

I seem to remember quaternions being hashable in a previous version of Sage (I think I was using 6.7 before). Is it intentional that quaternions are now unhashable, or is this an omission?