Skip to content

Commit 0b3cc93

Browse files
authored
Merge pull request #985 from mathics/doc-fixes3
Title Capitalization; StringInsert examples
2 parents 14b6528 + 4a15095 commit 0b3cc93

File tree

7 files changed

+38
-55
lines changed

7 files changed

+38
-55
lines changed

mathics/builtin/integer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
Integer functions
5+
Integer Functions
66
"""
77

88

mathics/builtin/numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
"""
7-
Numeric evaluation
7+
Numeric Evaluation
88
99
Support for numeric evaluation with arbitrary precision is just a proof-of-concept.
1010
Precision is not "guarded" through the evaluation process. Only integer precision is supported.

mathics/builtin/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
Options and default arguments
5+
Options and Default Arguments
66
"""
77

88
from mathics.builtin.base import Builtin, Test

mathics/builtin/patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
Patterns and rules
5+
Patterns and Rules
66
77
Some examples:
88
>> a + b + c /. a + b -> t

mathics/builtin/strings.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,33 +2471,17 @@ class StringInsert(Builtin):
24712471
<dd>inserts a copy of $snew$ at each position $n_i$ in $string$;
24722472
the $n_i$ are taken before any insertion is done.
24732473
2474-
<dt>'StringInsert[{$str_1$, $str_2$, ...}, "$snew$", $n$]'
2474+
<dt>'StringInsert[{$s_1$, $s_2$, ...}, "$snew$", $n$]'
24752475
<dd>gives the list of resutls for each of the $s_i$.
24762476
</dl>
24772477
2478-
## FIXME: Below are way too many examples to be of interest for
2479-
## general use. Strip this down to just essentials
2480-
## put the rest in a pytest.
2481-
2482-
>> StringInsert["abcdefghijklm", "X", 4]
2483-
= abcXdefghijklm
2484-
2485-
>> StringInsert["abcdefghijklm", "X", 1]
2486-
= Xabcdefghijklm
2487-
2488-
>> StringInsert["abcdefghijklm", "X", 14]
2489-
= abcdefghijklmX
2478+
>> StringInsert["noting", "h", 4]
2479+
= nothing
24902480
24912481
#> StringInsert["abcdefghijklm", "X", 15]
24922482
: Cannot insert at position 15 in abcdefghijklm.
24932483
= StringInsert[abcdefghijklm, X, 15]
24942484
2495-
#> StringInsert["", "X", 1]
2496-
= X
2497-
2498-
#> StringInsert["abcdefghijklm", "", 1]
2499-
= abcdefghijklm
2500-
25012485
#> StringInsert[abcdefghijklm, "X", 4]
25022486
: String or list of strings expected at position 1 in StringInsert[abcdefghijklm, X, 4].
25032487
= StringInsert[abcdefghijklm, X, 4]
@@ -2514,24 +2498,18 @@ class StringInsert(Builtin):
25142498
: Cannot insert at position 0 in abcdefghijklm.
25152499
= StringInsert[abcdefghijklm, X, 0]
25162500
2517-
>> StringInsert["abcdefghijklm", "X", -1]
2518-
= abcdefghijklmX
2501+
>> StringInsert["note", "d", -1]
2502+
= noted
25192503
2520-
>> StringInsert["abcdefghijklm", "X", -14]
2521-
= Xabcdefghijklm
2504+
>> StringInsert["here", "t", -5]
2505+
= there
25222506
25232507
#> StringInsert["abcdefghijklm", "X", -15]
25242508
: Cannot insert at position -15 in abcdefghijklm.
25252509
= StringInsert[abcdefghijklm, X, -15]
25262510
2527-
#> StringInsert["", "X", -1]
2528-
= X
2529-
2530-
#> StringInsert["abcdefghijklm", "", -1]
2531-
= abcdefghijklm
2532-
2533-
>> StringInsert["abcdefghijklm", "X", {1, 4, 9}]
2534-
= XabcXdefghXijklm
2511+
>> StringInsert["adac", "he", {1, 5}]
2512+
= headache
25352513
25362514
#> StringInsert["abcdefghijklm", "X", {1, -1, 14, -14}]
25372515
= XXabcdefghijklmXX
@@ -2559,8 +2537,8 @@ class StringInsert(Builtin):
25592537
#> StringInsert["abcdefghijklm", "X", {}]
25602538
= abcdefghijklm
25612539
2562-
>> StringInsert[{"abcdefghijklm", "Mathics"}, "X", 4]
2563-
= {abcXdefghijklm, MatXhics}
2540+
>> StringInsert[{"something", "sometimes"}, " ", 5]
2541+
= {some thing, some times}
25642542
25652543
#> StringInsert[{"abcdefghijklm", "Mathics"}, "X", 13]
25662544
: Cannot insert at position 13 in Mathics.
@@ -2581,9 +2559,6 @@ class StringInsert(Builtin):
25812559
#> StringInsert[{"", "Mathics"}, "X", {1, 1, -1}]
25822560
= {XXX, XXMathicsX}
25832561
2584-
#> StringInsert[{"abcdefghijklm", "Mathics"}, "X", {}]
2585-
= {abcdefghijklm, Mathics}
2586-
25872562
>> StringInsert["1234567890123456", ".", Range[-16, -4, 3]]
25882563
= 1.234.567.890.123.456 """
25892564

mathics/doc/documentation/1-Manual.mdoc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Some of the most important features of \Mathics are
3535
<section title="What is missing?">
3636
There are lots of ways in which \Mathics could still be improved.
3737

38-
Most notably, performance is still slow, so any serious usage in cutting-edge industry or research will fail, unfortunately. Although Cython can be used to speed up parts of \Mathics, more is needed to speed up pattern matching. Replacing recusion with iteration may help here.
38+
Most notably, performance is still slow, so any serious usage in cutting-edge industry or research will fail, unfortunately. Although Cython can be used to speed up parts of \Mathics, more is needed to speed up pattern matching. Replacing recursion with iteration may help here.
3939

4040
Apart from performance issues, new features such as more functions in various mathematical fields like calculus, number theory, or graph theory are still to be added.
4141

@@ -70,11 +70,11 @@ Since installation may change, see <url>https://github.com/mathics/Mathics/wiki/
7070
</chapter>
7171

7272

73-
<chapter title="Language tutorials">
73+
<chapter title="Language Tutorials">
7474

75-
The following sections are introductions to the basic principles of the language of \Mathics. A few examples and functions are presented. Only their most common usages are listed; for a full description of their possible arguments, options, etc., see their entry in the Reference of built-in symbols.
75+
The following sections are introductions to the basic principles of the language of \Mathics. A few examples and functions are presented. Only their most common usages are listed; for a full description of a Symbols possible arguments, options, etc., see its entry in the Reference of Built-in Symbols.
7676

77-
However if you google for "Mathematica Tutorials" youw will find easily dozens of other tutorials which are applicable. Be warned though that \Mathics does not yet offer the full range and features and capabilities of \Mathematica.
77+
However if you google for "Mathematica Tutorials" you will find easily dozens of other tutorials which are applicable. Be warned though that \Mathics does not yet offer the full range and features and capabilities of \Mathematica.
7878

7979
<section title="Basic calculations">
8080
\Mathics can be used to calculate basic stuff:
@@ -156,7 +156,7 @@ The result of the previous query to \Mathics can be accessed by '%':
156156
= 49
157157
</section>
158158

159-
<section title="Symbols and assignments">
159+
<section title="Symbols and Assignments">
160160
Symbols need not be declared in \Mathics, they can just be entered and remain variable:
161161
>> x
162162
= x
@@ -195,7 +195,7 @@ Such a dependency can be achieved by using "delayed assignment" with the ':=' op
195195
</section>
196196

197197

198-
<section title="Comparisons and Boolean logic">
198+
<section title="Comparisons and Boolean Logic">
199199
Values can be compared for equality using the operator '==':
200200
>> 3 == 3
201201
= True
@@ -223,7 +223,7 @@ Truth values can be negated using '!' (logical <em>not</em>) and combined using
223223
</section>
224224

225225
<section title="Strings">
226-
Strings can be entered with '"' as delimeters:
226+
Strings can be entered with '"' as delimiters:
227227
>> "Hello world!"
228228
= Hello world!
229229
As you can see, quotation marks are not printed in the output by default. This can be changed by using 'InputForm':
@@ -320,7 +320,7 @@ It is an error to combine lists with unequal lengths:
320320
= {1, 2} + {4, 5, 6}
321321
</section>
322322

323-
<section title="The structure of things">
323+
<section title="The Structure of Things">
324324
Every expression in \Mathics is built upon the same principle: it consists of a <em>head</em> and an arbitrary number of <em>children</em>, unless it is an <em>atom</em>, i.e. it can not be subdivided any further. To put it another way: everything is a function call. This can be best seen when displaying expressions in their "full form":
325325
>> FullForm[a + b + c]
326326
= Plus[a, b, c]
@@ -390,7 +390,7 @@ But
390390
because '3' (an 'Integer') and '3.0' (a 'Real') are structurally different.
391391
</section>
392392

393-
<section title="Functions and patterns">
393+
<section title="Functions and Patterns">
394394
Functions can be defined in the following way:
395395
>> f[x_] := x ^ 2
396396
This tells \Mathics to replace every occurrence of 'f' with one (arbitrary) parameter 'x' with 'x ^ 2'.
@@ -468,7 +468,7 @@ While 'ReplaceAll' and 'ReplaceRepeated' simply take the first possible match in
468468
>> ReplaceAll[{a, b, c}, {___, x__, ___} -> {x}]
469469
= {a}
470470

471-
In addition to defining functions as rules for certain patterns, there are <em>pure</em> functions that can be defined using the '&' postfix operator, where everything before it is treated as the funtion body and '#' can be used as argument placeholder:
471+
In addition to defining functions as rules for certain patterns, there are <em>pure</em> functions that can be defined using the '&' postfix operator, where everything before it is treated as the function body and '#' can be used as argument placeholder:
472472
>> h = # ^ 2 &;
473473
>> h[3]
474474
= 9
@@ -494,7 +494,7 @@ Functions can be applied using prefix or postfix notation, in addition to using
494494
= 9
495495
</section>
496496

497-
<section title="Control statements">
497+
<section title="Control Statements">
498498
Like most programming languages, \Mathics has common control statements for conditions, loops, etc.:
499499
<dl>
500500
<dt>'If[$cond$, $pos$, $neg$]'
@@ -590,7 +590,7 @@ It is common to use scoping constructs for function definitions with local varia
590590
= 3628800
591591
</section>
592592

593-
<section title="Formatting output">
593+
<section title="Formatting Output">
594594
The way results are formatted for output in \Mathics is rather sophisticated, as compatibility to the way \Mathematica does things is one of the design goals. It can be summed up in the following procedure:
595595
<ol>
596596
<li>The result of the query is calculated.
@@ -714,7 +714,7 @@ The desired effect can be achieved in the following way:
714714
You can view the box structure of a formatted expression using 'ToBoxes':
715715
>> ToBoxes[m + n]
716716
= RowBox[{m, +, n}]
717-
The list elements in this 'RowBox' are strings, though string delimeters are not shown in the default output form:
717+
The list elements in this 'RowBox' are strings, though string delimiters are not shown in the default output form:
718718
>> InputForm[%]
719719
= RowBox[{"m", "+", "n"}]
720720
</section>
@@ -842,7 +842,7 @@ And test the second derivative:
842842
>> f''[x] /. extremes // N
843843
= {1.65086, -0.064079}
844844
Thus, there is a local maximum at 'x = Sqrt[5]' and a local minimum at 'x = -Sqrt[5]'.
845-
Compute the inflection points numerically, choping imaginary parts close to 0:
845+
Compute the inflection points numerically, chopping imaginary parts close to 0:
846846
>> inflections = Solve[f''[x] == 0, x] // N // Chop
847847
= {{x -> -1.0852}, {x -> -3.21463}, {x -> 4.29983}}
848848
Insert into the third derivative:
@@ -1045,7 +1045,7 @@ There are some keyboard commands you can use in the Django-based Web interface o
10451045
<dt>'Ctrl+D'</dt>
10461046
<dd>This moves the cursor over to the documentation pane on the right-hand side. From here you can preform a search for a pre-defined \Mathics function, or symbol. Clicking on the "?" symbol on the right-hand side does the same thing.</dd>
10471047
<dt>'Ctrl+C'</dt>
1048-
<dd>This moves the curser back to document code pane area where you type \Mathics expressions</dd>
1048+
<dd>This moves the cursor back to document code pane area where you type \Mathics expressions</dd>
10491049
<dt>'Ctrl+S'</dt>
10501050
<dd>Save worksheet</dd>
10511051
<dt>'Ctrl+O'</dt>

test/test_evaluation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def _evaluate(str_expression):
3939
# This doesn't work if not logged or in some OS's
4040
# (r"Head[$UserName]", "String"),
4141
(r"Head[$Version]", "String"),
42+
# Strings and Characters
43+
(r'StringInsert["abcdefghijklm", "X", 1]', r'"Xabcdefghijklm"'),
44+
(r'StringInsert["abcdefghijklm", "X", 14]', r'"abcdefghijklmX"'),
45+
(r'StringInsert["abcdefghijklm", "", 1]', r'"abcdefghijklm"'),
46+
(r'StringInsert["", "X", 1]', r'"X"'),
47+
(r'StringInsert["", "X", -1]', r'"X"'),
48+
(r'StringInsert["abcdefghijklm", "", -1]', r'"abcdefghijklm"'),
49+
(r'StringInsert[{"abcdefghijklm", "Mathics"}, "X", {}]', r'{"abcdefghijklm", "Mathics"}'),
4250
],
4351
)
4452
def test_evaluation(str_expr: str, str_expected: str, message=""):

0 commit comments

Comments
 (0)