Ask Your Question
0

how to get doc for object methods in sage

asked 2015-02-04 21:54:19 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi, I don't know if my question is clear but

to get the doc for a function I usually type "isprime?" for example

but for a method like small_roots that is used like this : "f.small_roots()" I cannot find the doc by typing "small_roots?" in sage.

Any idea?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-02-04 22:51:43 +0200

kcrisman gravatar image

updated 2015-02-05 15:30:33 +0200

If you do f.small_roots?, you get

Docstring:
    See "sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots()"
    for the documentation of this function.

And then

sage: sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots?

String form:    <built-in function small_roots>
Definition:     sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots(self, X=None, beta=1.0, epsilon=None, **kwds)
Docstring:
   Let N be the characteristic of the base ring this polynomial is
   defined over: "N = self.base_ring().characteristic()". This method
   returns small roots of this polynomial modulo some factor b of N
   with the constraint that b >= N^beta. Small in this context means
...

Does that help?

edit flag offensive delete link more

Comments

yep thanks a lot!

mimoo gravatar imagemimoo ( 2015-02-28 18:55:09 +0200 )edit
2

answered 2015-02-05 09:27:59 +0200

slelievre gravatar image

updated 2015-02-05 09:35:11 +0200

In cases like is_prime, there is a function with that name in the global namespace, and also some objects have a method called that. What the global function does is usually deal with some special cases, then check if the argument you entered for the function is an object that has a method with the same name, and then apply this method to that object.

You can inspect the source code for the global function is_prime:

sage: is_prime??

You can see that it's not the same as the source code for the method is_prime of an integer.

sage: a = 5
sage: a.is_prime??

In cases like small_roots, it doesn't make sense to have it as a global function in the global namespace. It can only be called as a method, for those objects which have such a method.

If f has a method small_roots, then you can access the documentation by

sage: f.small_roots?

and the source code by

sage: f.small_roots??

If you don't have an object with that method, you can do

sage: search_doc("small_roots")

or

sage: search_src("small_roots")

to get an idea of where in the documentation, resp. where in the source code, this string appears.

For instance, I get:

sage: search_src("small_roots")
rings/polynomial/polynomial_modn_dense_ntl.pyx:373:    def small_roots(self, *args, **kwds):
rings/polynomial/polynomial_modn_dense_ntl.pyx:375:        See :func:`sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots`
rings/polynomial/polynomial_modn_dense_ntl.pyx:384:            sage: f.small_roots()
rings/polynomial/polynomial_modn_dense_ntl.pyx:387:        return small_roots(self, *args, **kwds)
rings/polynomial/polynomial_modn_dense_ntl.pyx:389:def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds):
rings/polynomial/polynomial_modn_dense_ntl.pyx:443:        sage: f.small_roots()
rings/polynomial/polynomial_modn_dense_ntl.pyx:484:        sage: Kbar = f.small_roots()[0]
rings/polynomial/polynomial_modn_dense_ntl.pyx:513:        sage: d = f.small_roots(X=2^hidden-1, beta=0.5)[0] # time random
rings/polynomial/polynomial_zmod_flint.pyx:353:    def small_roots(self, *args, **kwds):
rings/polynomial/polynomial_zmod_flint.pyx:355:        See :func:`sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots`
rings/polynomial/polynomial_zmod_flint.pyx:364:            sage: f.small_roots()
rings/polynomial/polynomial_zmod_flint.pyx:367:        from sage.rings.polynomial.polynomial_modn_dense_ntl import small_roots
rings/polynomial/polynomial_zmod_flint.pyx:368:        return small_roots(self, *args, **kwds)

Then you can inspect these files in your favourite text editor, for instance open up a terminal and type

vim <SAGE_ROOT>/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

(replacing <sage_root> with the path to your Sage installation), and go to the specified lines, or use your text editor to search for the string small_roots, and you get an example of how to use the method, and the source code.

edit flag offensive delete link more

Comments

Now I see that I misunderstood the question. Updated my answer, but yours is naturally far more comprehensive.

kcrisman gravatar imagekcrisman ( 2015-02-05 15:31:01 +0200 )edit

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: 2015-02-04 21:54:19 +0200

Seen: 528 times

Last updated: Feb 05 '15