This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/docs/tut.ipynb

636 lines
407 KiB
Plaintext
Raw Normal View History

2018-02-08 10:46:22 +00:00
{
"cells": [
{
"attachments": {
"yap.ico": {
"image/vnd.microsoft.icon": "AAABAAYAAAAAAAEAGAAoIAMAZgAAAICAAAABABgAKMgAAI4gAwBAQAAAAQAYACgyAAC26AMAMDAAAAEAGACoHAAA3hoEACAgAAABABgAqAwAAIY3BAAQEAAAAQAIAGgFAAAuRAQAKAAAAAABAAAAAgAAAQAYAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAIE7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4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O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O4E7O
}
},
"cell_type": "markdown",
"metadata": {},
"source": [
"# YAP Jupyter Interface ![yap.ico](attachment:yap.ico)\n",
"\n",
"## Walkthrough and User Guide\n",
"\n",
"The next cells show examples of input output interaction with Prolog and Jupyter. We assume basic knowledge of both Prolog and Python/R/Jupyter. Notice that this is experimental software, subject to bugs and change. Also remember that \n",
" - all cells in the same page belong to the same process;\n",
" - _magic_ refers to annotations that perform extra, non-trivial work\n",
" - check the top=right ball right to the side of `YAP 6`: if empty the system is avsilable; otherwise, it is busy, \n",
"\n",
"### Basic Usage\n",
"\n",
"Any Prolog system should be able to unify two terms:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X = s\n",
"No (more) answers\n"
]
}
],
"source": [
"X= s"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X = 2\n",
"No (more) answers\n"
]
}
],
"source": [
"X = 2\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No (more) answers\n"
]
}
],
"source": [
"f(X,['olá',X] = f(`hello`,Z)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X = \"hello\",\n",
"Z = ['ol<6F><6C><EFBFBD><EFBFBD>',\"hello\"]\n",
"No (more) answers\n"
]
}
],
"source": [
"f(X,['olá',X]) = f(`hello`,Z)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X = Y\n",
"No (more) answers\n"
]
}
],
"source": [
"X=Y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You observe that the first time you press `shift-enter` or `ctl-enter`, YAP/Jupyter writes down `X=2`, the answer. If you press down `shift-enter` again, it writes `No (more) answers` Pressing again returns you to the first answer, `X=2`:\n",
"\n",
"- In YAP/Jupyter cells have a state that depends on how many answers you generated.\n",
"\n",
"The next example shows a more complex notion of state:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"between(1,100,I), J is I^I"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The YAP `^` operator generates floating-point numbers for large exponentials. You can try replacing `^` by `**` in the cell: notice that the cell state is reset, as changes in the text of a cell may mean anything. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to look at all solutions, you can place an `*` at the end of cell:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"between(1,20,I), J is 20-I, IJ is I*J *\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NB: in the current version, the states in a page are single-threaded, meaning only one cell is active at a rime."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Programming with cells\n",
"\n",
"Cells can store programs: in fact, by default that is what they should do. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next cell shows a program to recognise state-checking predicates:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" % reconsulting jupyter cell...\n",
" % reconsulted ??? in module user, 7 msec 0 bytes\n",
"No (more) answers\n"
]
}
],
"source": [
"state_info(Name/Arity) :- \n",
" current_predicate(Name/Arity), \n",
" atom_concat(current,_,Name).\n",
"state_info(Name/Arity) :- \n",
" system_predicate(Name/Arity),\n",
" atom_concat(current,_,Name)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A query cell follows:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"P = current_mutex/3\n",
"P = current_module/2\n",
"P = current_module/1\n",
"P = current_atom/1\n",
"P = current_key/2\n",
"P = current_predicate/1\n",
"P = current_predicate/2\n",
"P = current_thread/2\n",
"P = current_char_conversion/2\n",
"P = current_line_number/2\n",
"P = current_line_number/1\n",
"P = current_stream/3\n",
"P = current_op/3\n",
"P = current_prolog_flag/2\n",
"P = current_source_module/2\n",
"P = current_host/1\n",
"P = current_output/1\n",
"P = current_input/1\n",
"P = current_reference_count/2\n",
"No (more) answers\n"
]
}
],
"source": [
" state_info(P)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that you need to consult the program cell first. Of course, we can just do both: "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" % reconsulting jupyter cell...\n",
" % reconsulted ??? in module user, 15 msec 0 bytes\n",
"T = [5],\n",
"X = 3\n",
"No (more) answers\n"
]
}
],
"source": [
"\n",
"generate_ith(I, I, [Head|Tail], Head, Tail).\n",
"generate_ith(I, IN, [_|List], El, Tail) :-\n",
"\tI1 is I+1,\n",
"\tgenerate_ith(I1, IN, List, El, Tail).\n",
"\n",
"ith(V, In, Element, Tail) :- var(V), !,\n",
"\tgenerate_ith(0, V, In, Element, Tail).\n",
"ith(0, [Head|Tail], Head, Tail) :- !.\n",
"ith(N, [Head|Tail], Elem, [Head|Rest]) :-\n",
"\tM is N-1,\n",
"\tith(M, Tail, Elem, Rest).\n",
"\n",
"ith(X,[1,2,3,4,5],4, T)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"#y#\n",
"CMakeCache.txt\n",
"CMakeCache.txt~\n",
"CMakeDoxyfile.in\n",
"CMakeDoxyfile.tpl.bak\n",
"CMakeDoxygenDefaults.cmake\n",
"CMakeFiles\n",
"CXX\n",
"FindPackageLog.txt\n",
"GitSHA1.c\n",
"H\n",
"Makefile\n",
"OPTYap\n",
"PropsOfAE\n",
"Untitled.ipynb\n",
"Untitled1.ipynb\n",
"Untitled10.ipynb\n",
"Untitled11.ipynb\n",
"Untitled2.ipynb\n",
"Untitled3.ipynb\n",
"Untitled4.ipynb\n",
"Untitled5.ipynb\n",
"Untitled6.ipynb\n",
"Untitled7.ipynb\n",
"Untitled8.ipynb\n",
"Untitled9.ipynb\n",
"YAP.cbp\n",
"YapConfig.h\n",
"YapIOConfig.h\n",
"YapTermConfig.h\n",
"cmake_install.cmake\n",
"compile_commands.json\n",
"config.h\n",
"cudd_config.h\n",
"dlocals.h\n",
"docs\n",
"i\n",
"install_manifest.txt\n",
"libYap.6.3.5.dylib\n",
"libYap.6.3.5.dylib.dSYM\n",
"libYap.6.3.dylib\n",
"libYap.dylib\n",
"library\n",
"m\n",
"meta.js\n",
"myddas.yap\n",
"new~~cc\n",
"os\n",
"packages\n",
"pl\n",
"swiLibrary\n",
"temp-dir\n",
"test2.png\n",
"untitled.txt\n",
"utf8proc\n",
"x\n",
"x.yap\n",
"y\n",
"yap\n",
"yap.dSYM\n",
"y~\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"bash: line 1: fg: no job control\n"
]
}
],
"source": [
"%%bash\n",
"\n",
"ls"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Magic\n",
"\n",
"YAP allows the standard magics, buth with line and cell:\n",
"\n",
"- line magics should be the first non-empty line, and must start with `%` followed immediately by the name.\n",
"\n",
"- cell magaics start with `%%` and must be the only magic in the cell.\n",
"\n",
"You can use the completion mechanism to list all magics.\n",
"\n",
"The next cell shows a cell magic that starts a bash shell."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ERROR! Session/line number was not unique in database. History logging moved to new session 5605\n",
" % reconsulting jupyter cell...\n",
" % reconsulted ??? in module user, 16 msec 0 bytes\n",
"\n",
"No (more) answers\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYw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dLNbymRUi0t9SogaDwWAIIk6Ow/AA31LVt+ypnbeKyCuqutsnzVVAib0txFoTYaGIZGLNmDofa/79rSLyrKqedFCvwWAwGAbBMYOh1hKax+z3LSKyB2vlLF+DcS3wiN0XuFxE0kVkAta6wa+oahOAiLyCNYXyWYvQRCLtXR7erGzkYGMbFTXddGQf5+KSbFLiI2qcpcFFWjs9rKto4FBTG1U13XTlWHUsKc7UMcPABGUuKXtN3jeAc1W12ef488C/qeo6e/81rLn4lwEJqvoz+/gPgTOq+l/95H0r1nz45OXlla5atWpEGltbW0lJSRk6oYOc8SjPVHaxptZDR8/7z8VFw8X5MXysJI7kWOk/gyASCvdrIEJVWyjoautWnqroYu0RD1196lhCNFw6KYbrSuJIjDF1bCBCVReMTNvy5cu3qup8f9I6/jhhL/P5N+DrvsYiUKjqvcC9APPnz9dly5aNKJ+ysjJGem0g2HboJN9/9C2ON3u4bm4+H58/idkT0lj35jpypp3P37Ye5sm3DvN2Uw+/uXEuS4qzh87UQdy+X4MRqtrc1rWhqpFvP76Nk+09XH/BZD5WOokZ41NZt24dGUXn8eSWwzy9/Qhvn4rhtzddwAVTMlzTCu7fr4EIVV3gvDZHe0nZS2r+DXhUVZ/qJ8kR3r+e8CT72EDHI5JXd5/gxvvKiY2O4m9fXsKvP2kZhLSkWJJjhQVTM/n36+fw969cREZSLDc/uIlnd/S3nLTB0D/P7TjKzQ9uIj0plr9/5SL+/fo5LJiaSVqiVceWFGfzq0/O5akvLyEuJopP3Vf
"text/plain": [
"<matplotlib.figure.Figure at 0x11024d1d0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"\n",
"main :- \n",
" := import( matplotlib.pyplot ),\n",
" := import( numpy ),\n",
" Plt = matplotlib.pyplot,\n",
" Np = numpy,\n",
" t := Np.arange(0.0, 2.0, 0.01),\n",
" s := 1 + Np.sin(2*Np.pi*t),\n",
" := Plt.plot(t, s),\n",
" := Plt.xlabel(`time (s)`),\n",
" := Plt.ylabel(`voltage (mV)`),\n",
" := Plt.title(`About as simple as it gets, folks`),\n",
" := Plt.grid(true),\n",
" := Plt.savefig(`test2.png`),\n",
" := Plt.show().\n",
"\n",
"main"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "bracket or operator expected. (<string>, line 8)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32m8\u001b[0m\n\u001b[0;31m lt = bqplot.pyplot,\n Np = numpy,\n := Plt.figure(1, title=`Line\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m bracket or operator expected.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" % reconsulting jupyter cell...\n",
" % reconsulted ??? in module user, 20 msec 0 bytes\n",
"No (more) answers\n"
]
}
],
"source": [
"\n",
"main2 :-\n",
" python_import( numpy),\n",
" python_import( matplotlib.mlab),\n",
" python_import( matplotlib.pyplot ),\n",
" NP = numpy,\n",
" Mlab = matplotlib.mlab,\n",
" Plt = matplotlib.pyplot,\n",
"\n",
" /* example data */\n",
" Mu = 100, /* mean of distribution, */\n",
" Sigma = 15, /* standard deviation of distribution, */\n",
" x := Mu + Sigma * NP.random.randn(10000),\n",
" NumBins = 50,\n",
"/* the histogram of the data */\n",
"t(n, bins, patches) := Plt.hist(x, NumBins, normed=1, facecolor= `green`, alpha=0.5),\n",
"/* add a `best fit` line */\n",
"y := Mlab.normpdf(bins, mu, sigma),\n",
":= Plt.plot(bins, y, `r--`),\n",
":= Plt.xlabel(`Smarts`),\n",
":= Plt.ylabel(`Probability`),\n",
":=Plt.title(`Histogram of IQ: $\\\\mu=100$, $\\\\sigma=15$ `),\n",
"/* Tweak spacing to prevent clipping of ylabel, */\n",
":= Plt.show().\n",
" \n",
" main2\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" File \"<stdin>\", line 1\n",
" %%python3\n",
" ^\n",
"SyntaxError: invalid syntax\n"
]
}
],
"source": [
"%%python3\n",
"\n",
"dir(__root__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "bracket or operator expected. (<string>, line 8)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32m8\u001b[0m\n\u001b[0;31m Plt = bqplot.pyplot,\n Np = numpy,\n := Plt.figure(1, title=`Lin\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m bracket or operator expected.\n"
]
},
{
"ename": "SyntaxError",
"evalue": "bracket or operator expected. (<string>, line 8)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32m8\u001b[0m\n\u001b[0;31m lt = bqplot.pyplot,\n Np = numpy,\n := Plt.figure(1, title=`Line\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m bracket or operator expected.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" % reconsulting jupyter cell...\n",
":- user:python_import(numoy) failed.\n",
" % reconsulted ??? in module user, 262 msec 0 bytes\n",
"No (more) answers\n"
]
}
],
"source": [
":- python_import(bqplot).\n",
":- python_import(numoy).\n",
"\n",
":- Plt = bqplot.pyplot,\n",
" Np = numpy,\n",
" := Plt.figure(1, title=`Line Chart`),\n",
" := Np.random.seed(0),\n",
"n = 200,\n",
"x = Np.linspace(0.0, 10.0, n).\n",
"y = Np.cumsum(np.random.randn(n)),\n",
":= Plt.plot(x, y),\n",
":= Plt.show().\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No (more) answers\n"
]
}
],
"source": [
":-[library(real)].\n",
"\n",
"X <- c(1:10), Y := sin(X)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"X:=x"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%% javascript\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "YAP 6",
"language": "prolog",
"name": "yap_kernel"
},
"language_info": {
"codemirror_mode": {
"name": "prolog"
},
"file_extension": "yap",
"mimetype": "text/x-prolog",
"name": "prolog",
"nbconvert_exporter": "python",
"pygments_lexer": "prolog",
"version": "6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}