On Thu, 21 Aug 2014 09:38:54 -0700 (PDT)
kcrisman <[email protected]> wrote:
> In this class, we don't quite instantiate the nice documentation we
> actually have for TwinPrime
...
> but instead do
> TwinPrime().expression()
> which gets rid of all that useful info. Same for most such constants, I
> believe, so that they are in the symbolic ring/Ginac.
>
> Does anyone have a quick way to fix this? (Maybe even by getting rid of
> .expression() ?) I have wondered about this too but I knew what the twin
> prime constant was so I didn't run into it... but of course Nathann is
> right that this is not that helpful currently.
The quickest fix is probably writing in the documentation of
sage.symbolic.expression.Expression that the user should maybe try
sage: tmp = expression.pyobject()
sage: tmp?
for some more useful information.
Here's what the result would be for twinprime:
sage: tmp = twinprime.pyobject()
sage: tmp?
Type: TwinPrime
String form: twinprime
File:
/home/erik/sage/local/lib/python2.7/site-packages/sage/symbolic/constants.py
Docstring:
The Twin Primes constant is defined as prod 1 - 1/(p-1)^2 for
primes p > 2.
EXAMPLES:
sage: float(twinprime)
0.6601618158468696
sage: twinprime.n(digits=60)
0.660161815846869573927812110014555778432623360284733413319448
Init docstring:
EXAMPLES:
sage: loads(dumps(twinprime))
twinprime
The docstring of sage.symbolic.expression.Expression-objects could also
be dynamically generated. This is done as a proof of concept in the
attached patch. Recursing in docstring generation is maybe not so nice
though. Also you still get the nasty Init and Call documentation from
Expression. The cleanest solution from a docstring-perspective is
probably getting rid of expression().
Is there a ticket for this?
Regards,
Erik Massop
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
>From aae3db519f1ea588b23c6f299d7206e444e2cab2 Mon Sep 17 00:00:00 2001
From: Erik Massop <[email protected]>
Date: Thu, 21 Aug 2014 22:10:24 +0200
Subject: [PATCH] Dynamic docstring for constant expressions
---
src/sage/symbolic/expression.pyx | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx
index 659948b..ee87503 100644
--- a/src/sage/symbolic/expression.pyx
+++ b/src/sage/symbolic/expression.pyx
@@ -203,6 +203,13 @@ cpdef bint is_SymbolicEquation(x):
return isinstance(x, Expression) and is_a_relational((<Expression>x)._gobj)
cdef class Expression(CommutativeRingElement):
+ property __doc__:
+ def __get__(self):
+ if is_a_constant(self._gobj):
+ from sage.symbolic.constants import constants_name_table
+ return constants_name_table[GEx_to_str(&self._gobj)].__doc__
+ return None
+
cpdef object pyobject(self):
"""
Get the underlying Python object.
--
2.0.4