(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 12.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 57800, 1443] NotebookOptionsPosition[ 53068, 1366] NotebookOutlinePosition[ 53529, 1384] CellTagsIndexPosition[ 53486, 1381] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[ RowBox[{"Get", "@", RowBox[{"FileNameJoin", "[", RowBox[{"{", RowBox[{ RowBox[{"DirectoryName", "@", RowBox[{"NotebookFileName", "[", "]"}]}], ",", "\"\\""}], "}"}], "]"}]}]], "Input", InitializationCell->True, CellChangeTimes->{{3.82254947495747*^9, 3.8225495093988934`*^9}}, CellLabel->"In[75]:=",ExpressionUUID->"3c1daa83-8c0a-4e99-ad7f-c3f04877f88a"], Cell[BoxData[ RowBox[{ RowBox[{"$ContextPath", "=", RowBox[{"DeleteDuplicates", "@", RowBox[{"Append", "[", RowBox[{"$ContextPath", ",", "\"\\""}], "]"}]}]}], ";"}]], "Input", CellLabel->"In[2]:=",ExpressionUUID->"7775dbb6-7ac4-457a-96d6-a9ae875b828b"], Cell[CellGroupData[{ Cell["Parse out the structure", "Title", CellChangeTimes->{{3.8225056218298264`*^9, 3.822505625838307*^9}},ExpressionUUID->"02135865-b6e5-4cad-ad4b-\ 5778f2375c71"], Cell["\<\ Here follows some ghastly, though at least pure, XLSX-parsing code.\ \>", "Text", CellChangeTimes->{{3.8225045199462013`*^9, 3.822504539065948*^9}},ExpressionUUID->"54930d51-3a8d-4d53-bf35-\ 80e6641e2c1b"], Cell[BoxData[{ RowBox[{ RowBox[{"Clear", "[", "fixColour", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"fixColour", "[", "\"\\"", "]"}], "=", "Red"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"fixColour", "[", "\"\\"", "]"}], "=", "Yellow"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"fixColour", "[", "\"\\"", "]"}], "=", "Black"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"fixColour", "[", "\"\\"", "]"}], "=", "Blue"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"fixColour", "[", "x_", "]"}], ":=", RowBox[{"Throw", "[", "x", "]"}]}], ";"}]}], "Input", CellChangeTimes->{{3.822503800728251*^9, 3.822503887208557*^9}, { 3.8225039516130342`*^9, 3.822503977819137*^9}, {3.822552940100294*^9, 3.8225529405676203`*^9}}, CellLabel->"In[3]:=",ExpressionUUID->"f6d80843-4dfa-4983-94cf-3ae0a4d9d2f5"], Cell[BoxData[ RowBox[{ RowBox[{"extractSi", "[", RowBox[{"XMLElement", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "}"}], ",", "xs_List"}], "]"}], "]"}], ":=", RowBox[{"Select", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", RowBox[{"#", "[", RowBox[{"[", "3", "]"}], "]"}], "]"}], "\[Equal]", "1"}], ",", RowBox[{"{", RowBox[{ RowBox[{"fixColour", "@", "\"\\""}], ",", RowBox[{"First", "@", RowBox[{"Cases", "[", RowBox[{"#", ",", RowBox[{ RowBox[{"XMLElement", "[", RowBox[{"\"\\"", ",", "_", ",", RowBox[{"{", "x_", "}"}]}], "]"}], "\[RuleDelayed]", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"FromDigits", "[", RowBox[{"#", ",", "10"}], "]"}], "&"}], "/@", RowBox[{"StringSplit", "[", "x", "]"}]}], ")"}]}], ",", "All"}], "]"}]}]}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"style", "=", RowBox[{"Cases", "[", RowBox[{ RowBox[{"#", "[", RowBox[{"[", RowBox[{"3", ",", "1"}], "]"}], "]"}], ",", RowBox[{ RowBox[{"XMLElement", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "}"}], ",", RowBox[{"{", RowBox[{"___", ",", RowBox[{"XMLElement", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", "r_"}], "}"}], ",", "___"}], "]"}], ",", "___"}], "}"}]}], "]"}], "\[RuleDelayed]", "r"}], ",", "All"}], "]"}]}], ",", RowBox[{"text", "=", RowBox[{"Cases", "[", RowBox[{ RowBox[{"#", "[", RowBox[{"[", RowBox[{"3", ",", "2"}], "]"}], "]"}], ",", RowBox[{ RowBox[{"XMLElement", "[", RowBox[{"\"\\"", ",", "_", ",", RowBox[{"{", "t_", "}"}]}], "]"}], "\[RuleDelayed]", "t"}], ",", "All"}], "]"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"style", "===", RowBox[{"{", "}"}]}], ",", RowBox[{"fixColour", "@", "\"\\""}], ",", RowBox[{ RowBox[{ RowBox[{"Assert", "[", RowBox[{"Length", "@", "style"}], "]"}], "\[Equal]", "1"}], ";", RowBox[{"fixColour", "@", RowBox[{"First", "@", "style"}]}]}]}], "]"}], ",", RowBox[{ RowBox[{"Assert", "[", RowBox[{ RowBox[{"Length", "@", "text"}], "\[Equal]", "1"}], "]"}], ";", RowBox[{ RowBox[{ RowBox[{"FromDigits", "[", RowBox[{"#", ",", "10"}], "]"}], "&"}], "/@", RowBox[{"StringSplit", "[", RowBox[{"First", "@", "text"}], "]"}]}]}]}], "}"}]}], "]"}]}], "]"}], "&"}], "/@", "xs"}], ",", RowBox[{ RowBox[{ RowBox[{"Length", "@", RowBox[{"Last", "[", "#", "]"}]}], ">", "0"}], "&"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.8225028985282393`*^9, 3.8225031594502573`*^9}, { 3.822503192884095*^9, 3.8225032034581327`*^9}, {3.822503270767446*^9, 3.822503277197755*^9}, {3.822503385015192*^9, 3.822503389078148*^9}, { 3.822503439715667*^9, 3.822503570412619*^9}, {3.822503603654608*^9, 3.822503715890572*^9}, {3.82250384962638*^9, 3.822503880841918*^9}, { 3.822503957653474*^9, 3.822503958955127*^9}, {3.8225040722951307`*^9, 3.8225041289810257`*^9}, {3.822504173034113*^9, 3.8225041732476063`*^9}, { 3.8225042142890873`*^9, 3.822504406708754*^9}, {3.822504454761606*^9, 3.8225044589846582`*^9}, {3.822504494939788*^9, 3.822504495561797*^9}, 3.822504534389085*^9}, CellLabel->"In[9]:=",ExpressionUUID->"dcba92b8-bdae-4748-9c95-dbbe8d4931ce"], Cell[BoxData[ RowBox[{ RowBox[{"xlsx", "=", RowBox[{"FileNameJoin", "[", RowBox[{"{", RowBox[{ RowBox[{"DirectoryName", "@", RowBox[{"NotebookFileName", "[", "]"}]}], ",", "\"\\""}], "}"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822552500828095*^9, 3.822552510602881*^9}}, CellLabel->"In[10]:=",ExpressionUUID->"c02f4912-315d-4b9b-9cf1-77bb3afc8c01"], Cell[BoxData[ RowBox[{ RowBox[{"extracted", "=", RowBox[{"extractSi", "/@", RowBox[{ RowBox[{"Import", "[", RowBox[{"xlsx", ",", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], "]"}], "[", RowBox[{"[", RowBox[{"2", ",", "3"}], "]"}], "]"}]}]}], ";"}]], "Input", CellChangeTimes->{{3.8225054887261133`*^9, 3.8225054902517757`*^9}, { 3.822552461692048*^9, 3.822552507907854*^9}}, CellLabel->"In[11]:=",ExpressionUUID->"cc4e3da7-ea3a-4a6a-9637-548147cd7fd7"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"colStringIds", "=", RowBox[{ RowBox[{ RowBox[{ RowBox[{"1", "+", RowBox[{"FromDigits", "[", RowBox[{"#", ",", "10"}], "]"}]}], "&"}], "@*", "First", "@*", "Last", "@*", "First", "@*", "Last"}], "/@", RowBox[{"Most", "@", RowBox[{"Rest", "[", RowBox[{ RowBox[{ RowBox[{"Import", "[", RowBox[{"xlsx", ",", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], "]"}], "[", RowBox[{"[", "2", "]"}], "]"}], "[", RowBox[{"[", RowBox[{"3", ",", "5", ",", "3", ",", "1", ",", "3"}], "]"}], "]"}], "]"}]}]}]}]], "Input", CellChangeTimes->{{3.822505108433877*^9, 3.822505159183049*^9}, { 3.8225052050721483`*^9, 3.822505264385549*^9}, {3.822505428636228*^9, 3.8225054543156033`*^9}, {3.822505603624071*^9, 3.822505604215929*^9}, { 3.822552514526011*^9, 3.8225525149874487`*^9}}, CellLabel->"In[12]:=",ExpressionUUID->"3f064e76-94cf-47b5-94d0-1e1467e317b2"], Cell[BoxData[ RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", "4", ",", "92", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9", ",", "10", ",", "11", ",", "12", ",", "13", ",", "14", ",", "15", ",", "16", ",", "17", ",", "18", ",", "19", ",", "20", ",", "21", ",", "22", ",", "23", ",", "24", ",", "25", ",", "26", ",", "27", ",", "28", ",", "29", ",", "93", ",", "30", ",", "31", ",", "32", ",", "33", ",", "34", ",", "35", ",", "36", ",", "37", ",", "38", ",", "39", ",", "40", ",", "41", ",", "42", ",", "43", ",", "44", ",", "45", ",", "46", ",", "47", ",", "48", ",", "49", ",", "50", ",", "51", ",", "52", ",", "53", ",", "54", ",", "55", ",", "56", ",", "57", ",", "58"}], "}"}]], "Output", CellChangeTimes->{{3.8225051137936163`*^9, 3.822505159464691*^9}, { 3.822505214421823*^9, 3.822505264655711*^9}, {3.8225054305013447`*^9, 3.82250545467334*^9}, 3.8225056743425198`*^9, 3.82253920709877*^9, 3.822548454987849*^9, {3.822552497507575*^9, 3.8225525153552837`*^9}, 3.822552943866859*^9}, CellLabel->"Out[12]=",ExpressionUUID->"e09a3cba-325e-4344-be44-02f3917bee2a"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"rowStringIds", "=", RowBox[{ RowBox[{ RowBox[{"1", "+", RowBox[{"FromDigits", "[", RowBox[{ RowBox[{"#", "[", RowBox[{"[", RowBox[{"3", ",", "1", ",", "3", ",", "1", ",", "3", ",", "1"}], "]"}], "]"}], ",", "10"}], "]"}]}], "&"}], "/@", RowBox[{ RowBox[{ RowBox[{"Import", "[", RowBox[{"xlsx", ",", RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}]}], "]"}], "[", RowBox[{"[", "2", "]"}], "]"}], "[", RowBox[{"[", RowBox[{"3", ",", "5", ",", "3", ",", RowBox[{"2", ";;", RowBox[{"-", "2"}]}]}], "]"}], "]"}]}]}]], "Input", CellChangeTimes->{{3.8225052683377657`*^9, 3.822505442147874*^9}, { 3.822505601433588*^9, 3.822505602406671*^9}, {3.8225525188605013`*^9, 3.822552519427589*^9}}, CellLabel->"In[13]:=",ExpressionUUID->"138e3b90-4c0c-4db8-aaa5-3e0aafbd1af5"], Cell[BoxData[ RowBox[{"{", RowBox[{ "59", ",", "60", ",", "94", ",", "95", ",", "96", ",", "61", ",", "62", ",", "63", ",", "97", ",", "64", ",", "65", ",", "66", ",", "98", ",", "99", ",", "67", ",", "68", ",", "100", ",", "101", ",", "102", ",", "103", ",", "69", ",", "104", ",", "105", ",", "106", ",", "107", ",", "108", ",", "109", ",", "110", ",", "111", ",", "70", ",", "112", ",", "113", ",", "114", ",", "115", ",", "116", ",", "117", ",", "71", ",", "72", ",", "73", ",", "74", ",", "75", ",", "76", ",", "77", ",", "78", ",", "79", ",", "80", ",", "81", ",", "82", ",", "83", ",", "84", ",", "85", ",", "86", ",", "87", ",", "88", ",", "118", ",", "119", ",", "89", ",", "90", ",", "91", ",", "120"}], "}"}]], "Output", CellChangeTimes->{{3.8225052700703382`*^9, 3.822505293597924*^9}, { 3.8225053290459433`*^9, 3.822505442473522*^9}, 3.822505674977359*^9, 3.822539208710437*^9, 3.82254845588943*^9, 3.822552519801731*^9, 3.822552945184277*^9}, CellLabel->"Out[13]=",ExpressionUUID->"fc20ecc6-fcd2-49fc-9758-98259e023109"] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"rowsIn", "=", RowBox[{"Map", "[", RowBox[{"Reverse", ",", RowBox[{ RowBox[{ RowBox[{"Flatten", "[", RowBox[{"#", ",", "1"}], "]"}], "&"}], "/@", RowBox[{"Map", "[", RowBox[{"Thread", ",", RowBox[{"Extract", "[", RowBox[{"extracted", ",", RowBox[{"List", "/@", "rowStringIds"}]}], "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.8225054612532597`*^9, 3.822505533490829*^9}, { 3.822505571207807*^9, 3.8225055749171467`*^9}, {3.822505655043681*^9, 3.8225056590877457`*^9}, {3.8225056942565536`*^9, 3.822505694343998*^9}, 3.8225392160629177`*^9}, CellLabel->"In[14]:=",ExpressionUUID->"eca3f930-5a68-478e-82f7-834ce5f65ec5"], Cell[BoxData[ RowBox[{ RowBox[{"colsIn", "=", RowBox[{"Map", "[", RowBox[{"Reverse", ",", RowBox[{ RowBox[{ RowBox[{"Flatten", "[", RowBox[{"#", ",", "1"}], "]"}], "&"}], "/@", RowBox[{"Map", "[", RowBox[{"Thread", ",", RowBox[{"Extract", "[", RowBox[{"extracted", ",", RowBox[{"List", "/@", "colStringIds"}]}], "]"}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ",", RowBox[{"{", "2", "}"}]}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822505548285812*^9, 3.822505553180203*^9}, { 3.822505584049301*^9, 3.822505595421825*^9}, {3.82250564619384*^9, 3.822505649495471*^9}, {3.8225056909482403`*^9, 3.822505691120751*^9}, 3.822539218373446*^9}, CellLabel->"In[15]:=",ExpressionUUID->"5aa1f04d-9c2c-4fc9-9141-460fc6348539"], Cell["For example:", "Text", CellChangeTimes->{{3.822539224452923*^9, 3.822539226059381*^9}},ExpressionUUID->"ea1249c9-39db-4a08-80f7-\ 13bb19b4b25a"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"colsIn", "[", RowBox[{"[", "1", "]"}], "]"}]], "Input", CellChangeTimes->{{3.822539219671064*^9, 3.822539221371369*^9}, { 3.822539253423045*^9, 3.8225392540765*^9}}, CellLabel->"In[16]:=",ExpressionUUID->"4e23066e-5bf7-4f9d-b4ae-4253517db36a"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"4", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 0, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0., 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 0, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 0, 0], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {GrayLevel[0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->GrayLevel[0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"GrayLevel", "[", "0", "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = GrayLevel[0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["GrayLevelColorValueSelector"], { 0, {Left, Bottom}}, {Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], GrayLevel[0], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[0, 0, 1], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0., 0., 0.6666666666666666], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"0", ",", "0", ",", "1"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[0, 0, 1]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[0, 0, 1], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[0, 0, 1], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0., 0., 0.6666666666666666], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"0", ",", "0", ",", "1"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[0, 0, 1]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[0, 0, 1], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 0, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0., 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 0, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 0, 0], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 0, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0., 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 0, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 0, 0], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 0, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0., 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 0, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 0, 0], Editable->False, Selectable->False]}], "}"}], ",", RowBox[{"{", RowBox[{"12", ",", InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {GrayLevel[0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->GrayLevel[0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"GrayLevel", "[", "0", "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = GrayLevel[0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["GrayLevelColorValueSelector"], { 0, {Left, Bottom}}, {Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], GrayLevel[0], Editable->False, Selectable->False]}], "}"}]}], "}"}]], "Output", CellChangeTimes->{{3.822539226924357*^9, 3.8225392543434153`*^9}, 3.8225484587841597`*^9, 3.822552522812119*^9, 3.822552948150165*^9}, CellLabel->"Out[16]=",ExpressionUUID->"d532308a-3bee-465f-85da-222cf61ed03a"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Construct a system of constraints", "Title", CellChangeTimes->{{3.822505785616539*^9, 3.822505794904256*^9}},ExpressionUUID->"037c6dbc-3a59-473b-8fb0-\ 315c7c1cb529"], Cell["For more detail, see the z3interop.nb example notebook.", "Text", CellChangeTimes->{{3.822552354332161*^9, 3.822552363817124*^9}},ExpressionUUID->"cb26ffa5-b5c2-4596-b123-\ 78036efb6fd2"], Cell["\<\ Define an arbitrary mapping of colours to numbers, so that we can represent \ the problem in integers.\ \>", "Text", CellChangeTimes->{{3.82253923819639*^9, 3.822539246996353*^9}, { 3.82254886640399*^9, 3.8225488729483*^9}},ExpressionUUID->"12e99fd2-db46-43e8-8071-524c2583d0b9"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"mapping", "=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"colours", "=", RowBox[{"Union", "@", RowBox[{"Cases", "[", RowBox[{"rowsIn", ",", RowBox[{"_", "?", "ColorQ"}], ",", "All"}], "]"}]}]}], "}"}], ",", RowBox[{ RowBox[{"Assert", "[", RowBox[{"FreeQ", "[", RowBox[{"colours", ",", "White"}], "]"}], "]"}], ";", RowBox[{"MapIndexed", "[", RowBox[{ RowBox[{ RowBox[{"#1", "\[Rule]", RowBox[{"First", "@", "#2"}]}], "&"}], ",", RowBox[{"Append", "[", RowBox[{"colours", ",", "White"}], "]"}]}], "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.8225484982761383`*^9, 3.82254858099977*^9}}, CellLabel->"In[17]:=",ExpressionUUID->"0d18a283-ce67-42f6-a22b-58c7601f110b"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{ InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {GrayLevel[0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->GrayLevel[0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"GrayLevel", "[", "0", "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = GrayLevel[0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["GrayLevelColorValueSelector"], { 0, {Left, Bottom}}, {Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], GrayLevel[0], Editable->False, Selectable->False], "\[Rule]", "1"}], ",", RowBox[{ InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[0, 0, 1], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0., 0., 0.6666666666666666], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"0", ",", "0", ",", "1"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[0, 0, 1]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[0, 0, 1], Editable->False, Selectable->False], "\[Rule]", "2"}], ",", RowBox[{ InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 0, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0., 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "0", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 0, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 0, 0], Editable->False, Selectable->False], "\[Rule]", "3"}], ",", RowBox[{ InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {RGBColor[1, 1, 0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->RGBColor[0.6666666666666666, 0.6666666666666666, 0.], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"RGBColor", "[", RowBox[{"1", ",", "1", ",", "0"}], "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = RGBColor[1, 1, 0]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["RGBColorValueSelector"], {0, {Left, Bottom}}, { Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], RGBColor[1, 1, 0], Editable->False, Selectable->False], "\[Rule]", "4"}], ",", RowBox[{ InterpretationBox[ ButtonBox[ TooltipBox[ GraphicsBox[{ {GrayLevel[0], RectangleBox[{0, 0}]}, {GrayLevel[0], RectangleBox[{1, -1}]}, {GrayLevel[1], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, DefaultBaseStyle->"ColorSwatchGraphics", Frame->True, FrameStyle->GrayLevel[0.6666666666666666], FrameTicks->None, ImageSize-> Dynamic[{ Automatic, 1.35 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ Magnification]}], PlotRangePadding->None], StyleBox[ RowBox[{"GrayLevel", "[", "1", "]"}], NumberMarks -> False]], Appearance->None, BaseStyle->{}, BaselinePosition->Baseline, ButtonFunction:>With[{Typeset`box$ = EvaluationBox[]}, If[ Not[ AbsoluteCurrentValue["Deployed"]], SelectionMove[Typeset`box$, All, Expression]; FrontEnd`Private`$ColorSelectorInitialAlpha = 1; FrontEnd`Private`$ColorSelectorInitialColor = GrayLevel[1]; FrontEnd`Private`$ColorSelectorUseMakeBoxes = True; MathLink`CallFrontEnd[ FrontEnd`AttachCell[Typeset`box$, FrontEndResource["GrayLevelColorValueSelector"], { 0, {Left, Bottom}}, {Left, Top}, "ClosingActions" -> { "SelectionDeparture", "ParentChanged", "EvaluatorQuit"}]]]], DefaultBaseStyle->{}, Evaluator->Automatic, Method->"Preemptive"], GrayLevel[1], Editable->False, Selectable->False], "\[Rule]", "5"}]}], "}"}]], "Output", CellChangeTimes->{{3.822548501811932*^9, 3.822548530074448*^9}, { 3.8225485773412*^9, 3.822548581500639*^9}, 3.822548874410872*^9, 3.822550883185535*^9, 3.8225514250140057`*^9, 3.82255157770621*^9, 3.822551634151635*^9, 3.822551802460992*^9, 3.8225518885913057`*^9, 3.822551964229311*^9, 3.822552064437503*^9, 3.822552525157888*^9, 3.822552949910215*^9}, CellLabel->"Out[17]=",ExpressionUUID->"1b183895-cd3c-409c-a5b1-29cdb4483a1a"] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"constrainedColumns", ":=", RowBox[{"MapIndexed", "[", RowBox[{ RowBox[{ RowBox[{"gapsToConstraints", "[", RowBox[{"#1", ",", RowBox[{"First", "@", "#2"}], ",", RowBox[{"Length", "@", "rowsIn"}], ",", "colGap"}], "]"}], "&"}], ",", "colsIn"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822542276174329*^9, 3.8225423268775177`*^9}, 3.822546145935195*^9}, CellLabel->"In[18]:=",ExpressionUUID->"c08dcb76-025b-469d-be95-bf8bf64eb836"], Cell[BoxData[ RowBox[{ RowBox[{"constrainedRows", ":=", RowBox[{"MapIndexed", "[", RowBox[{ RowBox[{ RowBox[{"gapsToConstraints", "[", RowBox[{"#1", ",", RowBox[{"First", "@", "#2"}], ",", RowBox[{"Length", "@", "colsIn"}], ",", "rowGap"}], "]"}], "&"}], ",", "rowsIn"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822542338936245*^9, 3.82254235153629*^9}, 3.822546147070763*^9}, CellLabel->"In[19]:=",ExpressionUUID->"021dba8f-7b7e-448c-912b-c19261def5b3"], Cell[BoxData[ RowBox[{ RowBox[{"additionalConstraints", ":=", RowBox[{"constrainedCells", "[", RowBox[{ "rowGap", ",", "colGap", ",", "cell", ",", "rowsIn", ",", "colsIn", ",", "constrainedRows", ",", "constrainedColumns", ",", "mapping"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822551299141808*^9, 3.8225513326405487`*^9}, { 3.8225522315043573`*^9, 3.8225522323102083`*^9}, {3.822552952898403*^9, 3.822552953456399*^9}}, CellLabel->"In[20]:=",ExpressionUUID->"b6ffd7d9-03e4-42ea-a327-6d7466f527d4"], Cell["Form the program:", "Text", CellChangeTimes->{{3.822543172308032*^9, 3.8225431759837637`*^9}, { 3.8225432065952673`*^9, 3.8225432068193693`*^9}},ExpressionUUID->"4888e038-3eeb-4e51-b9b5-\ 02abc4f0daaf"], Cell[BoxData[ RowBox[{ RowBox[{"vars", ":=", RowBox[{"DeleteDuplicates", "@", RowBox[{"Flatten", "@", RowBox[{"{", RowBox[{ RowBox[{"Cases", "[", RowBox[{ RowBox[{"{", RowBox[{ "constrainedCells", ",", "constrainedColumns", ",", "constrainedRows"}], "}"}], ",", RowBox[{"colGap", "[", RowBox[{"_", ",", "_"}], "]"}], ",", "Infinity"}], "]"}], ",", RowBox[{"Cases", "[", RowBox[{ RowBox[{"{", RowBox[{ "additionalConstraints", ",", "constrainedColumns", ",", "constrainedRows"}], "}"}], ",", RowBox[{"rowGap", "[", RowBox[{"_", ",", "_"}], "]"}], ",", "Infinity"}], "]"}], ",", RowBox[{"Cases", "[", RowBox[{ RowBox[{"{", RowBox[{ "additionalConstraints", ",", "constrainedColumns", ",", "constrainedRows"}], "}"}], ",", RowBox[{"cell", "[", RowBox[{"_", ",", "_"}], "]"}], ",", "Infinity"}], "]"}]}], "}"}]}]}]}], ";"}]], "Input", CellChangeTimes->{{3.788337270244377*^9, 3.7883374021686573`*^9}, { 3.822551373702321*^9, 3.822551378429165*^9}}, CellLabel->"In[21]:=",ExpressionUUID->"60f12c2a-f204-4f40-9b8b-de31c09b25ad"], Cell[BoxData[ RowBox[{"constraints", ":=", RowBox[{"Assertion", "/@", RowBox[{"Flatten", "[", RowBox[{"{", RowBox[{ "additionalConstraints", ",", "constrainedColumns", ",", "constrainedRows"}], "}"}], "]"}]}]}]], "Input", CellChangeTimes->{{3.788337413343278*^9, 3.7883374276446743`*^9}, { 3.822552199087512*^9, 3.822552200916888*^9}}, CellLabel->"In[22]:=",ExpressionUUID->"54dec3cc-3d2a-42aa-906c-23244fa06175"], Cell[BoxData[ RowBox[{"declared", ":=", RowBox[{ RowBox[{ RowBox[{"Declare", "[", RowBox[{"#", ",", "Integer"}], "]"}], "&"}], "/@", "vars"}]}]], "Input", CellChangeTimes->{{3.788337418424449*^9, 3.788337419730074*^9}}, CellLabel->"In[23]:=",ExpressionUUID->"f347490a-c18b-4ef0-9074-80bea49bce46"], Cell[BoxData[ RowBox[{ RowBox[{"symbols", "=", RowBox[{"{", RowBox[{ RowBox[{"colGap", "\[Rule]", "\"\\""}], ",", RowBox[{"rowGap", "\[Rule]", "\"\\""}], ",", RowBox[{"cell", "\[Rule]", "\"\\""}]}], "}"}]}], ";"}]], "Input", CellChangeTimes->{{3.822551391639176*^9, 3.8225514083491096`*^9}}, CellLabel->"In[24]:=",ExpressionUUID->"94f11626-0311-45f4-9ede-acacd293fc56"], Cell[BoxData[ RowBox[{ RowBox[{"program", ":=", RowBox[{ RowBox[{"Riffle", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"toString", "[", RowBox[{"symbols", ",", "#"}], "]"}], "&"}], "/@", RowBox[{"Flatten", "@", RowBox[{"{", RowBox[{ "declared", ",", "constraints", ",", "CheckSat", ",", "GetModel"}], "}"}]}]}], ",", "\"\<\\n\>\""}], "]"}], "//", "StringJoin"}]}], ";"}]], "Input", CellChangeTimes->{{3.8225471941677437`*^9, 3.822547226548307*^9}, { 3.822551382478524*^9, 3.8225513933565083`*^9}}, CellLabel->"In[25]:=",ExpressionUUID->"d3f12812-6d0b-4848-a83c-ca671d057b7c"], Cell["\<\ This is an example where the built-in Z3Interop `toString` does not know how \ to perform addition. Teach it:\ \>", "Text", CellChangeTimes->{{3.8225521209433327`*^9, 3.822552141558868*^9}},ExpressionUUID->"2989a4a2-698e-441f-8bc7-\ 2b4e5c9a8602"], Cell[BoxData[ RowBox[{ RowBox[{"toString", "[", RowBox[{"symbols_", ",", RowBox[{"a_", "+", "b_"}]}], "]"}], ":=", RowBox[{"StringJoin", "[", RowBox[{"\"\<(+ \>\"", ",", RowBox[{"toString", "[", RowBox[{"symbols", ",", "a"}], "]"}], ",", "\"\< \>\"", ",", RowBox[{"toString", "[", RowBox[{"symbols", ",", "b"}], "]"}], ",", "\"\<)\>\""}], "]"}]}]], "Input", CellChangeTimes->{{3.822552142072356*^9, 3.822552158985262*^9}}, CellLabel->"In[26]:=",ExpressionUUID->"73ddd8a0-a167-4e89-a450-94844fba891a"], Cell["Write and run the program:", "Text", CellChangeTimes->{{3.822543210275341*^9, 3.8225432127634993`*^9}},ExpressionUUID->"1aa66ce9-f6a2-456a-b20d-\ 7139617c7de8"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"s", "=", RowBox[{"OpenWrite", "[", RowBox[{ RowBox[{"FormatType", "\[Rule]", "OutputForm"}], ",", RowBox[{"PageWidth", "\[Rule]", "Infinity"}]}], "]"}]}], ";", RowBox[{"Write", "[", RowBox[{"s", ",", "program"}], "]"}], ";", RowBox[{"outputLocation", "=", RowBox[{"Close", "[", "s", "]"}]}]}]], "Input", CellChangeTimes->{{3.788204653394897*^9, 3.788204656650256*^9}, { 3.788206375808857*^9, 3.788206441405658*^9}, {3.788206499417495*^9, 3.7882065027668943`*^9}, {3.788206545018368*^9, 3.788206547998867*^9}, { 3.788206601390177*^9, 3.78820660493946*^9}, {3.822551364797474*^9, 3.82255136669978*^9}, {3.822552086285446*^9, 3.8225520867737217`*^9}}, CellLabel->"In[27]:=",ExpressionUUID->"f752ce23-eb81-48db-92e7-b4a7837180db"], Cell[BoxData["\<\"/private/var/folders/hz/9prp92151cqgf8370qt8ngfw0000gn/T/\ m00000685231\"\>"], "Output", CellChangeTimes->{ 3.788206454133148*^9, 3.78820650304189*^9, 3.78820655383759*^9, { 3.788206602224842*^9, 3.788206605208042*^9}, {3.788206866382893*^9, 3.788206870838726*^9}, 3.788206926487749*^9, 3.7882069866619987`*^9, 3.78820717194135*^9, 3.788207701938747*^9, 3.788207936015203*^9, 3.788208059486527*^9, 3.788337440025797*^9, {3.78833747166005*^9, 3.7883374799615707`*^9}, 3.788337530607819*^9, 3.788337662892407*^9, 3.7883377082739153`*^9, 3.788337861220901*^9, 3.788338054966352*^9, 3.788338209083877*^9, 3.788338266764277*^9, 3.788338372006834*^9, 3.7883385688847513`*^9, 3.788339195596026*^9, 3.822501767232312*^9, 3.82250200835958*^9, 3.822505723689625*^9, 3.822542389666006*^9, { 3.8225442496405077`*^9, 3.822544289501874*^9}, 3.822544468071608*^9, 3.822544599124298*^9, 3.822544762148199*^9, 3.8225456626677628`*^9, 3.8225460990024567`*^9, 3.8225461602114887`*^9, 3.822546351381563*^9, 3.822546950734087*^9, 3.822547003022386*^9, 3.822547198224662*^9, 3.8225472455528593`*^9, {3.822547687226099*^9, 3.822547694963635*^9}, 3.822548188967702*^9, 3.822548256695305*^9, 3.822548376309533*^9, 3.822548438047086*^9, 3.822552087067842*^9, 3.8225521614619417`*^9, 3.822552204768271*^9, 3.822552237197201*^9, 3.82255255088132*^9, 3.82255297484801*^9}, CellLabel->"Out[27]=",ExpressionUUID->"90435790-d03b-4895-8e6e-ad611998423d"] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"output", "=", RowBox[{ RowBox[{"RunProcess", "[", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", "outputLocation"}], "}"}], ",", RowBox[{"ProcessEnvironment", "\[Rule]", RowBox[{"<|", RowBox[{"\"\\"", "\[Rule]", "\"\\""}], "|>"}]}]}], "]"}], "[", "\"\\"", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.788206570918592*^9, 3.788206682075213*^9}, 3.788207709771576*^9, {3.822501822796315*^9, 3.822501836476252*^9}}, CellLabel->"In[28]:=",ExpressionUUID->"c3f34f18-a080-4e3f-b261-ce576e384c3c"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"StringCases", "[", RowBox[{"output", ",", RowBox[{"RegularExpression", "[", "\"\<(un)?sat\>\"", "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.7882077147165737`*^9, 3.7882077481216373`*^9}, { 3.788207939638994*^9, 3.7882079405578823`*^9}, {3.822548377626794*^9, 3.822548378293522*^9}, 3.822552244696313*^9}, CellLabel->"In[29]:=",ExpressionUUID->"337a81cb-cc45-4983-9618-d1b8fb1814b8"], Cell[BoxData[ RowBox[{"{", "\<\"sat\"\>", "}"}]], "Output", CellChangeTimes->{ 3.82250183870959*^9, 3.8225057322030773`*^9, 3.8225443134502497`*^9, 3.822544482601907*^9, 3.822545664172749*^9, {3.822546158951002*^9, 3.822546161954015*^9}, 3.822546354125864*^9, 3.822546952921803*^9, 3.822547004155629*^9, 3.822547697846916*^9, {3.822552240026669*^9, 3.822552244968198*^9}, 3.822552574401678*^9, 3.822552992524292*^9}, CellLabel->"Out[29]=",ExpressionUUID->"416009e5-cc45-4adc-b60b-842f53f11b15"] }, Open ]], Cell["\<\ Parse out the solution (sorry about the rendered PDF being so blurry):\ \>", "Text", CellChangeTimes->{{3.8225522561723948`*^9, 3.822552258214281*^9}, { 3.822553788625781*^9, 3.82255379497896*^9}},ExpressionUUID->"b31fa580-b4f1-4f39-9cba-\ 6ec7ecad2d10"], Cell[BoxData[ RowBox[{ RowBox[{"answer", "=", RowBox[{"getDefinitions", "[", RowBox[{"symbols", ",", "output"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.822550211980287*^9, 3.822550236471098*^9}, { 3.822550869926653*^9, 3.8225508721902733`*^9}}, CellLabel->"In[30]:=",ExpressionUUID->"b7b281f7-4fcf-4ec5-a850-198078988a38"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"cell", "[", RowBox[{"i", ",", "j"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "@", "rowsIn"}]}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "@", "colsIn"}]}], "}"}]}], "]"}], "/.", "answer"}], "/.", RowBox[{"(", RowBox[{"Reverse", "/@", "mapping"}], ")"}]}], "//", "Image"}]], "Input", CellChangeTimes->{{3.788205932636307*^9, 3.7882059525632257`*^9}, { 3.78820611891381*^9, 3.788206121734747*^9}, {3.788207768105526*^9, 3.788207778758956*^9}, 3.822506363570977*^9, {3.8225508681982317`*^9, 3.822550868644143*^9}, {3.822552272977952*^9, 3.822552300263513*^9}, { 3.822553041927376*^9, 3.822553042283087*^9}, {3.822553609635956*^9, 3.822553629570902*^9}, 3.8225536830541773`*^9}, CellLabel->"In[77]:=",ExpressionUUID->"074f239e-cdbd-42c1-b518-6147302011e9"], Cell[BoxData[ GraphicsBox[ TagBox[RasterBox[CompressedData[" 1:eJztlV2KFTEQhS8K4jbcgr4K4hbGFYygTwPC+CC+uXQVRJqQpE5VnUpV+vaB SE3fdP2cfB3ffP728PXF7Xb7/vrPPw+PPz4+Pz/+/PTq7x9fHp/evX16+Sd8 /2/9jW+3Xx9u/+WNPYvVQ9WYle9a61i6Z4arenyPa6XXrFoVYs1cETWvlcMz K3+1+OLZxljveZQnrLyePLvEGTyP6ldcPbG4835TV2xje5WXVZYkD2sRfe4S Z9evHp+VizPM0Iuz61ePL573mKdVtj9nXx5FcBQ9C7I/4hth5MhmZYellZRn 9Xlpe9buiZiNkeNsizUjIm0/0eflkZbt6NkYOc6wWPOiZ5rNs1Yrelp1pr3Y K3bP3pya2VFPVp6d1iutduRZc75eRZ9RBs/ZvLIZbv08i0e9vhj+rDqvi2e/ zuoRWyyfVtba5azYczFyjVSJSa0iWFpZ6+LZHh+l5RPxepWiWVpZayeetWyP 9md6avUaEdtblqp4nKWjrz2PUW5n+5F9q2JEyP5KPFfwtQrPR4149tzhFTxF +Wz7RtnL4LmCl6t5ZtwBZ76fEcai2baqgpcIG14d82lzj87TE1fxuieEYeS5 Rqx7rIKXEd+pRSPmL55tzzU6A8+R/+9YhPDMmieCw94sqLfZZ1Hhm0b9Rs8a vRuZQhluYyufbM6luaw8a2oxVIHVi2c9kxrOonnW9hCpCqx6z210V7Rzstm2 MqyZje0LMyejVs9Pz/PouK2PxB5u23q993bieSXbq3jueehlG5lJ6gvZP5LV S6tYDCP5o3geeV0hj5VntqLmZtVG9mvyS/1onvdqzeJRTk+sFZPbjHOXnkus Ij30ckX4qZUnp+bbnsWz/KyY4Q+yJ5p5D9vH39u9o980sdaTCEWcBcIz2hsr tpy7RSvPziorz6Pz7e1p67G/a5a0vXj6iua5sjz3tvR8xinKMIPJLLa1tVj1 0TsBia3+VLwrpN6knq1sjt5H63pnR96Nys+KPd5KeUY9t8+j7wpNXUYPkjej 30bvs7WCT+2dNqqL9KPpmfntIDHr/onszcJnxHPrvCOhPEh1tfLeH+z+WTHS JzpLZJ8W37R8Rp4Fomo8a/as9hPxQaop7Wf3xuQzYr9lFkbcy68RcqbauArP KLuz2SN708Yr+bT0c3xujXu1JM3eY/TGYJjFv/Rub/YsHjR8Ru+39O+Vhmek R2sPEQwjfUd8F6xZtLFnReTR5GRJ4lLrq7UH1rmz/UHE/L5WxgjP0nOWoudd VUf6jq3vr9SuPDNils7M8+w39A7fRehc7FmPOZA4WvfCs/Z+24FrD8MstrXn 4fEVeffiGeu/iiIY9rCN3s/Sfm3+2X5PLHESURPpxcuz5x7pyXsHZi/v7O0s bcxSBs9R9SM4ZCmbR9Qfdp42ZvsZHXu4qsghS9n8okxG8Kzxx7I/Kj7Wsiri jCooi7eV34LGBzT2vOut1Yu1ivaZnd8bn5Xn7L68s4zOTKtdfJbmRuOsuux+ WmWz6fUTnVPS6FsZPZfiUf6LZ24/rbI59Xro4fn4TjTPo7zRXDFqaWdf3WeW P566SD9HSc9nMZJDime65/MaeXXPPI84G/kz+l1T6/j3LEZ0b+fVi5me7OiP lKfdJ/mGxto+EVXwLYPnKE+y/ImuhXilqTvLIfE/UzZXK2NUu/AcnR/h7+K5 JsNHVeY5IufKee08/wYTjaG3 "], {{0, 60}, {60, 0}}, {0., 1.}, ColorFunction->RGBColor], BoxForm`ImageTag["Real32", ColorSpace -> "RGB", Interleaving -> True], Selectable->False], DefaultBaseStyle->"ImageGraphics", ImageSize->{345.1328125, Automatic}, ImageSizeRaw->{60, 60}, PlotRange->{{0, 60}, {0, 60}}]], "Output", CellChangeTimes->{{3.788205948079363*^9, 3.788205952768847*^9}, 3.7882061219056168`*^9, 3.7882067040548162`*^9, {3.788207765574544*^9, 3.788207778997447*^9}, 3.822506162488027*^9, 3.822506363855856*^9, 3.822550872991807*^9, {3.822552282230081*^9, 3.8225523005069237`*^9}, 3.822552997248495*^9, 3.8225530433821087`*^9, 3.8225536323335543`*^9, 3.822553685761364*^9}, CellLabel->"Out[77]=",ExpressionUUID->"167bf944-8d85-4bca-b05e-1bb05b3d0394"] }, Open ]] }, Open ]] }, WindowSize->{808, 755}, WindowMargins->{{160, Automatic}, {Automatic, 26}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, TaggingRules->{ScrollPosition -> {0., 24.}, "TryRealOnly" -> False}, FrontEndVersion->"12.0 for Mac OS X x86 (64-bit) (April 8, 2019)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[558, 20, 416, 10, 46, "Input",ExpressionUUID->"3c1daa83-8c0a-4e99-ad7f-c3f04877f88a", InitializationCell->True], Cell[977, 32, 296, 7, 30, "Input",ExpressionUUID->"7775dbb6-7ac4-457a-96d6-a9ae875b828b"], Cell[CellGroupData[{ Cell[1298, 43, 168, 3, 98, "Title",ExpressionUUID->"02135865-b6e5-4cad-ad4b-5778f2375c71"], Cell[1469, 48, 219, 5, 35, "Text",ExpressionUUID->"54930d51-3a8d-4d53-bf35-80e6641e2c1b"], Cell[1691, 55, 978, 26, 136, "Input",ExpressionUUID->"f6d80843-4dfa-4983-94cf-3ae0a4d9d2f5"], Cell[2672, 83, 4448, 106, 241, "Input",ExpressionUUID->"dcba92b8-bdae-4748-9c95-dbbe8d4931ce"], Cell[7123, 191, 416, 10, 30, "Input",ExpressionUUID->"c02f4912-315d-4b9b-9cf1-77bb3afc8c01"], Cell[7542, 203, 556, 14, 30, "Input",ExpressionUUID->"cc4e3da7-ea3a-4a6a-9637-548147cd7fd7"], Cell[CellGroupData[{ Cell[8123, 221, 1046, 26, 52, "Input",ExpressionUUID->"3f064e76-94cf-47b5-94d0-1e1467e317b2"], Cell[9172, 249, 1135, 18, 77, "Output",ExpressionUUID->"e09a3cba-325e-4344-be44-02f3917bee2a"] }, Open ]], Cell[CellGroupData[{ Cell[10344, 272, 965, 26, 52, "Input",ExpressionUUID->"138e3b90-4c0c-4db8-aaa5-3e0aafbd1af5"], Cell[11312, 300, 1089, 17, 77, "Output",ExpressionUUID->"fc20ecc6-fcd2-49fc-9758-98259e023109"] }, Open ]], Cell[12416, 320, 844, 20, 73, "Input",ExpressionUUID->"eca3f930-5a68-478e-82f7-834ce5f65ec5"], Cell[13263, 342, 835, 20, 73, "Input",ExpressionUUID->"5aa1f04d-9c2c-4fc9-9141-460fc6348539"], Cell[14101, 364, 154, 3, 35, "Text",ExpressionUUID->"ea1249c9-39db-4a08-80f7-13bb19b4b25a"], Cell[CellGroupData[{ Cell[14280, 371, 274, 5, 30, "Input",ExpressionUUID->"4e23066e-5bf7-4f9d-b4ae-4253517db36a"], Cell[14557, 378, 13959, 363, 34, "Output",ExpressionUUID->"d532308a-3bee-465f-85da-222cf61ed03a"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[28565, 747, 176, 3, 98, "Title",ExpressionUUID->"037c6dbc-3a59-473b-8fb0-315c7c1cb529"], Cell[28744, 752, 197, 3, 35, "Text",ExpressionUUID->"cb26ffa5-b5c2-4596-b123-78036efb6fd2"], Cell[28944, 757, 295, 6, 35, "Text",ExpressionUUID->"12e99fd2-db46-43e8-8071-524c2583d0b9"], Cell[CellGroupData[{ Cell[29264, 767, 839, 23, 73, "Input",ExpressionUUID->"0d18a283-ce67-42f6-a22b-58c7601f110b"], Cell[30106, 792, 8730, 227, 34, "Output",ExpressionUUID->"1b183895-cd3c-409c-a5b1-29cdb4483a1a"] }, Open ]], Cell[38851, 1022, 528, 13, 52, "Input",ExpressionUUID->"c08dcb76-025b-469d-be95-bf8bf64eb836"], Cell[39382, 1037, 522, 13, 52, "Input",ExpressionUUID->"021dba8f-7b7e-448c-912b-c19261def5b3"], Cell[39907, 1052, 540, 11, 52, "Input",ExpressionUUID->"b6ffd7d9-03e4-42ea-a327-6d7466f527d4"], Cell[40450, 1065, 214, 4, 35, "Text",ExpressionUUID->"4888e038-3eeb-4e51-b9b5-02abc4f0daaf"], Cell[40667, 1071, 1297, 34, 178, "Input",ExpressionUUID->"60f12c2a-f204-4f40-9b8b-de31c09b25ad"], Cell[41967, 1107, 448, 10, 52, "Input",ExpressionUUID->"54dec3cc-3d2a-42aa-906c-23244fa06175"], Cell[42418, 1119, 316, 7, 30, "Input",ExpressionUUID->"f347490a-c18b-4ef0-9074-80bea49bce46"], Cell[42737, 1128, 425, 9, 30, "Input",ExpressionUUID->"94f11626-0311-45f4-9ede-acacd293fc56"], Cell[43165, 1139, 672, 18, 73, "Input",ExpressionUUID->"d3f12812-6d0b-4848-a83c-ca671d057b7c"], Cell[43840, 1159, 261, 6, 35, "Text",ExpressionUUID->"2989a4a2-698e-441f-8bc7-2b4e5c9a8602"], Cell[44104, 1167, 547, 13, 52, "Input",ExpressionUUID->"73ddd8a0-a167-4e89-a450-94844fba891a"], Cell[44654, 1182, 170, 3, 35, "Text",ExpressionUUID->"1aa66ce9-f6a2-456a-b20d-7139617c7de8"], Cell[CellGroupData[{ Cell[44849, 1189, 807, 16, 73, "Input",ExpressionUUID->"f752ce23-eb81-48db-92e7-b4a7837180db"], Cell[45659, 1207, 1513, 22, 34, "Output",ExpressionUUID->"90435790-d03b-4895-8e6e-ad611998423d"] }, Open ]], Cell[47187, 1232, 640, 15, 73, "Input",ExpressionUUID->"c3f34f18-a080-4e3f-b261-ce576e384c3c"], Cell[CellGroupData[{ Cell[47852, 1251, 428, 8, 30, "Input",ExpressionUUID->"337a81cb-cc45-4983-9618-d1b8fb1814b8"], Cell[48283, 1261, 515, 8, 34, "Output",ExpressionUUID->"416009e5-cc45-4adc-b60b-842f53f11b15"] }, Open ]], Cell[48813, 1272, 270, 6, 35, "Text",ExpressionUUID->"b31fa580-b4f1-4f39-9cba-6ec7ecad2d10"], Cell[49086, 1280, 346, 7, 30, "Input",ExpressionUUID->"b7b281f7-4fcf-4ec5-a850-198078988a38"], Cell[CellGroupData[{ Cell[49457, 1291, 1005, 23, 52, "Input",ExpressionUUID->"074f239e-cdbd-42c1-b518-6147302011e9"], Cell[50465, 1316, 2575, 46, 362, "Output",ExpressionUUID->"167bf944-8d85-4bca-b05e-1bb05b3d0394"] }, Open ]] }, Open ]] } ] *)