sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 462 forks source link

adding apropos to SAGE -- try `conductor**?' for an example. #391

Closed 93749b3a-c0a4-47a7-b178-004ba08b0b97 closed 6 years ago

93749b3a-c0a4-47a7-b178-004ba08b0b97 commented 17 years ago

This bundle adds an apropos command to SAGE -- try `conductor**?' for an example.

The implementation is in sage.misc.apropos. Some code that needs to be fast is in sage.misc.apropos_internals, a Pyrex module.

This bundle addresses some annoyances with IPython's introspection module.

See the hg log for details.

Component: user interface

Keywords: apropos ipython search

Issue created by migration from https://trac.sagemath.org/ticket/391

93749b3a-c0a4-47a7-b178-004ba08b0b97 commented 17 years ago
comment:1

Attachment: ncalexan-apropos.hg.gz

Summary of bundle, in a nutshell:

sage: conductor**? sage.all.mwrank_EllipticCurve.conductor Command: Return the conductor of this curve, computed using Cremona's implementation of Tate's algorithm. sage.databases.cremona.LargeCremonaDatabase.conductor_range Command: Return the range of conductors that are covered by the database. sage.databases.cremona.LargeCremonaDatabase.largest_conductor Command: The largest conductor for which the database is complete. OUTPUT: int -- largest conductor sage.databases.cremona.LargeCremonaDatabase.smallest_conductor Command: The smallest conductor for which the database is complete. (Always 1.) sage.databases.cremona.MiniCremonaDatabase.conductor_range Command: Return the range of conductors that are covered by the database. sage.databases.cremona.MiniCremonaDatabase.largest_conductor Command: The largest conductor for which the database is complete. OUTPUT: int -- largest conductor sage.databases.cremona.MiniCremonaDatabase.smallest_conductor Command: The smallest conductor for which the database is complete. (Always 1.) sage.modular.dirichlet.DirichletCharacter.conductor Command: Computes and returns the conductor of this character. sage.schemes.elliptic_curves.ell_rational_field.EllipticCurve_rational_field.conductor Command: Returns the conductor of the elliptic curve.

Lists all callable things (classes, functions, etc) that have conductor in the last part of their dotted name.

The bundle also contains several enhancements to IPython's introspection. For example:

sage: ?y Parent: Symbolic Ring :: <class 'sage.calculus.calculus.SymbolicExpressionRing_class'> Type: SymbolicVariable Base Class: <class 'sage.calculus.calculus.SymbolicVariable'> String Form: y Namespace: Interactive Docstring:

Displays y's parent, which is very helpful. sage: ?2 Parent: Integer Ring :: Type: Integer Base Class: String Form: 2 Docstring: Interrogating literals works, more or less. sage: ?factor(6) Type: Factorization Base Class: String Form: 2 * 3 Length: 2 Docstring: Does what you'd expect, even if it will mangle iterators in strange corner cases.
williamstein commented 17 years ago
comment:2

Hi Nick,

(1) I applied the patch and when I do

conductor**?

I get a segfault that results from an infinite loop; at least for me, this happens in the function given below, which recursively calls itself and gets in an infinite loop. This happens for me on 32-bit Linux on both SAGE-2.6 vanilla and my latest SAGE-2.7 devel tree.

  cdef propos_name(object obj, object hist, object names, object matches):
     objid = <int>(<void*> obj) # id(obj)
     if PyDict_Contains(names, objid):
         return <object>PyDict_GetItem(names, objid)
     hist_record = <object>PyDict_GetItem(hist, objid)
     parent_name = apropos_name(<object>PyTuple_GetItem(hist_record, 1), hist, names, matches)
     name = parent_name + '.' + <object>PyTuple_GetItem(hist_record, 2)
     PyList_Append(matches, (name, obj))
     PyDict_SetItem(names, objid, name)
     return name
  1. The style of the above code surprises me. The whole point of Pyrex (and me choosing Pyrex for SAGE) is so that one never ever has to write code like that. Do you really think it is actually significantly more readable or faster? I personally find the following, which is equivalent, more readable:

    cdef propos_name(obj, hist, names, matches): objid = (<void*> obj) # id(obj) if objid in names: return names[objid] hist_record = hist[objid] parent_name = apropos_name(hist_record[1], hist, names, matches) name = parent_name + '.' + hist_record[2] matches.append((name, obj)) names[objid] = name return name

    -- William

williamstein commented 16 years ago
comment:5

NOT ready -- Nick never addressed my comments from "06/29/2007 09:52:03 PM". The code is unpleasant (in many ways) since it directly is written against the python/c api instead of using Cython as it should be used. Also, I got that segfault (though I haven't retested this).

85eec1a4-3d04-4b4d-b711-d4db03337c41 commented 16 years ago
comment:6

Nick said:

At some point I will resubmit -- I'm just too busy right now.  I  
don't know what invalidate means but I'd appreciate it if the ticket  
(and the patch!) stayed in TRAC. 

Cheers,

Michael

93749b3a-c0a4-47a7-b178-004ba08b0b97 commented 16 years ago
comment:7

Sorry William,

Your comments are all valid. Segfaults of course can't be applied :)

The unorthodox style (calling the C Python API directly) decreases the runtime by a large constant factor -- more than 10 times on my old machine. I'll rewrite against Cython and not worry about that last constant factor.

Soon :)

Nick

mwhansen commented 11 years ago
comment:11

I think we can mark this as invalid / wontfix since I can't access the bundle. For something similar, see the Python package "grasp".

fchapoton commented 6 years ago
comment:16

Let us get rid of this very old ticket.

videlec commented 6 years ago
comment:17

closing positively reviewed duplicates