Skip to content

Commit 9893cf4

Browse files
Make the Lab's notebooks the sample notebooks (#2110)
AngouriMathLab's try branch had an F# tutorial of 38 code cells -- building and parsing expressions, substitution, calculus with its shortcuts, vectors, matrices, sets, the aggressive operators and a surface plot -- and a C# example, both against the current API, where the samples here had five cells each. The F# tutorial is Interactive.Sample.ipynb now, so the README's links and the Binder button open it, and the C# sample is the Lab's example followed by the three cells of the old sample it did not have. Outputs are stripped, the MyGet feed the Lab used is gone, and the tutorial's Try link builds from here. Executed with nbconvert in the binder/Dockerfile image: every cell of both runs, in 14 and 5 seconds. The F# one's first cell prints the C# compile error of #2109 and carries on. Part of #1689. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent a849c99 commit 9893cf4

3 files changed

Lines changed: 636 additions & 209 deletions

File tree

‎Sources/Samples/CSharp.Interactive.Sample.ipynb‎

Lines changed: 86 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,130 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# C# example for AngouriMath\n",
8+
"\n",
9+
"While [AngouriMath.Interactive](https://www.nuget.org/packages/AngouriMath.Interactive) is recommended for research purposes, you can also use the default AngouriMath package in C# within interactive environment."
10+
]
11+
},
312
{
413
"cell_type": "code",
5-
"execution_count": 1,
614
"metadata": {},
7-
"outputs": [
8-
{
9-
"data": {
10-
"text/html": [
11-
"\r\n",
12-
"<div>\r\n",
13-
" <div id='dotnet-interactive-this-cell-18492.Microsoft.DotNet.Interactive.Http.HttpPort' style='display: none'>\r\n",
14-
" The below script needs to be able to find the current output cell; this is an easy method to get it.\r\n",
15-
" </div>\r\n",
16-
" <script type='text/javascript'>\r\n",
17-
"async function probeAddresses(probingAddresses) {\r\n",
18-
" function timeout(ms, promise) {\r\n",
19-
" return new Promise(function (resolve, reject) {\r\n",
20-
" setTimeout(function () {\r\n",
21-
" reject(new Error('timeout'))\r\n",
22-
" }, ms)\r\n",
23-
" promise.then(resolve, reject)\r\n",
24-
" })\r\n",
25-
" }\r\n",
26-
"\r\n",
27-
" if (Array.isArray(probingAddresses)) {\r\n",
28-
" for (let i = 0; i < probingAddresses.length; i++) {\r\n",
29-
"\r\n",
30-
" let rootUrl = probingAddresses[i];\r\n",
31-
"\r\n",
32-
" if (!rootUrl.endsWith('/')) {\r\n",
33-
" rootUrl = `${rootUrl}/`;\r\n",
34-
" }\r\n",
35-
"\r\n",
36-
" try {\r\n",
37-
" let response = await timeout(1000, fetch(`${rootUrl}discovery`, {\r\n",
38-
" method: 'POST',\r\n",
39-
" cache: 'no-cache',\r\n",
40-
" mode: 'cors',\r\n",
41-
" timeout: 1000,\r\n",
42-
" headers: {\r\n",
43-
" 'Content-Type': 'text/plain'\r\n",
44-
" },\r\n",
45-
" body: probingAddresses[i]\r\n",
46-
" }));\r\n",
47-
"\r\n",
48-
" if (response.status == 200) {\r\n",
49-
" return rootUrl;\r\n",
50-
" }\r\n",
51-
" }\r\n",
52-
" catch (e) { }\r\n",
53-
" }\r\n",
54-
" }\r\n",
55-
"}\r\n",
56-
"\r\n",
57-
"function loadDotnetInteractiveApi() {\r\n",
58-
" probeAddresses([\"http://192.168.2.16:1000/\", \"http://127.0.0.1:1000/\"])\r\n",
59-
" .then((root) => {\r\n",
60-
" // use probing to find host url and api resources\r\n",
61-
" // load interactive helpers and language services\r\n",
62-
" let dotnetInteractiveRequire = require.config({\r\n",
63-
" context: '18492.Microsoft.DotNet.Interactive.Http.HttpPort',\r\n",
64-
" paths:\r\n",
65-
" {\r\n",
66-
" 'dotnet-interactive': `${root}resources`\r\n",
67-
" }\r\n",
68-
" }) || require;\r\n",
69-
"\r\n",
70-
" window.dotnetInteractiveRequire = dotnetInteractiveRequire;\r\n",
71-
"\r\n",
72-
" window.configureRequireFromExtension = function(extensionName, extensionCacheBuster) {\r\n",
73-
" let paths = {};\r\n",
74-
" paths[extensionName] = `${root}extensions/${extensionName}/resources/`;\r\n",
75-
" \r\n",
76-
" let internalRequire = require.config({\r\n",
77-
" context: extensionCacheBuster,\r\n",
78-
" paths: paths,\r\n",
79-
" urlArgs: `cacheBuster=${extensionCacheBuster}`\r\n",
80-
" }) || require;\r\n",
81-
"\r\n",
82-
" return internalRequire\r\n",
83-
" };\r\n",
84-
" \r\n",
85-
" dotnetInteractiveRequire([\r\n",
86-
" 'dotnet-interactive/dotnet-interactive'\r\n",
87-
" ],\r\n",
88-
" function (dotnet) {\r\n",
89-
" dotnet.init(window);\r\n",
90-
" },\r\n",
91-
" function (error) {\r\n",
92-
" console.log(error);\r\n",
93-
" }\r\n",
94-
" );\r\n",
95-
" })\r\n",
96-
" .catch(error => {console.log(error);});\r\n",
97-
" }\r\n",
98-
"\r\n",
99-
"// ensure `require` is available globally\r\n",
100-
"if ((typeof(require) !== typeof(Function)) || (typeof(require.config) !== typeof(Function))) {\r\n",
101-
" let require_script = document.createElement('script');\r\n",
102-
" require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\r\n",
103-
" require_script.setAttribute('type', 'text/javascript');\r\n",
104-
" \r\n",
105-
" \r\n",
106-
" require_script.onload = function() {\r\n",
107-
" loadDotnetInteractiveApi();\r\n",
108-
" };\r\n",
109-
"\r\n",
110-
" document.getElementsByTagName('head')[0].appendChild(require_script);\r\n",
111-
"}\r\n",
112-
"else {\r\n",
113-
" loadDotnetInteractiveApi();\r\n",
114-
"}\r\n",
115-
"\r\n",
116-
" </script>\r\n",
117-
"</div>"
118-
]
119-
},
120-
"metadata": {},
121-
"output_type": "display_data"
122-
},
123-
{
124-
"name": "stderr",
125-
"output_type": "stream",
126-
"text": [
127-
"\r\n",
128-
"(1,1): error CS0006: Не удалось найти файл метаданных \"nuget:AngouriMath.Interactive, *-*\".\r\n",
129-
"\r\n"
130-
]
131-
},
132-
{
133-
"ename": "Cell not executed",
134-
"evalue": "compilation error",
135-
"output_type": "error",
136-
"traceback": []
137-
}
138-
],
13915
"source": [
14016
"#r \"nuget:AngouriMath, *-*\""
17+
],
18+
"execution_count": null,
19+
"outputs": []
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"### Basics"
14126
]
14227
},
14328
{
14429
"cell_type": "code",
30+
"metadata": {},
31+
"source": [
32+
"Entity expr = \"a2 + sqrt(b) / 6 = 4\";\n",
33+
"expr"
34+
],
14535
"execution_count": null,
36+
"outputs": []
37+
},
38+
{
39+
"cell_type": "code",
14640
"metadata": {},
147-
"outputs": [],
14841
"source": [
149-
"using AngouriMath.Extensions;\n",
150-
"using AngouriMath;"
151-
]
42+
"expr.Solve(\"a\")"
43+
],
44+
"execution_count": null,
45+
"outputs": []
15246
},
15347
{
15448
"cell_type": "code",
49+
"metadata": {},
50+
"source": [
51+
"\"sin(a x) / sqrt(x)\".ToEntity().Differentiate(\"x\")"
52+
],
15553
"execution_count": null,
54+
"outputs": []
55+
},
56+
{
57+
"cell_type": "code",
15658
"metadata": {},
157-
"outputs": [],
15859
"source": [
159-
"\"x2 + sin(sqrt(x + 1/2)) + integral(sqrt(x + derivative(sin(y), y)), x)\".ToEntity()"
60+
"\"a + b\".ToEntity().Substitute(\"a\", 5).Substitute(\"b\", 6).Evaled"
61+
],
62+
"execution_count": null,
63+
"outputs": []
64+
},
65+
{
66+
"cell_type": "code",
67+
"metadata": {},
68+
"source": [
69+
"@\"{ 1, 2 } \\/ RR \\/ [3; +oo)\".ToEntity()"
70+
],
71+
"execution_count": null,
72+
"outputs": []
73+
},
74+
{
75+
"cell_type": "code",
76+
"metadata": {},
77+
"source": [
78+
"var system = MathS.Equations(\n",
79+
" \"a + b\",\n",
80+
" \"sin(b) + c\"\n",
81+
");\n",
82+
"system.Solve(\"a\", \"b\")"
83+
],
84+
"execution_count": null,
85+
"outputs": []
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"metadata": {},
90+
"source": [
91+
"### Expressions, systems and matrices"
16092
]
16193
},
16294
{
16395
"cell_type": "code",
96+
"metadata": {},
97+
"source": [
98+
"\"x2 + sin(sqrt(x + 1/2)) + integral(sqrt(x + derivative(sin(y), y)), x)\".ToEntity()"
99+
],
164100
"execution_count": null,
101+
"outputs": []
102+
},
103+
{
104+
"cell_type": "code",
165105
"metadata": {},
166-
"outputs": [],
167106
"source": [
168107
"var sys = MathS.Equations(\n",
169108
" \"x + 2 - y - y2\",\n",
170109
" \"x / y - sin(z) + 3\",\n",
171110
" \"x - sin(z)\"\n",
172111
");\n",
173112
"sys"
174-
]
113+
],
114+
"execution_count": null,
115+
"outputs": []
175116
},
176117
{
177118
"cell_type": "code",
178-
"execution_count": null,
179119
"metadata": {},
180-
"outputs": [],
181120
"source": [
182121
"MathS.Matrix(new Entity[,]{\n",
183122
"{ \"x / 2\", \"beta - 2^3\", \"e / sqrt(pi)\" },\n",
184123
"{ \"epsilon\", \"integral(sin(k), k)\", \"e - pi\" },\n",
185124
"})"
186-
]
125+
],
126+
"execution_count": null,
127+
"outputs": []
187128
}
188129
],
189130
"metadata": {
@@ -193,11 +134,7 @@
193134
"name": ".net-csharp"
194135
},
195136
"language_info": {
196-
"file_extension": ".cs",
197-
"mimetype": "text/x-csharp",
198-
"name": "C#",
199-
"pygments_lexer": "csharp",
200-
"version": "8.0"
137+
"name": "C#"
201138
}
202139
},
203140
"nbformat": 4,

0 commit comments

Comments
 (0)