From 62fbf38f55b55ee85c96043df694c79f239492b8 Mon Sep 17 00:00:00 2001 From: Donovan Date: Thu, 4 Jul 2024 09:14:48 -0500 Subject: [PATCH] complete sp network algebra tutorial --- sp_network_algebra_tutorial.ipynb | 700 +++++++++++++++++++++++++----- 1 file changed, 593 insertions(+), 107 deletions(-) diff --git a/sp_network_algebra_tutorial.ipynb b/sp_network_algebra_tutorial.ipynb index c36a1ab..132cfed 100644 --- a/sp_network_algebra_tutorial.ipynb +++ b/sp_network_algebra_tutorial.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 69, "outputs": [], "source": [ "from src.models import OuterKey, InnerKey, SubstitutionKey" @@ -20,8 +20,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.365133Z", - "start_time": "2024-07-03T17:15:30.328857Z" + "end_time": "2024-07-04T14:12:16.685220Z", + "start_time": "2024-07-04T14:12:16.446987Z" } } }, @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 70, "outputs": [], "source": [ "height = 4\n", @@ -49,8 +49,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.365712Z", - "start_time": "2024-07-03T17:15:30.332512Z" + "end_time": "2024-07-04T14:12:16.686123Z", + "start_time": "2024-07-04T14:12:16.453332Z" } } }, @@ -58,8 +58,8 @@ "cell_type": "markdown", "source": [ "## Operand Types\n", - "### Inner Key\n", - "An inner key is a list of `height` rows, each a random permutation of an identity arrary of length `width`" + "### Inner Permutation Key\n", + "An inner permutation key (inner key for short) is a list of `height` rows, each a random permutation of an identity array of length `width`" ], "metadata": { "collapsed": false @@ -67,13 +67,13 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 71, "outputs": [ { "data": { - "text/plain": "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]" + "text/plain": "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]" }, - "execution_count": 84, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -82,21 +82,22 @@ "i0 = InnerKey.init_matrix(width, height)\n", "i1 = InnerKey.init_matrix(width, height)\n", "i2 = InnerKey.init_matrix(width, height)\n", + "i_identity = InnerKey.init_identity_matrix(width, height)\n", "\n", "i0.matrix" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.366169Z", - "start_time": "2024-07-03T17:15:30.335990Z" + "end_time": "2024-07-04T14:12:16.830392Z", + "start_time": "2024-07-04T14:12:16.460887Z" } } }, { "cell_type": "markdown", "source": [ - "### Outer Key\n", + "### Outer Permutation Key\n", "An outer key is ..." ], "metadata": { @@ -105,13 +106,13 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 72, "outputs": [ { "data": { - "text/plain": "[[1, 2, 3, 0]]" + "text/plain": "[[2, 0, 1, 3]]" }, - "execution_count": 85, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -120,21 +121,22 @@ "o0 = OuterKey.init_matrix(height)\n", "o1 = OuterKey.init_matrix(height)\n", "o2 = OuterKey.init_matrix(height)\n", + "o_identity = OuterKey.init_identity_matrix(height)\n", "\n", "o0.matrix" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.405313Z", - "start_time": "2024-07-03T17:15:30.341422Z" + "end_time": "2024-07-04T14:12:16.831572Z", + "start_time": "2024-07-04T14:12:16.469310Z" } } }, { "cell_type": "markdown", "source": [ - "### Substitution Key (formerly AlphabetKey or alpha_key)\n", + "### Substitution Key (formerly Alphabet Key or alpha_key)\n", "Sub key is ..." ], "metadata": { @@ -143,13 +145,13 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 73, "outputs": [ { "data": { - "text/plain": "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]" + "text/plain": "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]" }, - "execution_count": 106, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -157,14 +159,16 @@ "source": [ "a0 = SubstitutionKey.init_matrix(width, height)\n", "a1 = SubstitutionKey.init_matrix(width, height)\n", + "a2 = SubstitutionKey.init_matrix(width, height)\n", + "a_identity = SubstitutionKey.init_identity_matrix(width, height)\n", "\n", "a0.matrix" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:26:59.359984Z", - "start_time": "2024-07-03T17:26:59.355497Z" + "end_time": "2024-07-04T14:12:16.832461Z", + "start_time": "2024-07-04T14:12:16.476713Z" } } }, @@ -172,7 +176,7 @@ "cell_type": "markdown", "source": [ "## Operators Types\n", - "### ***<*** Outer Permutation\n", + "### < Outer Permutation\n", "#### Substitution Key < Outer Key" ], "metadata": { @@ -181,15 +185,15 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 74, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[1, 2, 3, 0]]\n", - "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", - "[[165, 114, 152], [38, 71, 114], [52, 116, 61], [237, 92, 1]]\n" + "[[2, 0, 1, 3]]\n", + "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", + "[[73, 204, 152], [51, 14, 207], [3, 171, 4], [142, 175, 64]]\n" ] } ], @@ -202,8 +206,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:27:00.733689Z", - "start_time": "2024-07-03T17:27:00.729585Z" + "end_time": "2024-07-04T14:12:16.833320Z", + "start_time": "2024-07-04T14:12:16.484335Z" } } }, @@ -218,15 +222,15 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 75, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[1, 2, 3, 0]]\n", - "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", - "[[0, 1, 2], [2, 1, 0], [2, 0, 1], [1, 2, 0]]\n" + "[[2, 0, 1, 3]]\n", + "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", + "[[1, 0, 2], [0, 1, 2], [1, 0, 2], [2, 1, 0]]\n" ] } ], @@ -239,16 +243,16 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:27:04.433733Z", - "start_time": "2024-07-03T17:27:04.429380Z" + "end_time": "2024-07-04T14:12:16.834157Z", + "start_time": "2024-07-04T14:12:16.492114Z" } } }, { "cell_type": "markdown", "source": [ - "### ***<<*** Inner Permutation\n", - "#### Outer Key << OuterKey" + "### << Inner Permutation\n", + "#### Outer Key << Outer Key" ], "metadata": { "collapsed": false @@ -256,15 +260,15 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 76, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[2, 1, 3, 0]]\n", - "[[1, 2, 3, 0]]\n", - "[[3, 2, 0, 1]]\n" + "[[0, 1, 3, 2]]\n", + "[[2, 0, 1, 3]]\n", + "[[2, 0, 3, 1]]\n" ] } ], @@ -277,8 +281,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:27:08.293098Z", - "start_time": "2024-07-03T17:27:08.288126Z" + "end_time": "2024-07-04T14:12:16.834973Z", + "start_time": "2024-07-04T14:12:16.499677Z" } } }, @@ -293,15 +297,15 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 77, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[0, 1, 2], [0, 2, 1], [0, 1, 2], [2, 1, 0]]\n", - "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", - "[[1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]\n" + "[[1, 0, 2], [0, 1, 2], [0, 2, 1], [2, 1, 0]]\n", + "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", + "[[1, 0, 2], [1, 0, 2], [1, 2, 0], [0, 1, 2]]\n" ] } ], @@ -314,8 +318,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:27:11.574355Z", - "start_time": "2024-07-03T17:27:11.568652Z" + "end_time": "2024-07-04T14:12:16.835789Z", + "start_time": "2024-07-04T14:12:16.507413Z" } } }, @@ -330,15 +334,15 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 78, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", - "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", - "[[92, 1, 237], [165, 114, 152], [114, 71, 38], [61, 52, 116]]\n" + "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", + "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", + "[[51, 14, 207], [171, 3, 4], [204, 73, 152], [64, 175, 142]]\n" ] } ], @@ -351,15 +355,84 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:27:14.277217Z", - "start_time": "2024-07-03T17:27:14.272132Z" + "end_time": "2024-07-04T14:12:16.854289Z", + "start_time": "2024-07-04T14:12:16.515159Z" } } }, { "cell_type": "markdown", "source": [ - "### ***^*** Substitution\n", + "### ~Permutation Inversion\n", + "#### ~Outer Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 79, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[2, 0, 1, 3]]\n", + "[[1, 2, 0, 3]]\n" + ] + } + ], + "source": [ + "print(o0.matrix)\n", + "print((~o0).matrix)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.855384Z", + "start_time": "2024-07-04T14:12:16.522867Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### ~Inner Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 80, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", + "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n" + ] + } + ], + "source": [ + "print(i0.matrix)\n", + "print((~i0).matrix)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.856225Z", + "start_time": "2024-07-04T14:12:16.530564Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### ^ Substitution\n", "#### Substitution Key ^ Substitution Key" ], "metadata": { @@ -368,16 +441,16 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 81, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", - "[[184, 159, 115], [199, 221, 35], [158, 70, 86], [74, 43, 129]]\n", - "[[85, 195, 114], [98, 175, 187], [184, 1, 36], [126, 95, 188]]\n", - "85\n" + "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", + "[[1, 41, 28], [228, 126, 163], [255, 48, 188], [53, 120, 13]]\n", + "[[50, 39, 211], [231, 213, 167], [182, 252, 36], [187, 215, 77]]\n", + "50\n" ] } ], @@ -391,15 +464,225 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:29:15.922958Z", - "start_time": "2024-07-03T17:29:15.915126Z" + "end_time": "2024-07-04T14:12:16.857040Z", + "start_time": "2024-07-04T14:12:16.538722Z" } } }, { "cell_type": "markdown", "source": [ - "## dddd" + "## Substitution Permutation Algebra\n", + "#### properites:\n", + "- associative: (a + b) + c = a + (b + c)\n", + "- commutative: a + b = b + a\n", + "- identity: a + 0 = a or a * 1 = a\n", + "- inverse: a + (-a) = 0 or a * 1/a = 1 (for all a ~= 0)\n", + "- distributive: a(b + c) = ab + ac\n", + "\n", + "### Associative\n", + "#### Outer Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 82, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(o0 << o1 << o2) == ((o0 << o1) << o2) == (o0 << (o1 << o2))" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.858322Z", + "start_time": "2024-07-04T14:12:16.546322Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Inner Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 83, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(i0 << i1 << i2) == ((i0 << i1) << i2) == (i0 << (i1 << i2))" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.863346Z", + "start_time": "2024-07-04T14:12:16.554187Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 84, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(a0 ^ a1 ^ a2) == ((a0 ^ a1) ^ a2) == (a0 ^ (a1 ^ a2))" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.864336Z", + "start_time": "2024-07-04T14:12:16.562025Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Commutative Property\n", + "Substitution is the only key type that is commutative\n", + "#### Substitution Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 85, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(a0 ^ a1) == (a1 ^ a0)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.865178Z", + "start_time": "2024-07-04T14:12:16.569781Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Identity Property\n", + "#### Outer Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 86, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(o0 << o_identity) == o0" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.866342Z", + "start_time": "2024-07-04T14:12:16.578046Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Inner Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 87, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(i0 << i_identity) == i0" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.867309Z", + "start_time": "2024-07-04T14:12:16.589133Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key" ], "metadata": { "collapsed": false @@ -419,19 +702,26 @@ } ], "source": [ - "a0_i0_o0_v0 = a0 << (i0 < o0)\n", - "a0_i0_o0_v1 = ((a0 < ~o0) << i0) < o0\n", - "\n", - "a0_i0_o0_v0 == a0_i0_o0_v1" + "(a0 ^ a_identity) == a0" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.408639Z", - "start_time": "2024-07-03T17:15:30.361902Z" + "end_time": "2024-07-04T14:12:16.868143Z", + "start_time": "2024-07-04T14:12:16.599974Z" } } }, + { + "cell_type": "markdown", + "source": [ + "### Inverse Property\n", + "#### Outer Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 89, @@ -446,18 +736,25 @@ } ], "source": [ - "a0_o0_i0_v0 = (a0 < o0) << i0\n", - "a0_o0_i0_v1 = (a0 << (i0 < ~o0)) < o0\n", - "a0_i0_o0_v0 == a0_i0_o0_v1" + "(o0 << ~o0) == o_identity" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.408838Z", - "start_time": "2024-07-03T17:15:30.365269Z" + "end_time": "2024-07-04T14:12:16.868953Z", + "start_time": "2024-07-04T14:12:16.608436Z" } } }, + { + "cell_type": "markdown", + "source": [ + "#### Inner Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 90, @@ -472,18 +769,25 @@ } ], "source": [ - "a0_o0_i0_v0 = (a0 < o0) << i0\n", - "a0_o0_i0_v1 = (a0 << (i0 < ~o0)) < o0\n", - "a0_o0_i0_v0 == a0_o0_i0_v1" + "(i0 << ~i0) == i_identity" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.408892Z", - "start_time": "2024-07-03T17:15:30.368768Z" + "end_time": "2024-07-04T14:12:16.869884Z", + "start_time": "2024-07-04T14:12:16.619030Z" } } }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 91, @@ -498,16 +802,26 @@ } ], "source": [ - "(~(i0 << i1)) == (~i1 << ~i0)" + "(a0 ^ a0) == a_identity" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.408977Z", - "start_time": "2024-07-03T17:15:30.371377Z" + "end_time": "2024-07-04T14:12:16.870708Z", + "start_time": "2024-07-04T14:12:16.629750Z" } } }, + { + "cell_type": "markdown", + "source": [ + "### Distributive\n", + "#### Inner Key/Outer Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 92, @@ -522,19 +836,25 @@ } ], "source": [ - "i0_i1_i2_v0 = i0 << i1 << i2\n", - "i0_i1_i2_v1 = i0 << (i1 << i2)\n", - "i0_i1_i2_v2 = (i0 << i1) << i2\n", - "i0_i1_i2_v0 == i0_i1_i2_v1 == i0_i1_i2_v2" + "((i0 << i1) < o0) == ((i0 < o0) << (i1 < o0))" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.409076Z", - "start_time": "2024-07-03T17:15:30.375604Z" + "end_time": "2024-07-04T14:12:16.871520Z", + "start_time": "2024-07-04T14:12:16.638198Z" } } }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key/Outer Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 93, @@ -549,16 +869,25 @@ } ], "source": [ - "i0 == ((i0 << i2 << i1) << ~(i2 << i1)) == ((i0 << i2 << i1) << ~i1 << ~i2)" + "((a0 ^ a1) < o0) == ((a0 < o0) ^ (a1 < o0))" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.409139Z", - "start_time": "2024-07-03T17:15:30.378496Z" + "end_time": "2024-07-04T14:12:16.872334Z", + "start_time": "2024-07-04T14:12:16.646323Z" } } }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key/Inner Key" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "code", "execution_count": 94, @@ -573,26 +902,20 @@ } ], "source": [ - "i0_o0_o1_o2_v1 = ((i0 < o0) < o1) < o2\n", - "i0_o0_o1_o2_v2 = (i0 < (o0 << o1)) < o2\n", - "i0_o0_o1_o2_v3 = (i0 < o0) < (o1 << o2)\n", - "i0_o0_o1_o2_v4 = (i0 < (o0 << o1 << o2))\n", - "\n", - "i0_o0_o1_o2_v1 == i0_o0_o1_o2_v2 == i0_o0_o1_o2_v3 == i0_o0_o1_o2_v4" + "((a0 ^ a1) << i0) == ((a0 << i0) ^ (a1 << i0))" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.409210Z", - "start_time": "2024-07-03T17:15:30.381727Z" + "end_time": "2024-07-04T14:12:16.873134Z", + "start_time": "2024-07-04T14:12:16.654286Z" } } }, { "cell_type": "markdown", "source": [ - "### Becareful about your order of operation\n", - "***Always use parenthesis to control the order of operations***" + "#### Substitution Key/Inner Key/Outer Key" ], "metadata": { "collapsed": false @@ -611,14 +934,177 @@ "output_type": "execute_result" } ], + "source": [ + "((a0 << i0) < o0) == ((a0 < o0) << (i0 < o0))" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.874410Z", + "start_time": "2024-07-04T14:12:16.662231Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Other Examples" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 96, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(a0 << (i0 < o0)) == (((a0 < ~o0) << i0) < o0)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.882191Z", + "start_time": "2024-07-04T14:12:16.670307Z" + } + } + }, + { + "cell_type": "code", + "execution_count": 97, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "((a0 < o0) << i0) == ((a0 << (i0 < ~o0)) < o0)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.882308Z", + "start_time": "2024-07-04T14:12:16.674096Z" + } + } + }, + { + "cell_type": "code", + "execution_count": 98, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(~(i0 << i1)) == (~i1 << ~i0)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.882394Z", + "start_time": "2024-07-04T14:12:16.677061Z" + } + } + }, + { + "cell_type": "code", + "execution_count": 99, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(~(o0 << o1)) == (~o1 << ~o0)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.883495Z", + "start_time": "2024-07-04T14:12:16.683278Z" + } + } + }, + { + "cell_type": "code", + "execution_count": 100, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "i0 == ((i0 << i2 << i1) << ~(i2 << i1)) == ((i0 << i2 << i1) << ~i1 << ~i2)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-04T14:12:16.883574Z", + "start_time": "2024-07-04T14:12:16.687331Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Becareful about your order of operation\n", + "***Always use parenthesis to control the order of operations***" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 101, + "outputs": [ + { + "data": { + "text/plain": "True" + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "i0 < (o0 << o1 << o2) != (i0 < (o0 << o1 << o2)) # not equal !!!!!!" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T17:15:30.409260Z", - "start_time": "2024-07-03T17:15:30.384147Z" + "end_time": "2024-07-04T14:12:16.883645Z", + "start_time": "2024-07-04T14:12:16.690509Z" } } }