Ticket #7977: trac_7977-math-block.patch

File trac_7977-math-block.patch, 15.8 KB (added by mvngu, 3 years ago)

based on Sage 4.3.1.rc0

  • doc/en/developer/conventions.rst

    # HG changeset patch
    # User Minh Van Nguyen <nguyenminh2@gmail.com>
    # Date 1263824332 28800
    # Node ID 5ee55fff04cc159a812b3c4a318443a039bea808
    # Parent  33c04bb5aea0255c4fac02782a9974deaf33f1ce
    trac 7977: explain how to use the MATH block and automatic numbering with hash-dot
    
    diff -r 33c04bb5aea0 -r 5ee55fff04cc doc/en/developer/conventions.rst
    a b  
    5555.. You are encouraged 
    5656   to include miscellaneous notes, emails, design 
    5757   discussions, etc., in your package.  Make these 
    58    plain text files (with extension ``.txt``)  
     58   plain text files (with extension ``.txt``) 
    5959   in a subdirectory called ``notes``.  (For example, see 
    6060   ``SAGE_ROOT/devel/sage/sage/ext/notes/``.) 
    6161 
     
    8181 
    8282    r""" 
    8383    <Very short 1-line summary> 
    84      
     84 
    8585    <Paragraph description> 
    8686    ... 
    87      
    88     AUTHORS:  
    89          
     87 
     88    AUTHORS: 
     89 
    9090    - YOUR NAME (2005-01-03): initial version 
    91      
    92     - person (date in ISO year-month-day format): short desc 
    93      
    94     ...  
    9591 
    9692    - person (date in ISO year-month-day format): short desc 
    97      
     93 
    9894    ... 
    99      
     95 
     96    - person (date in ISO year-month-day format): short desc 
     97 
     98    ... 
     99 
    100100    Lots and lots of examples. 
    101101    """ 
    102      
     102 
    103103    #***************************************************************************** 
    104104    #       Copyright (C) 2008 YOUR NAME <your email> 
    105105    # 
     
    117117 
    118118    """ 
    119119    Elements of the ring m`\ZZ` of integers 
    120      
     120 
    121121    AUTHORS: 
    122      
     122 
    123123    - William Stein (2005): initial version 
    124      
     124 
    125125    - Gonzalo Tornaria (2006-03-02): vastly improved python/GMP 
    126126      conversion; hashing 
    127      
     127 
    128128    - Didier Deshommes (2006-03-06): numerous examples 
    129129      and docstrings 
    130      
     130 
    131131    - William Stein (2006-03-31): changes to reflect GMP bug fixes 
    132      
     132 
    133133    - William Stein (2006-04-14): added GMP factorial method (since it's 
    134134      now very fast). 
    135      
     135 
    136136    - David Harvey (2006-09-15): added nth_root, exact_log 
    137      
     137 
    138138    - David Harvey (2006-09-16): attempt to optimise Integer constructor 
    139      
     139 
    140140    - Rishikesh (2007-02-25): changed quo_rem so that the rem is positive 
    141      
     141 
    142142    - David Harvey, Martin Albrecht, Robert Bradshaw (2007-03-01): 
    143143      optimized Integer constructor and pool 
    144      
     144 
    145145    - Pablo De Napoli (2007-04-01): multiplicative_order should return 
    146146      +infinity for non zero numbers 
    147      
     147 
    148148    - Robert Bradshaw (2007-04-12): is_perfect_power, Jacobi symbol (with 
    149149      Kronecker extension).  Convert some methods to use GMP directly 
    150150      rather than pari, Integer(), PY_NEW(Integer) 
    151      
     151 
    152152    - David Roe (2007-03-21): sped up valuation and is_square, added 
    153153      val_unit, is_power, is_power_of and divide_knowing_divisible_by 
    154      
     154 
    155155    - Robert Bradshaw (2008-03-26): gamma function, multifactorials 
    156      
     156 
    157157    - Robert Bradshaw (2008-10-02): bounded squarefree part 
    158      
     158 
    159159    EXAMPLES: 
    160      
     160 
    161161    Add 2 integers:: 
    162      
     162 
    163163        sage: a = Integer(3) ; b = Integer(4) 
    164164        sage: a + b == 7 
    165165        True 
    166      
     166 
    167167    Add an integer and a real number:: 
    168      
     168 
    169169        sage: a + 4.0 
    170170        7.00000000000000 
    171      
     171 
    172172    Add an integer and a rational number:: 
    173      
     173 
    174174        sage: a + Rational(2)/5 
    175175        17/5 
    176      
     176 
    177177    Add an integer and a complex number:: 
    178      
     178 
    179179        sage: b = ComplexField().0 + 1.5 
    180180        sage: loads((a+b).dumps()) == a+b 
    181181        True 
    182      
     182 
    183183    :: 
    184      
     184 
    185185        sage: z = 32 
    186186        sage: -z 
    187187        -32 
     
    191191        0 
    192192        sage: z = -1; -z 
    193193        1 
    194      
     194 
    195195    Multiplication:: 
    196      
     196 
    197197        sage: a = Integer(3) ; b = Integer(4) 
    198198        sage: a * b == 12 
    199199        True 
     
    201201        True 
    202202        sage: a * Rational(2)/5 
    203203        6/5 
    204      
     204 
    205205    :: 
    206      
     206 
    207207        sage: list([2,3]) * 4 
    208208        [2, 3, 2, 3, 2, 3, 2, 3] 
    209      
     209 
    210210    :: 
    211      
     211 
    212212        sage: 'sage'*Integer(3) 
    213213        'sagesagesage' 
    214      
     214 
    215215    COERCIONS: Returns version of this integer in the multi-precision 
    216216    floating real field R. 
    217      
     217 
    218218    :: 
    219      
     219 
    220220        sage: n = 9390823 
    221221        sage: RR = RealField(200) 
    222222        sage: RR(n) 
     
    255255----------------- 
    256256 
    257257**Every** function must have a docstring that includes the 
    258 following information: 
     258following information. Source files in the Sage library contain 
     259numerous examples on how to format your documentation, so you could 
     260use them as a guide. 
    259261 
    260262 
    261263-  A one-sentence description of the function, followed by a blank 
     
    265267   below for format). The type names should be descriptive, but do not 
    266268   have to represent the exact Sage/Python types. For example, use 
    267269   "integer" for anything that behaves like an integer; you do not 
    268    have to put a precise type name such as ``int``. 
     270   have to put a precise type name such as ``int``. The INPUT block 
     271   describes the expected input to your function or method, while the 
     272   OUTPUT block describes the expected output of the 
     273   function/method. If appropriate, you need to describe any default 
     274   values for the input arguments. For example:: 
     275 
     276       INPUT: 
     277 
     278       - ``p`` -- (default: 2) a positive prime integer. 
     279 
     280       OUTPUT: 
     281 
     282       A 5-tuple consisting of integers in this order: 
     283 
     284       1. the smallest primitive root modulo p 
     285       2. the smallest prime primitive root modulo p 
     286       3. the largest primitive root modulo p 
     287       4. the largest prime primitive root modulo p 
     288       5. total number of prime primitive roots modulo p 
     289 
     290   Some people prefer to format their OUTPUT section as a block by 
     291   using a dash. That is acceptable as well:: 
     292 
     293       OUTPUT: 
     294 
     295       - The plaintext resulting from decrypting the ciphertext ``C`` 
     296         using the Blum-Goldwasser decryption algorithm. 
    269297 
    270298-  Instead of INPUT and OUTPUT blocks, you can include descriptions of 
    271299   the arguments and output using Sphinx/ReST markup, as described in 
     
    279307 
    280308-  An ALGORITHM block (optional) which indicates what software 
    281309   and/or what algorithm is used. For example 
    282    ``ALGORITHM: Uses Pari``. 
     310   ``ALGORITHM: Uses Pari``. Here's a longer example that describes an 
     311   algorithm used. Note that it also cites the reference where this 
     312   algorithm can be found:: 
     313 
     314       ALGORITHM: 
     315 
     316       The following algorithm is adapted from page 89 of [Nat2000]_. 
     317 
     318       Let `p` be an odd (positive) prime and let `g` be a generator 
     319       modulo `p`. Then `g^k` is a generator modulo `p` if and only if 
     320       `\gcd(k, p-1) = 1`. Since `p` is an odd prime and positive, then 
     321       `p - 1` is even so that any even integer between 1 and `p - 1`, 
     322       inclusive, is not relatively prime to `p - 1`. We have now 
     323       narrowed our search to all odd integers `k` between 1 and `p - 1`, 
     324       inclusive. 
     325 
     326       So now start with a generator `g` modulo an odd (positive) prime 
     327       `p`. For any odd integer `k` between 1 and `p - 1`, inclusive, 
     328       `g^k` is a generator modulo `p` if and only if `\gcd(k, p-1) = 1`. 
     329 
     330       REFERENCES: 
     331 
     332       .. [Nat2000] M.B. Nathanson. Elementary Methods in Number Theory. 
     333         Springer, 2000. 
     334 
     335   You can also number the steps in your algorithm using the hash-dot 
     336   symbol. This way, the actual numbering of the steps are 
     337   automatically taken care of when you build the documentation:: 
     338 
     339        ALGORITHM: 
     340 
     341        The Blum-Goldwasser decryption algorithm is described in Algorithm 
     342        8.56, page 309 of [MenezesEtAl1996]_. The algorithm works as follows: 
     343 
     344        #. Let `C` be the ciphertext `C = (c_1, c_2, \dots, c_t, x_{t+1})`. 
     345           Then `t` is the number of ciphertext sub-blocks and `h` is the 
     346           length of each binary string sub-block `c_i`. 
     347        #. Let `(p, q, a, b)` be the private key whose corresponding 
     348           public key is `n = pq`. Note that `\gcd(p, q) = ap + bq = 1`. 
     349        #. Compute `d_1 = ((p + 1) / 4)^{t+1} \bmod{(p - 1)}`. 
     350        #. Compute `d_2 = ((q + 1) / 4)^{t+1} \bmod{(q - 1)}`. 
     351        #. Let `u = x_{t+1}^{d_1} \bmod p`. 
     352        #. Let `v = x_{t+1}^{d_2} \bmod q`. 
     353        #. Compute `x_0 = vap + ubq \bmod n`. 
     354        #. For `i` from 1 to `t`, do: 
     355 
     356           #. Compute `x_i = x_{t-1}^2 \bmod n`. 
     357           #. Let `p_i` be the `h` least significant bits of `x_i`. 
     358           #. Compute `m_i = p_i \oplus c_i`. 
     359 
     360        #. The plaintext is `m = m_1 m_2 \cdots m_t`. 
    283361 
    284362-  A NOTES block for special notes (optional). Include information 
    285    such as purpose etc. 
     363   such as purpose etc. A NOTES block should start with 
     364   ``.. NOTE::``. You can also use the lower-case version 
     365   ``.. note::``, but do not mix lower-case with upper-case. However, 
     366   you are encouraged to use the upper-case version ``.. NOTE::``. If 
     367   you want to put anything within the NOTES block, you should 
     368   indent it at least 4 spaces (no tabs). Here's an example of a NOTES 
     369   block:: 
     370 
     371       .. NOTE:: 
     372 
     373           You should note that this sentence is indented at least 4 
     374           spaces. Avoid tab characters as much as possible when 
     375           writing code or editing the Sage documentation. You should 
     376           follow Python conventions by using spaces only. 
     377 
     378- A WARNING block for critical information about your code. For 
     379  example, the WARNING block might include information about when or 
     380  under which conditions your code might break, or information that 
     381  the user should be particularly aware of. A WARNING block should start 
     382  with ``.. WARNING::``. It can also be the lower-case form 
     383  ``.. warning::``. However, you are encouraged to use the upper-case 
     384  form ``.. WARNING::``. Here's an example of a WARNING block:: 
     385 
     386      .. WARNING:: 
     387 
     388          Whenever you edit the Sage documentation, make sure that 
     389          the edited version still builds. That is, you need to ensure 
     390          that you can still build the HTML and PDF versions of the 
     391          updated documentation. If the edited documentation fails to 
     392          build, it is very likely that you would be requested to 
     393          change your patch. 
    286394 
    287395- A REFERENCES block to list books or papers (optional). This block serves 
    288   a similar purpose to a list of references in a research paper, or a  
     396  a similar purpose to a list of references in a research paper, or a 
    289397  bibliography in a monograph. If your method, function or class uses an 
    290398  algorithm that can be found in a standard reference, you should list 
    291399  that reference under this block. The Sphinx/ReST markup for 
     
    303411    def point(self, x=1, y=2): 
    304412        r""" 
    305413        This function returns the point `(x^5,y)`. 
    306      
     414 
    307415        INPUT: 
    308416 
    309417         - ``x`` - integer (default: 1) the description of the 
    310418           argument x goes here.  If it contains multiple lines, all 
    311419           the lines after the first need to be indented. 
    312              
     420 
    313421         - ``y`` - integer (default: 2) the ... 
    314      
     422 
    315423        OUTPUT: 
    316424 
    317425        integer -- the ... 
    318      
     426 
    319427        EXAMPLES: 
    320428 
    321429        This example illustrates ... 
     
    325433            sage: A = ModuliSpace() 
    326434            sage: A.point(2,3) 
    327435            xxx 
    328      
     436 
    329437        We now ... 
    330438 
    331439        :: 
    332440 
    333441            sage: B = A.point(5,6) 
    334442            sage: xxx 
    335      
     443 
    336444        It is an error to ...:: 
    337445 
    338446            sage: C = A.point('x',7) 
    339447            Traceback (most recent call last): 
    340448            ... 
    341449            TypeError: unable to convert x (=r) to an integer 
    342      
     450 
    343451        NOTES: 
    344              
     452 
    345453        This function uses the algorithm of [BCDT]_ to determine 
    346454        whether an elliptic curve E over Q is modular. 
    347      
     455 
    348456        ... 
    349      
     457 
    350458        REFERENCES: 
    351           
     459 
    352460        .. [BCDT] Breuil, Conrad, Diamond, Taylor, "Modularity ...." 
    353      
    354         AUTHORS:  
    355          
     461 
     462        AUTHORS: 
     463 
    356464        - William Stein (2005-01-03) 
    357          
     465 
    358466        - First_name Last_name (yyyy-mm-dd) 
    359467        """ 
    360468        <body of the function> 
     
    365473    def point(self, x=1, y=2): 
    366474        r""" 
    367475        This function returns the point `(x^5,y)`. 
    368      
     476 
    369477        :param x: the description of the argument x goes here. 
    370478           If it contains multiple lines, all the lines after the 
    371479           first need to be indented. 
     
    392500           """ 
    393501           Returns `\\cos(x)`. 
    394502           """ 
    395         
     503 
    396504       def sin(x): 
    397505           r""" 
    398506           Returns `\sin(x)`. 
    399507           """ 
    400508 
     509   You can also use the MATH block to format complicated mathematical 
     510   expressions:: 
     511 
     512       .. MATH:: 
     513 
     514           \sum_{i=1}^{\infty} (a_1 a_2 \cdots a_i)^{1/i} 
     515           \leq 
     516           e \sum_{i=1}^{\infty} a_i 
     517 
    401518   .. note:: 
    402519 
    403520      In ReST documentation, you use backticks \` to mark LaTeX code 
     
    472589        Create a Hill cryptosystem defined by the `m` x `m` matrix space 
    473590        over `\mathbf{Z} / N \mathbf{Z}`, where `N` is the alphabet size of 
    474591        the string monoid ``S``. 
    475      
     592 
    476593        INPUT: 
    477      
     594 
    478595        - ``S`` - a string monoid over some alphabet 
    479      
     596 
    480597        - ``m`` - integer `> 0`; the block length of matrices that specify 
    481598          block permutations 
    482      
     599 
    483600        OUTPUT: 
    484      
     601 
    485602        - A Hill cryptosystem of block length ``m`` over the alphabet ``S``. 
    486      
     603 
    487604        EXAMPLES:: 
    488      
     605 
    489606            sage: S = AlphabeticStrings() 
    490607            sage: E = HillCryptosystem(S,3) 
    491608            sage: E 
     
    508625   (Before Sage 3.4, the reference manual used to include methods 
    509626   starting with underscores, so you will probably find many examples 
    510627   in the code which don't follow this advice...) 
    511              
     628 
    512629 
    513630Automatic Testing 
    514631----------------- 
     
    517634that if the above code is in the file ``f.py`` (or 
    518635``f.sage``), then ``sage -t f.py`` should not give any 
    519636error messages. Testing occurs with full Sage preparsing of input 
    520 within the standard Sage shell environment, as described in  
     637within the standard Sage shell environment, as described in 
    521638:ref:`section-preparsing`. **Important:** The file ``f.py`` is not imported 
    522639when running tests unless you have arranged that it be imported 
    523640into your Sage environment, i.e., unless its functions are 
     
    550667-  All input is preparsed before being passed to Python, e.g., 
    551668   ``2/3`` is replaced by ``Integer(2)/Integer(3)``, which evaluates 
    552669   to ``2/3`` as a rational instead of the Python int 
    553    ``0``. For more information on preparsing, see  
     670   ``0``. For more information on preparsing, see 
    554671   :ref:`section-preparsing`. 
    555672 
    556673-  If a test outputs to a file, the file should be in a temporary 
     
    559676 
    560677        sage: fig.savefig(os.path.join(SAGE_TMP, 'test.png')) 
    561678 
    562    Here ``fig.savefig`` is the function doing the saving,  
     679   Here ``fig.savefig`` is the function doing the saving, 
    563680   ``SAGE_TMP`` is a temporary directory -- this variable will always 
    564681   be defined properly during automated testing -- and ``os.path.join`` is 
    565682   the preferred way to construct a path from a directory and a file: 
     
    634751           sage: E = EllipticCurve(GF(41),[2,5]) 
    635752           sage: E._magma_init_() # optional - requires Magma 
    636753           'EllipticCurve([...|GF(41)!0,GF(41)!0,GF(41)!0,GF(41)!2,GF(41)!5])' 
    637     
     754 
    638755 
    639756-  If the entire documentation string contains all three words 
    640757   ``optional``, ``package``, and ``installed``, 
     
    674791 
    675792:: 
    676793 
    677       sage -t [--verbose] [--optional]  [files and directories ... ]  
     794      sage -t [--verbose] [--optional]  [files and directories ... ] 
    678795 
    679796When you run ``sage -t <filename.py>``, Sage makes a copy of 
    680797``<filename.py>`` with all the ``sage`` prompts 
     
    718835    :: 
    719836 
    720837            sage: a = 1 
    721              
     838 
    722839 
    723840    Next we add 1 to ``a``. 
    724841 
     
    728845 
    729846            sage: 1 + a 
    730847            2 
    731              
     848 
    732849You can also put ``.. skip::`` right before a verbatim 
    733850environment to have that example skipped when testing the file.  This 
    734851goes right in the same place as the ``.. link::`` in the previous 
    735 example.  
     852example. 
    736853 
    737854See the files in ``SAGE_ROOT/devel/sage/doc/en/tutorial/`` for many 
    738855examples of how to include automated testing in ReST documentation