From daaa610c138fed53bbee61d24f30093fb3634672 Mon Sep 17 00:00:00 2001 From: Gerd Heber Date: Mon, 17 Aug 2015 20:59:10 -0500 Subject: [PATCH] Started iPython notebook for Chapter 2 of the Handbook. --- examples/Chapter2.ipynb | 861 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 861 insertions(+) create mode 100644 examples/Chapter2.ipynb diff --git a/examples/Chapter2.ipynb b/examples/Chapter2.ipynb new file mode 100644 index 0000000..9566aa1 --- /dev/null +++ b/examples/Chapter2.ipynb @@ -0,0 +1,861 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "To load \"kenzo\":\n", + " Load 1 ASDF system:\n", + " kenzo\n", + "; Loading \"kenzo\"\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "(:KENZO)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(ql:quickload :kenzo)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "---done---" + ] + }, + { + "data": { + "text/plain": [ + "NIL" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:cat-init)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.2.1 Representation of a reduction" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"----------------------------------------------------------------[class-doc]\n", + "REDUCTION\n", + "Slots: (tcc bcc f g h idnm orgn)\n", + "Instances of this class represent reductions of chain complexes.\n", + "\n", + " ^ h s ^ f ° g = 1\n", + " C -----> C C\n", + " ^ h ° d + d ° h = 1 - g ° f\n", + " | | ^\n", + " f | | g C\n", + " | | f ° h = 0\n", + " v h ° g = 0\n", + " C h ° h = 0\n", + "\n", + "The class has 7 slots:\n", + " ^\n", + "1. TCC, an object of type CHAIN-COMPLEX, the top chain complex C. Its reader\n", + " function is TCC1.\n", + "\n", + "2. BCC, an object of type CHAIN-COMPLEX, the bottom chain complex C. Its reader\n", + " function is BCC1.\n", + "\n", + "3. F, an object of type MORPHISM representing the morphism f. Its reader\n", + " function is F1.\n", + "\n", + "4. G, an object of type MORPHISM representing the morphism g. Its reader\n", + " function is G1.\n", + "\n", + "5. H, an object of type MORPHISM representing the morphism h. Its reader\n", + " function is H1.\n", + "\n", + "9. IDNM, an integer, a system-generated identifier for this object. Its reader\n", + " function is IDNM.\n", + "\n", + "10. ORGN, a list containg a comment indicating the origin of the object. The\n", + " should be unique (per session), since it is used in the implementation for\n", + " caching purposes. Its reader function is ORGN.\n", + "-----------------------------------------------------------------------------\"" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(documentation 'cat:reduction 'type)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.2.2 The function $\\texttt{build-rdct}$" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"--------------------------------------------------------------[function-doc]\n", + "BUILD-RDCT\n", + "Args: (&key f g h orgn)\n", + "Returns an instance of the class REDUCTION. The keyword arguments are as\n", + "follows:\n", + "\n", + ":F F, an object of type morphism representing the morphism f of a reduction\n", + "\n", + ":G G, an object of type morphism representing the morphism g of a reduction\n", + "\n", + ":H H, an object of type morphism representing the morphism h of a reduction\n", + "\n", + ":ORGN ORGN, a list containing a relevant and carefully chosen comment about\n", + " the origin of the chain complex. This comment should be unique\n", + " for a Kenzo session (between calls of CAT-INIT), as it is used\n", + " for caching purposes.\n", + "\n", + "Use this function instead of creating instances via the standard constructor\n", + "MAKE-INSTANCE.\n", + "------------------------------------------------------------------------------\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(documentation 'cat:build-rdct 'function)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2.2.4 Verification functions" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"--------------------------------------------------------------[function-doc]\n", + "PRE-CHECK-RDCT\n", + "Args: (rdct)\n", + "Assigns the following Lisp global variables, using morphisms from RDCT and the\n", + "differentials and identity morphisms of the underlying chain complexes,\n", + "according to these formulas:\n", + "\n", + "*TDD* = d ° d\n", + " ^ ^\n", + " C C\n", + "\n", + "*BDD* = d ° d\n", + " C C\n", + "\n", + "*ID-FG* = Id - f ° g\n", + " C\n", + "\n", + "*ID-GF-DH-HD* = Id - g ° f - (d ° h + h ° d )\n", + " ^ ^ ^\n", + " C C C\n", + "\n", + "*HH* = h ° h\n", + "*FH* = f ° h\n", + "*HG* = h ° g\n", + "\n", + "*DF-FD* = d ° f - f ° d\n", + " C ^\n", + " C\n", + "\n", + "*DG-GD* = d ° g - g ° d\n", + " ^ C\n", + " C\n", + "\n", + "------------------------------------------------------------------------------\"" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(documentation 'cat:pre-check-rdct 'function)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"--------------------------------------------------------------[function-doc]\n", + "CHECK-RDCT-NO-WAIT\n", + "Args: ()\n", + "Maps combinations of the top and bottom chain complexes of a reduction using\n", + "the morphisms created by PRE-CHECK-RDCT. Having no parameters, the\n", + "combinations must be provided via the Lisp global variables *TC* and *BC*,\n", + "for the top and bottom chain complex, respectively. If the morphisms are\n", + "coherent, the result of each mapping is a null combination.\n", + "------------------------------------------------------------------------------\"" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(documentation 'cat:check-rdct-no-wait 'function)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Example" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "CDELTA" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(defun cdelta (dmns)\n", + " (cat:build-chcm\n", + " :cmpr #'cat:l-cmpr\n", + " :basis :locally-effective\n", + " :bsgn '(0)\n", + " :intr-dffr\n", + " #'(lambda (degr gmsm)\n", + " (cat:make-cmbn\n", + " :degr (1- degr)\n", + " :list (do ((rslt cat:+empty-list+\n", + " (cons (cons sign\n", + " (append\n", + " (subseq gmsm 0 nark)\n", + " (subseq gmsm (1+ nark))))\n", + " rslt))\n", + " (sign 1 (- sign))\n", + " (nark 0 (1+ nark)))\n", + " ((> nark degr) rslt))))\n", + " :strt :gnrt\n", + " :orgn `(locally effective version of C_* delta ,dmns)))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "MAKE-F" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(defun make-f (tdmns bdmns)\n", + " (cat:build-mrph\n", + " :sorc (cdelta tdmns) :trgt (cdelta bdmns) :degr 0\n", + " :intr #'(lambda (degr gmsm)\n", + " (let ((pos (position-if #'(lambda (vertex) (>= vertex bdmns))\n", + " gmsm)))\n", + " (if pos\n", + " (if (< pos degr)\n", + " (cat:zero-cmbn degr)\n", + " (cat:cmbn degr 1 (nconc (butlast gmsm) (list bdmns))))\n", + " (cat:cmbn degr 1 gmsm))))\n", + " :strt :gnrt\n", + " :orgn `(projection delta ,tdmns => delta ,bdmns)))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "MAKE-G" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(defun make-g (tdmns bdmns)\n", + " (cat:build-mrph\n", + " :sorc (cdelta bdmns) :trgt (cdelta tdmns) :degr 0\n", + " :intr #'identity\n", + " :strt :cmbn\n", + " :orgn `(injection delta ,bdmns => delta ,tdmns)))" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "MAKE-H" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(defun make-h (tdmns bdmns)\n", + " (cat:build-mrph\n", + " :sorc (cdelta tdmns) :trgt (cdelta tdmns) :degr +1\n", + " :intr #'(lambda (degr gmsm)\n", + " (let ((pos (position-if #'(lambda (vertex) (>= vertex bdmns))\n", + " gmsm)))\n", + " (if pos\n", + " (if (member bdmns gmsm)\n", + " (cat:zero-cmbn (1+ degr))\n", + " (cat:cmbn (1+ degr) (cat:-1-expt-n pos)\n", + " (append (subseq gmsm 0 pos) (list bdmns)\n", + " (subseq gmsm pos))))\n", + " (cat:zero-cmbn (1+ degr)))))\n", + " :strt :gnrt\n", + " :orgn `(homotopy for delta ,tdmns => ,bdmns)))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "MAKE-RDCT" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(defun make-rdct (tdmns bdmns)\n", + " (let ((rdct (cat:build-rdct\n", + " :f (make-f tdmns bdmns)\n", + " :g (make-g tdmns bdmns)\n", + " :h (make-h tdmns bdmns)\n", + " :orgn `(reduction delta ,tdmns ,bdmns))))\n", + " rdct))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[K8 Reduction K1 => K3]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:def rdct (make-rdct 6 3))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(REDUCTION DELTA 6 3)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:orgn rdct)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "---done---" + ] + }, + { + "data": { + "text/plain": [ + "NIL" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:pre-check-rdct rdct)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\n", + "----------------------------------------------------------------------{CMBN 2}\n", + "<1 * (0 1 2)>\n", + "<10 * (1 2 3)>\n", + "<100 * (1 2 4)>\n", + "<1000 * (2 3 4)>\n", + "------------------------------------------------------------------------------\n" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(setf cat:*tc* (cat:cmbn 2 1 '(0 1 2) 10 '(1 2 3) 100 '(1 2 4) 1000 '(2 3 4)))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\n", + "----------------------------------------------------------------------{CMBN 3}\n", + "<4 * (0 1 2 3)>\n", + "------------------------------------------------------------------------------\n" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(setf cat:*bc* (cat:cmbn 3 4 '(0 1 2 3)))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "*TC* => \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "<1 * (0 1 2)>\n", + "<10 * (1 2 3)>\n", + "<100 * (1 2 4)>\n", + "<1000 * (2 3 4)>\n", + "------------------------------------------------------------------------------\n", + "\n", + "*BC* => \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "<4 * (0 1 2 3)>\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *TDD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 0}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *BDD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 1}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *DF-FD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 1}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *DG-GD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *ID-FG* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *ID-GF-DH-HD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *HH* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 4}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *FH* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *HG* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 4}\n", + "------------------------------------------------------------------------------\n", + "\n", + "---done---" + ] + }, + { + "data": { + "text/plain": [ + "NIL" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:check-rdct-no-wait)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[K35 Reduction K1 => K30]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:def trdct (make-rdct 6 4))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[K39 Reduction K30 => K3]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:def brdct (make-rdct 4 3))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[K45 Reduction K1 => K3]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(setf rdct (cat:cmps brdct trdct))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "---done---" + ] + }, + { + "data": { + "text/plain": [ + "NIL" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:pre-check-rdct rdct)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "*TC* => \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "<1 * (0 1 2)>\n", + "<10 * (1 2 3)>\n", + "<100 * (1 2 4)>\n", + "<1000 * (2 3 4)>\n", + "------------------------------------------------------------------------------\n", + "\n", + "*BC* => \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "<4 * (0 1 2 3)>\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *TDD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 0}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *BDD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 1}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *DF-FD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 1}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *DG-GD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *ID-FG* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *ID-GF-DH-HD* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 2}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *HH* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 4}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *FH* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 3}\n", + "------------------------------------------------------------------------------\n", + "\n", + "Checking *HG* = 0\n", + "Result: \n", + "----------------------------------------------------------------------{CMBN 4}\n", + "------------------------------------------------------------------------------\n", + "\n", + "---done---" + ] + }, + { + "data": { + "text/plain": [ + "NIL" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(cat:check-rdct-no-wait)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "CCL Lisp", + "language": "lisp", + "name": "lisp" + }, + "language_info": { + "codemirror_mode": "text/x-common-lisp", + "mimetype": "text/x-common-lisp", + "name": "common-lisp", + "pygments_lexer": "common-lisp", + "version": "X3J13" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}