# Print multiplication (*) operator

Problem Description The problem that I am facing is that I want to parse the output of sage into another file. Currently I am executing sage command to run a sage file, and then using the output of the sage file for another purpose. The issue with the output is that the space symbol is used for both multiplication and in general space. How to use '' or some other symbol for multiplication in 'sage'? For example when I run the following sage file:

var('x')
var('a')
var('b')
var('r')
var('tmp')
constr0 = (tmp - tmp +(Rational(1/1) (x^2)* (a^2)) + (Rational(1/1)* (b^2)) + (Rational(-1/1)* (a^2)* (b^2)) < 0)
constr1 = (tmp - tmp +(Rational(1/1)* (x^2)) + (Rational(221/1)) + (Rational(-20/1)* (x)) + (Rational(-1/1)* (r^2)) < 0)
F1 = qf.and_(constr0, constr1)
F3 =F1


I get the output as:

a - 1 /= 0 /\ a + 1 /= 0 /\ b /= 0 /\ r - 11 /= 0 /\ r + 11 /= 0 /\ [ a^4 r^4 - 2 a^4 b^2 r^2 + 2 a^2 b^2 r^2 - 442 a^4 r^2 + a^4 b^4 - 2 a^2 b^4 + b^4 + 42 a^4 b^2 - 42 a^2 b^2 + 48841 a^4 < 0 / [ a - 1 > 0 /\ a^2 r^2 - a^2 b^2 + b^2 - 221 a^2 > 0 ] / [ a + 1 < 0 /\ a^2 r^2 - a^2 b^2 + b^2 - 221 a^2 > 0 ] / [ a^2 b^2 - b^2 - 100 a^2 > 0 /\ r - 11 > 0 ] / [ a^2 b^2 - b^2 - 100 a^2 > 0 /\ r + 11 < 0 ] ]


Here it would be great if multiplication operator * is used for multiplication. Is there any way to do this in sage right now? I would like the print operator to output * instead for multiplication by space.

Proposed Solution:

The print function should allow the use of '*' operator for multiplication.

edit retag close merge delete

It's not Sage's but QEPCAD's output per se. But Sage could have done a bit more parsing to make QEPCAD's formulas look like Sage's expressions. It may be worth it to post a feature request at https://github.com/sagemath/sage/issues

( 2024-05-09 13:15:12 +0200 )edit

Sort by ยป oldest newest most voted

As a workaround you can perform a suitable substitution with regular expression - e.g.:

result = qepcad(qf.exists(x,F3))
import re
print( re.sub(r'(\w) (\w)',r'\1 * \2',result) )


gives

a - 1 /= 0 /\ a + 1 /= 0 /\ b /= 0 /\ r - 11 /= 0 /\ r + 11 /= 0 /\ [ a^4 * r^4 - 2 * a^4 * b^2 * r^2 + 2 * a^2 * b^2 * r^2 - 442 * a^4 * r^2 + a^4 * b^4 - 2 * a^2 * b^4 + b^4 + 42 * a^4 * b^2 - 42 * a^2 * b^2 + 48841 * a^4 < 0 \/ [ a - 1 > 0 /\ a^2 * r^2 - a^2 * b^2 + b^2 - 221 * a^2 > 0 ] \/ [ a + 1 < 0 /\ a^2 * r^2 - a^2 * b^2 + b^2 - 221 * a^2 > 0 ] \/ [ a^2 * b^2 - b^2 - 100 * a^2 > 0 /\ r - 11 > 0 ] \/ [ a^2 * b^2 - b^2 - 100 * a^2 > 0 /\ r + 11 < 0 ] ]

more

## Stats

Seen: 106 times

Last updated: May 09