ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Jun 2018 23:37:58 +0200Is it possible to default to real field?https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/It appears that Sage defaults symbolic variables to the complex field. This is passed along to Maxima, eventually triggering segfaults. Given that all of my variables are real, is it possible to default the symbolic domain to the real field BEFORE asking any calculations of Maxima?
[Related to my thread on the Development mailing list.]Tue, 19 Jun 2018 23:04:55 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/Answer by Richard_L for <p>It appears that Sage defaults symbolic variables to the complex field. This is passed along to Maxima, eventually triggering segfaults. Given that all of my variables are real, is it possible to default the symbolic domain to the real field BEFORE asking any calculations of Maxima?</p>
<p>[Related to my thread on the Development mailing list.]</p>
https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?answer=42688#post-id-42688Nils Bruin provided the answer over on sage-devel. It is to insert
maxima_calculus.eval("domain:real;")
before the variable declarations.
Wed, 20 Jun 2018 16:28:38 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?answer=42688#post-id-42688Comment by nbruin for <p>Nils Bruin provided the answer over on sage-devel. It is to insert</p>
<pre><code>maxima_calculus.eval("domain:real;")
</code></pre>
<p>before the variable declarations.</p>
https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42691#post-id-42691and it's a hack. Other parts of sage probably expect `domain: complex` to be active when maxima code is expected, so you may find failures in other areas. This is definitely in the "warranty voided if opened" category. Sage doesn't come with warranty, so you don't lose much ...Wed, 20 Jun 2018 17:38:59 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42691#post-id-42691Answer by tmonteil for <p>It appears that Sage defaults symbolic variables to the complex field. This is passed along to Maxima, eventually triggering segfaults. Given that all of my variables are real, is it possible to default the symbolic domain to the real field BEFORE asking any calculations of Maxima?</p>
<p>[Related to my thread on the Development mailing list.]</p>
https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?answer=42682#post-id-42682You can use the ``assume`` function (which is not alwys reliable, so you shoud test it):
sage: var('t')
t
sage: assume(t,'real')
sage: assumptions()
[t is real]
Wed, 20 Jun 2018 10:59:13 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?answer=42682#post-id-42682Comment by Richard_L for <p>You can use the <code>assume</code> function (which is not alwys reliable, so you shoud test it):</p>
<pre><code>sage: var('t')
t
sage: assume(t,'real')
sage: assumptions()
[t is real]
</code></pre>
https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42687#post-id-42687Thanks,but that does not work. Sage will send to Maxima something like:
domain: complex;
declare( t, real );
Alas, certain expressions involving t will now fail.
What I'm looking for is a way to cause Maxima to execute "domain:real;".Wed, 20 Jun 2018 15:59:01 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42687#post-id-42687Comment by Emmanuel Charpentier for <p>You can use the <code>assume</code> function (which is not alwys reliable, so you shoud test it):</p>
<pre><code>sage: var('t')
t
sage: assume(t,'real')
sage: assumptions()
[t is real]
</code></pre>
https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42702#post-id-42702You may try to wrap your computation in a `try`...`except`...`finally` structure, starting with `maxima_calculus("domain:real")` and `maxima_calculus("domain:complex")` in the `finally` clause. or, even better, define a decorator or a context.Wed, 20 Jun 2018 23:37:58 +0200https://ask.sagemath.org/question/42675/is-it-possible-to-default-to-real-field/?comment=42702#post-id-42702