Ask Your Question
1

sagemath stuck in rdf presentation

asked 2023-05-14 02:24:58 +0100

Hello. I made sagemath show an answer in RDF and played around in it. now it shows all answers with a lot of zeroes after decimal even if its an integer. how do I make sagemath show me numerical presentation of answers but with least amount of zeroes?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-19 11:42:17 +0100

slelievre gravatar image

updated 2023-05-19 11:45:32 +0100

Sage has several types of floating-point numbers.

See an overview in

Among them, float and RDF elements are displayed with no trailing zero, while RR elements are displayed with a fixed number of significant figures.

To figure out what kind of number a given number is, use the parent function.

Convert between types of numbers by using int(a), ZZ(a), QQ(a), float(a), RR(a), RDF(a), etc.

If numbers with different parents are added, multiplied, subtracted or divided, the parent of the result is determined by Sage's coercion system.

Short answer to your question: work in RDF.

Below are a few examples to illustrate the above explanations.

Example.

sage: a = 3/2
sage: b = float(a)
sage: c = RDF(a)
sage: d = RR(a)

sage: a
3/2
sage: parent(a)
Rational Field
sage: QQ
Rational Field

sage: b
1.5
sage: parent(b)
<class 'float'>
sage: float
<class 'float'>

sage: d
1.50000000000000
sage: parent(d)
Real Field with 53 bits of precision
sage: RR
Real Field with 53 bits of precision

sage: c
1.5
sage: parent(c)
Real Double Field
sage: RDF
Real Double Field

sage: parent(a + b)
<class 'float'>
sage: parent(a + c)
Real Double Field
sage: parent(a + d)
Real Field with 53 bits of precision
sage: parent(b + c)
Real Double Field
sage: parent(b + d)
Real Field with 53 bits of precision
sage: parent(c + d)
Real Field with 53 bits of precision
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: 2023-05-14 02:24:58 +0100

Seen: 144 times

Last updated: May 19 '23