# sqaure root type

I guess this is a very simple question:

What changes do I need to make in order to make

sage: sqrt(2) %1


work?

Also, what chapter in the manual I need to read in order not to ask such basic questions again??

Thanks a lot, Menny

edit retag close merge delete

What are you hoping to get? 0.414.. etc?

( 2011-12-20 16:11:54 +0200 )edit

Yes. when you write the code above you get an error regarding the type of the objects.

( 2011-12-21 08:07:05 +0200 )edit

Sort by ยป oldest newest most voted

In general if x % 1 fails (for x which is real) you can try RR(x) % 1 or RR(x).frac().

Note also that %1 and .frac() are different:

sage: RR(sqrt(3)) % 1
-0.267949192431123
sage: RR(sqrt(3)).frac()
0.732050807568877


I guess you want the latter. Actually %1 is a bit weird:

sage: [RR((2*k+1)/2)%1 for k in range(10)]
[0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000, 0.500000000000000, -0.500000000000000]

more

You can also get an numeric approximation: sqrt(2).n() % 1

( 2011-12-22 00:37:16 +0200 )edit

You can also get an numeric approximation:

( 2011-12-22 00:37:16 +0200 )edit

If you want a very basic stuff, then go for the sage tour.

For the documentation I guess "How do I..." manual and the tutorial section are really important to get an overview of the basics in a particular area.

Further you can start writing small codes in an area of your choice, by taking help from reference manual. (IMHO, the reference manual is quite complicated to understand for a person who is newbie to sage or python.)

Lastly, this forum plus the mailing list on google groups are quite useful places...

Hope this helps...

With best wishes,

VInay

more

This should do it.

sqrt(2.0) %1

more

It works. But I'm having similar problems when I, for example, take x to be some complex number, and y=x.real_part. Then, y%1 return a type error... where do I found how to deal with these errors?

( 2011-12-21 08:13:06 +0200 )edit

Did you really use y=x.real_part ? You need y=x.real_part()

( 2011-12-21 16:09:29 +0200 )edit

By the way there is one more place to get basics of sage: You can logon to the sagenb.org and view the published sheets.

e.g. Here is an example of one by William Stein

There are many other... Keep exploring...

-- VInay

more