Skip to content

Commit

Permalink
Add manual page for nevaluate and update front web page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Nov 27, 2023
1 parent ecdbaa4 commit c82b8e6
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 3 deletions.
127 changes: 127 additions & 0 deletions core/algorithms/nevaluate.cnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"cell_id": 7056241270934378170,
"cells": [
{
"cell_id": 6442002833303548429,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 14156260080777624593,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "\\algorithm{nevaluate}{Numerically evaluate an expression.}\n\nGiven a scalar expression of one or more variables, evaluate it for a range of values \nof those variables. This algorithm accepts a Cadabra expression and one or more numpy arrays\ncontaining the values of the variables, in the form of a dictionary. A simple example with \nan expression of one variable:"
}
],
"hidden": true,
"source": "\\algorithm{nevaluate}{Numerically evaluate an expression.}\n\nGiven a scalar expression of one or more variables, evaluate it for a range of values \nof those variables. This algorithm accepts a Cadabra expression and one or more numpy arrays\ncontaining the values of the variables, in the form of a dictionary. A simple example with \nan expression of one variable:"
},
{
"cell_id": 7717361411841115229,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 16317621934812508465,
"cell_origin": "server",
"cell_type": "latex_view",
"cells": [
{
"cell_id": 3643042606220920068,
"cell_origin": "server",
"cell_type": "input_form",
"source": "\\cos(x) \\exp( - 1/4 (x)**2)"
}
],
"source": "\\begin{dmath*}{}\\cos{x} \\exp\\left( - \\frac{1}{4}{x}^{2}\\right)\\end{dmath*}"
}
],
"source": "ex:= \\cos(x) \\exp(-x**2/4);\n\nimport numpy as np\n\nxv = np.linspace(0, 3, 100)\nz = np.array( nevaluate(ex, {$x$: xv} ) )"
},
{
"cell_id": 9285492536561123852,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 9668872934801381964,
"cell_origin": "server",
"cell_type": "verbatim",
"source": "\\begin{verbatim}[1. 0.99931146 0.99724785 0.99381515 0.98902334 0.98288631\n 0.97542182 0.96665142 0.95660038 0.94529757]\\end{verbatim}"
}
],
"source": "z[0:10];"
},
{
"cell_id": 5511376990109163867,
"cell_origin": "client",
"cell_type": "latex",
"cells": [
{
"cell_id": 3830134294778153283,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "The \\algo{nevaluate} function thus takes as its second argument a Python\ndictionary which maps each variable in the expression to a list of values.\n\nFor expressions of multiple variables, the logic is the same: just list all \nthe variables in the dictionary, as in the example below."
}
],
"hidden": true,
"source": "The \\algo{nevaluate} function thus takes as its second argument a Python\ndictionary which maps each variable in the expression to a list of values.\n\nFor expressions of multiple variables, the logic is the same: just list all \nthe variables in the dictionary, as in the example below."
},
{
"cell_id": 2992782121045095320,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 3251060037967502714,
"cell_origin": "server",
"cell_type": "latex_view",
"cells": [
{
"cell_id": 6149534026651365282,
"cell_origin": "server",
"cell_type": "input_form",
"source": "\\cos(x) \\sin(y)"
}
],
"source": "\\begin{dmath*}{}\\cos{x} \\sin{y}\\end{dmath*}"
}
],
"source": "ex:= \\cos(x) \\sin(y);"
},
{
"cell_id": 13003303353493457346,
"cell_origin": "client",
"cell_type": "input",
"source": "xv = np.linspace(0, np.pi, 100)\nyv = np.linspace(0, np.pi, 100)"
},
{
"cell_id": 14177849469379369091,
"cell_origin": "client",
"cell_type": "input",
"source": "z = np.array( nevaluate(ex, {$x$: xv, $y$: yv}) )"
},
{
"cell_id": 10078872525967387623,
"cell_origin": "client",
"cell_type": "input",
"cells": [
{
"cell_id": 26823108033460839,
"cell_origin": "server",
"cell_type": "verbatim",
"source": "\\begin{verbatim}0.3106205340965772\\end{verbatim}"
}
],
"source": "z[3,10];"
},
{
"cell_id": 10368637782920619472,
"cell_origin": "client",
"cell_type": "input",
"source": ""
}
],
"description": "Cadabra JSON notebook format",
"version": 1.0
}
6 changes: 3 additions & 3 deletions examples/ref_numerical.cnb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
"cell_type": "latex",
"cells": [
{
"cell_id": 17518277435515688271,
"cell_id": 18054204918676316375,
"cell_origin": "client",
"cell_type": "latex_view",
"source": "The \\verb|nevaluate| function returns an \\verb|NTensor|, which is Cadabra's\nobject to store numerical values of tensors. It can be converted to a numpy\narray, after which you can plot it:"
"source": "The \\algo{nevaluate} function returns an \\verb|NTensor|, which is Cadabra's\nobject to store numerical values of tensors. It can be converted to a numpy\narray by wrapping it in `np.array`, after which you can plot it:"
}
],
"hidden": true,
"source": "The \\verb|nevaluate| function returns an \\verb|NTensor|, which is Cadabra's\nobject to store numerical values of tensors. It can be converted to a numpy\narray, after which you can plot it:"
"source": "The \\algo{nevaluate} function returns an \\verb|NTensor|, which is Cadabra's\nobject to store numerical values of tensors. It can be converted to a numpy\narray by wrapping it in `np.array`, after which you can plot it:"
},
{
"cell_id": 5634273073315875314,
Expand Down
1 change: 1 addition & 0 deletions web2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ set(ALGOS
lr_tensor
map_sympy
meld
nevaluate
product_rule
raise_free_indices
reduce_delta
Expand Down
7 changes: 7 additions & 0 deletions web2/cadabra2/source/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ <h1>News</h1>
</div>
</p>
<dl>
<dt>20 Sep 2023</dt>
<dd>Release of 2.4.4 (<a href="changelog.html#2.4.4">changes</a>).
Many new features for numerical evaluation and plotting of expressions
using <tt>nevaluate</tt> (see
the <a href="https://cadabra.science/notebooks/ref_numerical.html">numerical
evaluation</a> chapter in the book) and many bug fixes.
</dd>
<dt>25 Aug 2022</dt>
<dd>Release of 2.4.0 (<a href="changelog.html#2.4.0">changes</a>).
Update to accompany the release of
Expand Down

0 comments on commit c82b8e6

Please sign in to comment.