Ask Your Question
0

Print multiplication (*) operator

asked 2024-05-09 01:04:46 +0100

ani gravatar image

updated 2024-05-09 13:16:55 +0100

Max Alekseyev gravatar image

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')
qf = qepcad_formula
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
print(qepcad(qf.exists(x,F3)))

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 flag offensive close merge delete

Comments

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

Max Alekseyev gravatar imageMax Alekseyev ( 2024-05-09 13:15:12 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-05-09 16:50:46 +0100

Max Alekseyev gravatar image

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 ] ]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2024-05-09 01:04:46 +0100

Seen: 167 times

Last updated: May 09