From f99d4ff0b369f2e0ec71a68d71550f0dc63e0785 Mon Sep 17 00:00:00 2001 From: yut23 Date: Wed, 31 Jan 2024 00:19:40 -0500 Subject: [PATCH] 2023: day 24 part 2 complete in C++ --- 2023/day24.nb | 968 +++++++++++++++++++++++ 2023/day24b.nb | 1639 +++++++++++++++++++++++++++++++++++++++ 2023/src/day24.cpp | 54 +- 2023/src/day24.hpp | 89 ++- 2023/src/day24.py | 313 +++++++- 2023/src/gauss_elim.hpp | 260 +++++++ 2023/src/util/util.hpp | 4 + 7 files changed, 3289 insertions(+), 38 deletions(-) create mode 100644 2023/day24.nb create mode 100644 2023/day24b.nb create mode 100644 2023/src/gauss_elim.hpp diff --git a/2023/day24.nb b/2023/day24.nb new file mode 100644 index 0000000..b27d6f7 --- /dev/null +++ b/2023/day24.nb @@ -0,0 +1,968 @@ +(* Content-type: application/vnd.wolfram.mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 13.3' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 158, 7] +NotebookDataLength[ 34237, 960] +NotebookOptionsPosition[ 31145, 899] +NotebookOutlinePosition[ 31540, 915] +CellTagsIndexPosition[ 31497, 912] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ +Cell[BoxData[{ + RowBox[{ + RowBox[{"pAx", "=", "19"}], ";", + RowBox[{"pAy", "=", "13"}], ";", + RowBox[{"pAz", "=", "30"}], ";", + RowBox[{"vAx", "=", + RowBox[{"-", "2"}]}], ";", + RowBox[{"vAy", "=", "1"}], ";", + RowBox[{"vAz", "=", + RowBox[{"-", "2"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"pBx", "=", "18"}], ";", + RowBox[{"pBy", "=", "19"}], ";", + RowBox[{"pBz", "=", "22"}], ";", + RowBox[{"vBx", "=", + RowBox[{"-", "1"}]}], ";", + RowBox[{"vBy", "=", + RowBox[{"-", "1"}]}], ";", + RowBox[{"vBz", "=", + RowBox[{"-", "2"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"pCx", "=", "20"}], ";", + RowBox[{"pCy", "=", "25"}], ";", + RowBox[{"pCz", "=", "34"}], ";", + RowBox[{"vCx", "=", + RowBox[{"-", "2"}]}], ";", + RowBox[{"vCy", "=", + RowBox[{"-", "2"}]}], ";", + RowBox[{"vCz", "=", + RowBox[{"-", "4"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{"(*", + RowBox[{ + RowBox[{"pCx", "=", "20"}], ";", + RowBox[{"pCy", "=", "19"}], ";", + RowBox[{"pCz", "=", "15"}], ";", + RowBox[{"vCx", "=", "1"}], ";", + RowBox[{"vCy", "=", + RowBox[{"-", "5"}]}], ";", + RowBox[{"vCz", "=", + RowBox[{"-", "3"}]}], ";"}], "*)"}]}], "\[IndentingNewLine]"}], "Input", + CellChangeTimes->{{3.913216430449355*^9, 3.9132164333845167`*^9}, { + 3.9132173236985903`*^9, 3.913217496952894*^9}, {3.9132175825355263`*^9, + 3.913217596990007*^9}, {3.913221308273324*^9, 3.913221344651147*^9}, { + 3.9132223710285*^9, 3.913222403755423*^9}, 3.9132225225374517`*^9}, + CellLabel->"In[47]:=",ExpressionUUID->"15a82781-faca-4873-867c-b12778607d19"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"FirstIfSingle", "=", + RowBox[{ + RowBox[{"If", "[", + RowBox[{ + RowBox[{ + RowBox[{"Length", "[", "#", "]"}], "==", "1"}], ",", + RowBox[{"First", "@", "#"}], ",", "#"}], "]"}], "&"}]}], ";"}]], "Input",\ + + CellChangeTimes->{{3.913221459393527*^9, 3.913221480743381*^9}}, + CellLabel->"In[50]:=",ExpressionUUID->"a78421be-a2d3-45fa-8414-57e42696f81a"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"pr", "=", + RowBox[{"{", + RowBox[{"prx", ",", "pry", ",", "prz"}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"vr", "=", + RowBox[{"{", + RowBox[{"vrx", ",", "vry", ",", "vrz"}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"ts", "=", + RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"eqns", "=", + RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"vars", "=", + RowBox[{"Flatten", "@", + RowBox[{"{", + RowBox[{"pr", ",", "vr"}], "}"}]}]}], ";"}], "\[IndentingNewLine]", + RowBox[{"Catch", "[", + RowBox[{"Do", "[", + RowBox[{ + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{"stoneLetter", ",", "t"}], "}"}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"stoneLetter", "=", + RowBox[{"ToUpperCase", "[", + RowBox[{"FromLetterNumber", "[", "stone", "]"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"t", "=", + RowBox[{"Symbol", "[", + RowBox[{"\"\\"", "<>", "stoneLetter"}], "]"}]}], ";", + "\[IndentingNewLine]", + RowBox[{"AppendTo", "[", + RowBox[{"vars", ",", "t"}], "]"}], ";", "\[IndentingNewLine]", + RowBox[{"AppendTo", "[", + RowBox[{"ts", ",", "t"}], "]"}], ";", "\[IndentingNewLine]", + RowBox[{"Do", "[", + RowBox[{ + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"stonePos", "=", + RowBox[{"Symbol", "[", + RowBox[{"\"\\"", "<>", "stoneLetter", "<>", "coord"}], + "]"}]}], ",", "\[IndentingNewLine]", + RowBox[{"stoneVel", "=", + RowBox[{"Symbol", "[", + RowBox[{"\"\\"", "<>", "stoneLetter", "<>", "coord"}], + "]"}]}], ",", "\[IndentingNewLine]", + RowBox[{"rockPos", "=", + RowBox[{"Symbol", "[", + RowBox[{"\"\\"", "<>", "coord"}], "]"}]}], ",", + "\[IndentingNewLine]", + RowBox[{"rockVel", "=", + RowBox[{"Symbol", "[", + RowBox[{"\"\\"", "<>", "coord"}], "]"}]}]}], + "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", + RowBox[{ + RowBox[{"AppendTo", "[", + RowBox[{"eqns", ",", + RowBox[{"0", "==", + RowBox[{ + RowBox[{"t", + RowBox[{"(", + RowBox[{"stoneVel", "-", "rockVel"}], ")"}]}], "+", + RowBox[{"(", + RowBox[{"stonePos", "-", "rockPos"}], ")"}]}]}]}], "]"}], + ";", "\[IndentingNewLine]", + RowBox[{"If", "[", + RowBox[{ + RowBox[{ + RowBox[{"Length", "[", "vars", "]"}], "==", + RowBox[{"Length", "[", "eqns", "]"}]}], ",", + RowBox[{"Throw", "[", + RowBox[{"{", + RowBox[{"eqns", ",", "vars"}], "}"}], "]"}]}], "]"}]}]}], + "\[IndentingNewLine]", "]"}], ",", + RowBox[{"{", + RowBox[{"coord", ",", + RowBox[{"{", + RowBox[{"\"\\"", ",", "\"\\"", ",", "\"\\""}], + "}"}]}], "}"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], + "\[IndentingNewLine]", "]"}], ",", + RowBox[{"{", + RowBox[{"stone", ",", "4"}], "}"}]}], "]"}], "]"}]}], "Input", + CellChangeTimes->{{3.9132143162514973`*^9, 3.9132143331359053`*^9}, { + 3.913214727044882*^9, 3.913214828349718*^9}, {3.913214985833992*^9, + 3.913215109351831*^9}, {3.9132151552865057`*^9, 3.913215578558507*^9}, { + 3.9132156098938103`*^9, 3.913215621788413*^9}, 3.9132156925895433`*^9, { + 3.913215771070421*^9, 3.9132157884414797`*^9}, {3.913215928814953*^9, + 3.913216013660652*^9}, {3.9132160463989153`*^9, 3.913216077907548*^9}, { + 3.913220891511644*^9, 3.9132209111495113`*^9}, {3.913221361213128*^9, + 3.913221372628224*^9}, {3.913221707202825*^9, 3.913221712242943*^9}, { + 3.913222289827681*^9, 3.913222296135397*^9}}, + CellLabel->"In[51]:=",ExpressionUUID->"fd026e70-4d35-4ad7-a145-1a4801620899"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"0", "\[Equal]", + RowBox[{"19", "-", "prx", "+", + RowBox[{"tA", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "2"}], "-", "vrx"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"13", "-", "pry", "+", + RowBox[{"tA", " ", + RowBox[{"(", + RowBox[{"1", "-", "vry"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"30", "-", "prz", "+", + RowBox[{"tA", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "2"}], "-", "vrz"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"18", "-", "prx", "+", + RowBox[{"tB", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "-", "vrx"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"19", "-", "pry", "+", + RowBox[{"tB", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "-", "vry"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"22", "-", "prz", "+", + RowBox[{"tB", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "2"}], "-", "vrz"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"20", "-", "prx", "+", + RowBox[{"tC", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "2"}], "-", "vrx"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"25", "-", "pry", "+", + RowBox[{"tC", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "2"}], "-", "vry"}], ")"}]}]}]}], ",", + RowBox[{"0", "\[Equal]", + RowBox[{"34", "-", "prz", "+", + RowBox[{"tC", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "4"}], "-", "vrz"}], ")"}]}]}]}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + "prx", ",", "pry", ",", "prz", ",", "vrx", ",", "vry", ",", "vrz", ",", + "tA", ",", "tB", ",", "tC"}], "}"}]}], "}"}]], "Output", + CellChangeTimes->{ + 3.91321638230011*^9, 3.9132209121228743`*^9, 3.913221388902269*^9, + 3.913221486684132*^9, 3.913221600485909*^9, 3.9132217218599653`*^9, + 3.9132222973359957`*^9, {3.913222381135682*^9, 3.913222406284451*^9}, + 3.91322244542172*^9, {3.913222610789645*^9, 3.913222630495276*^9}, + 3.91322507415742*^9}, + CellLabel->"Out[56]=",ExpressionUUID->"24b2837f-15fe-4b92-ac5b-e4a72f031d79"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"sols", "=", + RowBox[{"FirstIfSingle", "@", + RowBox[{"Solve", "[", + RowBox[{ + RowBox[{"Append", "[", + RowBox[{"eqns", ",", + RowBox[{"ts", ">=", "0"}]}], "]"}], ",", "vars"}], "]"}]}]}]], "Input",\ + + CellChangeTimes->{{3.913216016954628*^9, 3.913216020505004*^9}, { + 3.913216363635429*^9, 3.913216365010085*^9}, {3.913217442496828*^9, + 3.913217451049487*^9}, {3.9132175272419653`*^9, 3.91321755796189*^9}, { + 3.913217603865609*^9, 3.913217784362875*^9}, {3.913217825940037*^9, + 3.91321799128468*^9}, {3.913220713552805*^9, 3.9132207393964453`*^9}, { + 3.913220795950837*^9, 3.913220811022307*^9}, {3.9132209616730337`*^9, + 3.913221042321011*^9}, {3.913221077688962*^9, 3.913221266876068*^9}, { + 3.913221416434101*^9, 3.913221422953024*^9}, {3.9132214907213707`*^9, + 3.913221544469722*^9}, {3.9132216221175117`*^9, 3.9132216470764503`*^9}, + 3.9132217314765673`*^9, {3.913221803431634*^9, 3.913221803913269*^9}, { + 3.913222308805987*^9, 3.913222351148066*^9}, {3.9132224195863256`*^9, + 3.913222425074277*^9}, {3.9132224555873947`*^9, 3.913222498686624*^9}}, + CellLabel->"In[43]:=",ExpressionUUID->"91c19974-0016-417d-b987-15ae70ae3757"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"prx", "\[Rule]", "24"}], ",", + RowBox[{"pry", "\[Rule]", "13"}], ",", + RowBox[{"prz", "\[Rule]", "10"}], ",", + RowBox[{"vrx", "\[Rule]", + RowBox[{"-", "3"}]}], ",", + RowBox[{"vry", "\[Rule]", "1"}], ",", + RowBox[{"vrz", "\[Rule]", "2"}], ",", + RowBox[{"tA", "\[Rule]", "5"}], ",", + RowBox[{"tB", "\[Rule]", "3"}], ",", + RowBox[{"tC", "\[Rule]", "4"}]}], "}"}]], "Output", + CellChangeTimes->{{3.91322178576794*^9, 3.913221804297531*^9}, { + 3.913222299791082*^9, 3.9132223667433023`*^9}, {3.91322239949354*^9, + 3.913222423046955*^9}, {3.913222453909526*^9, 3.913222474309366*^9}, { + 3.913222617328417*^9, 3.913222631569125*^9}}, + CellLabel->"Out[43]=",ExpressionUUID->"e31571ed-86f9-4ed5-9477-fe9497375e1d"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"{", + RowBox[{"pr", ",", "vr", ",", + RowBox[{"Sequence", "@@", "ts"}]}], "}"}], "/.", "sols"}]], "Input", + CellChangeTimes->{{3.913217998775257*^9, 3.913218036412225*^9}, { + 3.9132208665793667`*^9, 3.913220879132128*^9}, {3.913220921262992*^9, + 3.913220941067419*^9}, {3.913220971480297*^9, 3.9132209826664457`*^9}, { + 3.9132213822277193`*^9, 3.913221382505252*^9}, {3.9132214398979893`*^9, + 3.913221441456409*^9}, {3.913222358995926*^9, 3.9132223591537333`*^9}}, + CellLabel->"In[44]:=",ExpressionUUID->"30db8513-478d-4058-aff5-06d32132e49b"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"24", ",", "13", ",", "10"}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"-", "3"}], ",", "1", ",", "2"}], "}"}], ",", "5", ",", "3", ",", + "4"}], "}"}]], "Output", + CellChangeTimes->{{3.9132180291226892`*^9, 3.9132180377518044`*^9}, + 3.913220886443409*^9, 3.9132209857381163`*^9, 3.913221402762908*^9, { + 3.913221435496488*^9, 3.91322144183667*^9}, 3.913221502309729*^9, + 3.913221559343424*^9, 3.913221823595462*^9, 3.913222301667314*^9, + 3.913222360201169*^9, 3.913222408363368*^9, 3.913222632322727*^9}, + CellLabel->"Out[44]=",ExpressionUUID->"2e3ab301-bc72-487d-8180-d508a7f12000"] +}, Open ]], + +Cell[BoxData[ + RowBox[{ + RowBox[{"Clear", "[", + RowBox[{ + "pAx", ",", "pAy", ",", "pAz", ",", "vAx", ",", "vAy", ",", "vAz", ",", + "pBx", ",", "pBy", ",", "pBz", ",", "vBx", ",", "vBy", ",", "vBz", ",", + "pCx", ",", "pCy", ",", "pCz", ",", "vCx", ",", "vCy", ",", "vCz"}], + "]"}], ";"}]], "Input", + CellChangeTimes->{{3.913222526960223*^9, 3.9132226070551357`*^9}}, + CellLabel->"In[21]:=",ExpressionUUID->"1302dd20-c99e-4603-9cce-69153d82f334"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Minimize", "[", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"{", + RowBox[{"p1x", ",", "p1y", ",", "p1z"}], "}"}], "+", + RowBox[{ + RowBox[{"{", + RowBox[{"v1x", ",", "v1y", ",", "v1z"}], "}"}], " ", "t"}]}], ")"}], + "-", + RowBox[{"(", + RowBox[{"pr", "+", + RowBox[{"vr", " ", "t"}]}], ")"}]}], "//", + RowBox[{ + RowBox[{"#", ".", "#"}], "&"}]}], ",", "t"}], "]"}]], "Input", + CellChangeTimes->{{3.913224919330023*^9, 3.9132250230719976`*^9}, { + 3.9132251133908243`*^9, 3.913225123789445*^9}, {3.913225156376224*^9, + 3.913225224707683*^9}}, + CellLabel->"In[79]:=",ExpressionUUID->"13dffd7a-3dd0-48a6-ae84-82da73ef4b18"], + +Cell[BoxData["$Aborted"], "Output", + CellChangeTimes->{3.913225294477664*^9}, + CellLabel->"Out[79]=",ExpressionUUID->"21f9d8fd-1e48-4946-b4ae-71631c4c1d37"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"(*", + RowBox[{"expr", "=", + RowBox[{ + RowBox[{ + RowBox[{"#", ".", "#"}], "&"}], "[", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"{", + RowBox[{"p1x", ",", "p1y", ",", "p1z"}], "}"}], "+", + RowBox[{ + RowBox[{"{", + RowBox[{"v1x", ",", "v1y", ",", "v1z"}], "}"}], " ", "t"}]}], ")"}], + "-", + RowBox[{"(", + RowBox[{"pr", "+", + RowBox[{"vr", " ", "t"}]}], ")"}]}], "]"}]}], "*)"}], + "\[IndentingNewLine]", + RowBox[{ + RowBox[{"expr", "=", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"x", "+", + RowBox[{"vx", " ", "t"}]}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"y", "+", + RowBox[{"vy", " ", "t"}]}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"z", "+", + RowBox[{"vz", " ", "t"}]}], ")"}], "2"]}]}], "\[IndentingNewLine]", + RowBox[{"sol", "=", + RowBox[{ + RowBox[{"FirstIfSingle", "@", + RowBox[{"Solve", "[", + RowBox[{ + RowBox[{ + RowBox[{"D", "[", + RowBox[{"expr", ",", "t"}], "]"}], "==", "0"}], ",", "t"}], "]"}]}], + "//", "FullSimplify"}]}]}]}]], "Input", + CellChangeTimes->{{3.913225331919985*^9, 3.913225418821918*^9}, { + 3.913225456423468*^9, 3.913225465630457*^9}, {3.9132256134856787`*^9, + 3.913225616482971*^9}, {3.9132256507861557`*^9, 3.913225677738886*^9}, { + 3.9132295956785583`*^9, 3.9132296104792128`*^9}}, + CellLabel-> + "In[144]:=",ExpressionUUID->"49dd6087-ad9d-4ba6-b259-e1711c187c98"], + +Cell[BoxData[ + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + RowBox[{"t", " ", "vx"}], "+", "x"}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + RowBox[{"t", " ", "vy"}], "+", "y"}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + RowBox[{"t", " ", "vz"}], "+", "z"}], ")"}], "2"]}]], "Output", + CellChangeTimes->{{3.913225339151169*^9, 3.913225352890115*^9}, { + 3.9132254042080297`*^9, 3.913225419156645*^9}, {3.9132254631855373`*^9, + 3.913225466035174*^9}, 3.913225679781598*^9, 3.913229612382633*^9}, + CellLabel-> + "Out[144]=",ExpressionUUID->"5fef6f26-ff9c-430d-b550-9c0b6550b6bf"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{"t", "\[Rule]", + RowBox[{"-", + FractionBox[ + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}]}], "}"}]], "Output", + CellChangeTimes->{{3.913225339151169*^9, 3.913225352890115*^9}, { + 3.9132254042080297`*^9, 3.913225419156645*^9}, {3.9132254631855373`*^9, + 3.913225466035174*^9}, 3.913225679781598*^9, 3.9132296124170313`*^9}, + CellLabel-> + "Out[145]=",ExpressionUUID->"82f5cb10-5e34-45a6-89f6-2e0defb99d7f"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Dt", "[", + RowBox[{"Log", "[", + RowBox[{"expr", "/.", "sol"}], "]"}], "]"}]], "Input", + CellChangeTimes->{{3.913226972779828*^9, 3.913227006082058*^9}, { + 3.91322731837751*^9, 3.913227392928953*^9}}, + CellLabel-> + "In[146]:=",ExpressionUUID->"bae8a795-084f-4b73-b44a-5a1ee7a96688"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"x", "-", + FractionBox[ + RowBox[{"vx", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"Dt", "[", "vx", "]"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], "+", + FractionBox[ + RowBox[{"vx", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", "vx", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"2", " ", "vy", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"2", " ", "vz", " ", + RowBox[{"Dt", "[", "vz", "]"}]}]}], ")"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}], ")"}], "2"]], "+", + RowBox[{"Dt", "[", "x", "]"}], "-", + FractionBox[ + RowBox[{"vx", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"x", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"y", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"z", " ", + RowBox[{"Dt", "[", "vz", "]"}]}], "+", + RowBox[{"vx", " ", + RowBox[{"Dt", "[", "x", "]"}]}], "+", + RowBox[{"vy", " ", + RowBox[{"Dt", "[", "y", "]"}]}], "+", + RowBox[{"vz", " ", + RowBox[{"Dt", "[", "z", "]"}]}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}]}], "+", + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"y", "-", + FractionBox[ + RowBox[{"vy", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"Dt", "[", "vy", "]"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], "+", + FractionBox[ + RowBox[{"vy", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", "vx", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"2", " ", "vy", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"2", " ", "vz", " ", + RowBox[{"Dt", "[", "vz", "]"}]}]}], ")"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}], ")"}], "2"]], "+", + RowBox[{"Dt", "[", "y", "]"}], "-", + FractionBox[ + RowBox[{"vy", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"x", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"y", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"z", " ", + RowBox[{"Dt", "[", "vz", "]"}]}], "+", + RowBox[{"vx", " ", + RowBox[{"Dt", "[", "x", "]"}]}], "+", + RowBox[{"vy", " ", + RowBox[{"Dt", "[", "y", "]"}]}], "+", + RowBox[{"vz", " ", + RowBox[{"Dt", "[", "z", "]"}]}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}]}], "+", + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"z", "-", + FractionBox[ + RowBox[{"vz", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"Dt", "[", "vz", "]"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], "+", + FractionBox[ + RowBox[{"vz", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", "vx", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"2", " ", "vy", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"2", " ", "vz", " ", + RowBox[{"Dt", "[", "vz", "]"}]}]}], ")"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}], ")"}], "2"]], "+", + RowBox[{"Dt", "[", "z", "]"}], "-", + FractionBox[ + RowBox[{"vz", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"x", " ", + RowBox[{"Dt", "[", "vx", "]"}]}], "+", + RowBox[{"y", " ", + RowBox[{"Dt", "[", "vy", "]"}]}], "+", + RowBox[{"z", " ", + RowBox[{"Dt", "[", "vz", "]"}]}], "+", + RowBox[{"vx", " ", + RowBox[{"Dt", "[", "x", "]"}]}], "+", + RowBox[{"vy", " ", + RowBox[{"Dt", "[", "y", "]"}]}], "+", + RowBox[{"vz", " ", + RowBox[{"Dt", "[", "z", "]"}]}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}]}]}], ")"}], "/", + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"x", "-", + FractionBox[ + RowBox[{"vx", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"y", "-", + FractionBox[ + RowBox[{"vy", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], "2"], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"z", "-", + FractionBox[ + RowBox[{"vz", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"vx", " ", "x"}], "+", + RowBox[{"vy", " ", "y"}], "+", + RowBox[{"vz", " ", "z"}]}], ")"}]}], + RowBox[{ + SuperscriptBox["vx", "2"], "+", + SuperscriptBox["vy", "2"], "+", + SuperscriptBox["vz", "2"]}]]}], ")"}], "2"]}], ")"}]}]], "Output", + CellChangeTimes->{{3.913226985639599*^9, 3.913227007126642*^9}, { + 3.913227322733221*^9, 3.913227395868648*^9}, 3.913229618904828*^9}, + CellLabel-> + "Out[146]=",ExpressionUUID->"4ae6700a-7dc7-429d-98ac-a49e3e817967"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Dt", "[", + RowBox[{"t", "/.", "sol"}], "]"}]], "Input", + CellChangeTimes->{{3.913227734027995*^9, 3.913227764545527*^9}}, + CellLabel-> + "In[135]:=",ExpressionUUID->"91070c74-0f8c-4aa6-af8f-7d3b4e0348a0"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + RowBox[{"b", " ", + RowBox[{"Dt", "[", "a", "]"}]}], "+", + RowBox[{"a", " ", + RowBox[{"Dt", "[", "b", "]"}]}], "+", + RowBox[{"d", " ", + RowBox[{"Dt", "[", "c", "]"}]}], "+", + RowBox[{"c", " ", + RowBox[{"Dt", "[", "d", "]"}]}], "+", + RowBox[{"f", " ", + RowBox[{"Dt", "[", "e", "]"}]}], "+", + RowBox[{"e", " ", + RowBox[{"Dt", "[", "f", "]"}]}]}], + RowBox[{ + SuperscriptBox["b", "2"], "+", + SuperscriptBox["d", "2"], "+", + SuperscriptBox["f", "2"]}]]}], "+", + FractionBox[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"a", " ", "b"}], "+", + RowBox[{"c", " ", "d"}], "+", + RowBox[{"e", " ", "f"}]}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"2", " ", "b", " ", + RowBox[{"Dt", "[", "b", "]"}]}], "+", + RowBox[{"2", " ", "d", " ", + RowBox[{"Dt", "[", "d", "]"}]}], "+", + RowBox[{"2", " ", "f", " ", + RowBox[{"Dt", "[", "f", "]"}]}]}], ")"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox["b", "2"], "+", + SuperscriptBox["d", "2"], "+", + SuperscriptBox["f", "2"]}], ")"}], "2"]]}]], "Output", + CellChangeTimes->{{3.9132277467733803`*^9, 3.913227764863882*^9}, + 3.913228543420228*^9}, + CellLabel-> + "Out[135]=",ExpressionUUID->"5cabe096-5a8d-4cd7-928f-ee06f984a289"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Dt", "[", + RowBox[{ + RowBox[{"b", "^", "2"}], "+", + RowBox[{"d", "^", "2"}], "+", + RowBox[{"f", "^", "2"}]}], "]"}]], "Input", + CellChangeTimes->{{3.913228215366679*^9, 3.913228226807276*^9}}, + CellLabel-> + "In[126]:=",ExpressionUUID->"d34a572d-ae39-484e-b049-c66fdb6b6543"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"2", " ", "b", " ", + RowBox[{"Dt", "[", "b", "]"}]}], "+", + RowBox[{"2", " ", "d", " ", + RowBox[{"Dt", "[", "d", "]"}]}], "+", + RowBox[{"2", " ", "f", " ", + RowBox[{"Dt", "[", "f", "]"}]}]}]], "Output", + CellChangeTimes->{3.913228227705768*^9}, + CellLabel-> + "Out[126]=",ExpressionUUID->"01742196-7b48-491e-9e18-2760c683b42c"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"Dt", "[", + RowBox[{ + RowBox[{"-", "numer"}], "/", "denom"}], "]"}], "==", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"Dt", "[", "numer", "]"}], "/", "numer"}], "-", + RowBox[{ + RowBox[{"Dt", "[", "denom", "]"}], "/", "denom"}]}], ")"}], "*", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "numer"}], "/", "denom"}], ")"}]}]}], "//", + "Simplify"}]], "Input", + CellChangeTimes->{{3.913228302114737*^9, 3.913228356091806*^9}}, + CellLabel-> + "In[132]:=",ExpressionUUID->"e87b61fb-acdb-4862-81cb-2b63088bbf42"], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{{3.913228307168482*^9, 3.913228356982923*^9}}, + CellLabel-> + "Out[132]=",ExpressionUUID->"414397b5-d6fd-4250-8748-22ef1130117c"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"Dt", "[", + RowBox[{"Sqrt", "[", "x", "]"}], "]"}], "==", + RowBox[{ + FractionBox["1", "2"], + RowBox[{ + RowBox[{"(", + RowBox[{"Dt", "[", "x", "]"}], ")"}], "/", + RowBox[{"Sqrt", "[", "x", "]"}]}]}]}], "//", "Simplify"}]], "Input", + CellChangeTimes->{{3.9132284647444963`*^9, 3.9132284918411837`*^9}, { + 3.913228550497073*^9, 3.913228619565284*^9}, {3.9132298760686493`*^9, + 3.913229881783885*^9}}, + CellLabel-> + "In[149]:=",ExpressionUUID->"05396c56-5374-4a25-9bf9-d6150f32d785"], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{{3.9132284741185617`*^9, 3.913228483409042*^9}, + 3.913228548029253*^9, {3.913228584097238*^9, 3.913228620008762*^9}, + 3.9132298823992*^9}, + CellLabel-> + "Out[149]=",ExpressionUUID->"d2ded272-c43f-495c-b25c-ead9403fb556"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Dt", "[", + RowBox[{"x", "^", "2"}], "]"}]], "Input", + CellChangeTimes->{{3.913229793712883*^9, 3.913229806160967*^9}}, + CellLabel-> + "In[148]:=",ExpressionUUID->"1d4e1e52-2b5e-432c-a336-f69735a00557"], + +Cell[BoxData[ + RowBox[{"2", " ", "x", " ", + RowBox[{"Dt", "[", "x", "]"}]}]], "Output", + CellChangeTimes->{{3.913229799170886*^9, 3.913229806902195*^9}}, + CellLabel-> + "Out[148]=",ExpressionUUID->"59eb82a0-20b0-4c1c-a4f3-275072d3f154"] +}, Open ]] +}, +WindowSize->{706.5, 789}, +WindowMargins->{{Automatic, 47.25}, {117, Automatic}}, +FrontEndVersion->"13.3 for Linux x86 (64-bit) (June 3, 2023)", +StyleDefinitions->"Default.nb", +ExpressionUUID->"2a0d355d-5806-41d3-bcd6-5e3a1a8b98c8" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[558, 20, 1640, 45, 84, "Input",ExpressionUUID->"15a82781-faca-4873-867c-b12778607d19"], +Cell[2201, 67, 409, 11, 22, "Input",ExpressionUUID->"a78421be-a2d3-45fa-8414-57e42696f81a"], +Cell[CellGroupData[{ +Cell[2635, 82, 4231, 101, 339, "Input",ExpressionUUID->"fd026e70-4d35-4ad7-a145-1a4801620899"], +Cell[6869, 185, 2423, 68, 59, "Output",ExpressionUUID->"24b2837f-15fe-4b92-ac5b-e4a72f031d79"] +}, Open ]], +Cell[CellGroupData[{ +Cell[9329, 258, 1209, 21, 22, "Input",ExpressionUUID->"91c19974-0016-417d-b987-15ae70ae3757"], +Cell[10541, 281, 789, 17, 25, "Output",ExpressionUUID->"e31571ed-86f9-4ed5-9477-fe9497375e1d"] +}, Open ]], +Cell[CellGroupData[{ +Cell[11367, 303, 589, 10, 22, "Input",ExpressionUUID->"30db8513-478d-4058-aff5-06d32132e49b"], +Cell[11959, 315, 681, 14, 25, "Output",ExpressionUUID->"2e3ab301-bc72-487d-8180-d508a7f12000"] +}, Open ]], +Cell[12655, 332, 461, 9, 22, "Input",ExpressionUUID->"1302dd20-c99e-4603-9cce-69153d82f334"], +Cell[CellGroupData[{ +Cell[13141, 345, 745, 21, 24, "Input",ExpressionUUID->"13dffd7a-3dd0-48a6-ae84-82da73ef4b18"], +Cell[13889, 368, 156, 2, 25, "Output",ExpressionUUID->"21f9d8fd-1e48-4946-b4ae-71631c4c1d37"] +}, Open ]], +Cell[CellGroupData[{ +Cell[14082, 375, 1614, 49, 56, "Input",ExpressionUUID->"49dd6087-ad9d-4ba6-b259-e1711c187c98"], +Cell[15699, 426, 657, 18, 37, "Output",ExpressionUUID->"5fef6f26-ff9c-430d-b550-9c0b6550b6bf"], +Cell[16359, 446, 663, 17, 54, "Output",ExpressionUUID->"82f5cb10-5e34-45a6-89f6-2e0defb99d7f"] +}, Open ]], +Cell[CellGroupData[{ +Cell[17059, 468, 312, 7, 22, "Input",ExpressionUUID->"bae8a795-084f-4b73-b44a-5a1ee7a96688"], +Cell[17374, 477, 9118, 264, 352, "Output",ExpressionUUID->"4ae6700a-7dc7-429d-98ac-a49e3e817967"] +}, Open ]], +Cell[CellGroupData[{ +Cell[26529, 746, 230, 5, 22, "Input",ExpressionUUID->"91070c74-0f8c-4aa6-af8f-7d3b4e0348a0"], +Cell[26762, 753, 1433, 45, 58, "Output",ExpressionUUID->"5cabe096-5a8d-4cd7-928f-ee06f984a289"] +}, Open ]], +Cell[CellGroupData[{ +Cell[28232, 803, 309, 8, 22, "Input",ExpressionUUID->"d34a572d-ae39-484e-b049-c66fdb6b6543"], +Cell[28544, 813, 374, 10, 35, "Output",ExpressionUUID->"01742196-7b48-491e-9e18-2760c683b42c"] +}, Open ]], +Cell[CellGroupData[{ +Cell[28955, 828, 611, 19, 22, "Input",ExpressionUUID->"e87b61fb-acdb-4862-81cb-2b63088bbf42"], +Cell[29569, 849, 180, 3, 35, "Output",ExpressionUUID->"414397b5-d6fd-4250-8748-22ef1130117c"] +}, Open ]], +Cell[CellGroupData[{ +Cell[29786, 857, 557, 15, 35, "Input",ExpressionUUID->"05396c56-5374-4a25-9bf9-d6150f32d785"], +Cell[30346, 874, 278, 5, 60, "Output",ExpressionUUID->"d2ded272-c43f-495c-b25c-ead9403fb556"] +}, Open ]], +Cell[CellGroupData[{ +Cell[30661, 884, 227, 5, 22, "Input",ExpressionUUID->"1d4e1e52-2b5e-432c-a336-f69735a00557"], +Cell[30891, 891, 238, 5, 35, "Output",ExpressionUUID->"59eb82a0-20b0-4c1c-a4f3-275072d3f154"] +}, Open ]] +} +] +*) + diff --git a/2023/day24b.nb b/2023/day24b.nb new file mode 100644 index 0000000..3793772 --- /dev/null +++ b/2023/day24b.nb @@ -0,0 +1,1639 @@ +(* Content-type: application/vnd.wolfram.mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='Mathematica 13.3' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 158, 7] +NotebookDataLength[ 69170, 1631] +NotebookOptionsPosition[ 66778, 1581] +NotebookOutlinePosition[ 67181, 1597] +CellTagsIndexPosition[ 67138, 1594] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell[BoxData[ + RowBox[{"\[CurlyEpsilon]", "=", + RowBox[{"LeviCivitaTensor", "[", "3", "]"}]}]], "Input", + CellChangeTimes->{{3.91511734227525*^9, 3.9151174109489527`*^9}}, + CellLabel->"In[1]:=",ExpressionUUID->"03f87126-b5d8-4089-b938-c38b96d229ea"], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{ + TagBox["SparseArray", + "SummaryHead"], "[", + DynamicModuleBox[{Typeset`open$$ = False, Typeset`embedState$$ = "Ready"}, + + TemplateBox[{ + PaneSelectorBox[{False -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxOpener"]], + ButtonFunction :> (Typeset`open$$ = True), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[ + SparseArray[ + Automatic, {10, 10}, 0.93, { + 1, {{0, 1, 1, 4, 4, 5, 6, 6, 8, 10, 13}, {{4}, {6}, {7}, { + 10}, {5}, {9}, {3}, {8}, {5}, {7}, {2}, {3}, {7}}}, {0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}}], {{0, 0}, {10, + 10}}, {0, 1}], Frame -> False, Axes -> False, AspectRatio -> 1, + ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], Frame -> True, FrameTicks -> None, + FrameStyle -> Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameLabel -> {None, None}, + FrameTicks -> {{None, None}, {None, None}}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["6", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"3", ",", "3", ",", "3"}], "}"}], + "SummaryItem"]}]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}], True -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxCloser"]], + ButtonFunction :> (Typeset`open$$ = False), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[ + SparseArray[ + Automatic, {10, 10}, 0.93, { + 1, {{0, 1, 1, 4, 4, 5, 6, 6, 8, 10, 13}, {{4}, {6}, {7}, { + 10}, {5}, {9}, {3}, {8}, {5}, {7}, {2}, {3}, {7}}}, {0., 0., + 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}}], {{0, 0}, {10, + 10}}, {0, 1}], Frame -> False, Axes -> False, AspectRatio -> 1, + ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], Frame -> True, FrameTicks -> None, + FrameStyle -> Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameLabel -> {None, None}, + FrameTicks -> {{None, None}, {None, None}}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["6", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"3", ",", "3", ",", "3"}], "}"}], + "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Default: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Density: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0.2222222222222222`", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Elements:\"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["\"\"", "SummaryItem"]}]}, { + TagBox[ + TagBox[ + GridBox[{{ + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "2", ",", "3"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + "1", ContentPadding -> False, FrameMargins -> 0, + StripOnInput -> True, BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "3", ",", "2"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"-", "1"}], ContentPadding -> False, FrameMargins -> + 0, StripOnInput -> True, BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"2", ",", "1", ",", "3"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"-", "1"}], ContentPadding -> False, FrameMargins -> + 0, StripOnInput -> True, BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"2", ",", "3", ",", "1"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + "1", ContentPadding -> False, FrameMargins -> 0, + StripOnInput -> True, BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + ItemBox[ + "\"\[VerticalEllipsis]\"", Alignment -> Center, + StripOnInput -> False]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}}, + DefaultBaseStyle -> "Column", + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], + "Column"], "SummaryItem"]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}]}, + Dynamic[Typeset`open$$], ImageSize -> Automatic]}, + "SummaryPanel"], + DynamicModuleValues:>{}], "]"}], + SparseArray[ + Automatic, {3, 3, 3}, 0, { + 1, {{0, 2, 4, 6}, {{2, 3}, {3, 2}, {1, 3}, {3, 1}, {1, 2}, {2, 1}}}, { + 1, -1, -1, 1, 1, -1}}], + Editable->False, + SelectWithContents->True, + Selectable->False]], "Output", + CellChangeTimes->{3.915117411702565*^9, 3.915638307252543*^9}, + CellLabel->"Out[1]=",ExpressionUUID->"6be7c123-ca55-402d-ac1c-d8a1a3dd6091"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"p", "=", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"pm1", ",", "pm2", ",", "pm3"}], "}"}], ",", + RowBox[{"{", + RowBox[{"pn1", ",", "pn2", ",", "pn3"}], "}"}], ",", + RowBox[{"{", + RowBox[{"p31", ",", "p32", ",", "p33"}], "}"}]}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"v", "=", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"vm1", ",", "vm2", ",", "vm3"}], "}"}], ",", + RowBox[{"{", + RowBox[{"vn1", ",", "vn2", ",", "vn3"}], "}"}], ",", + RowBox[{"{", + RowBox[{"v31", ",", "v32", ",", "v33"}], "}"}]}], "}"}]}], + ";"}], "\n", + RowBox[{ + RowBox[{"pr", "=", + RowBox[{"{", + RowBox[{"pr1", ",", "pr2", ",", "pr3"}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"vr", "=", + RowBox[{"{", + RowBox[{"vr1", ",", "vr2", ",", "vr3"}], "}"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{"eqns", "=", + RowBox[{"Flatten", "[", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"Module", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{"m", "=", + RowBox[{"idx", "[", + RowBox[{"[", "1", "]"}], "]"}]}], ",", + RowBox[{"n", "=", + RowBox[{"idx", "[", + RowBox[{"[", "2", "]"}], "]"}]}]}], "}"}], ",", + RowBox[{"Table", "[", + RowBox[{ + RowBox[{"Sum", "[", "\[IndentingNewLine]", + RowBox[{ + RowBox[{ + RowBox[{"\[CurlyEpsilon]", "[", + RowBox[{"[", + RowBox[{"j", ",", "k", ",", "l"}], "]"}], "]"}], + RowBox[{"(", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"p", "[", + RowBox[{"[", + RowBox[{"m", ",", "k"}], "]"}], "]"}], + RowBox[{"v", "[", + RowBox[{"[", + RowBox[{"m", ",", "l"}], "]"}], "]"}]}], "-", + RowBox[{ + RowBox[{"p", "[", + RowBox[{"[", + RowBox[{"n", ",", "k"}], "]"}], "]"}], + RowBox[{"v", "[", + RowBox[{"[", + RowBox[{"n", ",", "l"}], "]"}], "]"}]}]}], ")"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"p", "[", + RowBox[{"[", + RowBox[{"m", ",", "k"}], "]"}], "]"}], "-", + RowBox[{"p", "[", + RowBox[{"[", + RowBox[{"n", ",", "k"}], "]"}], "]"}]}], ")"}], + RowBox[{"vr", "[", + RowBox[{"[", "l", "]"}], "]"}]}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"v", "[", + RowBox[{"[", + RowBox[{"m", ",", "l"}], "]"}], "]"}], "-", + RowBox[{"v", "[", + RowBox[{"[", + RowBox[{"n", ",", "l"}], "]"}], "]"}]}], ")"}], + RowBox[{"pr", "[", + RowBox[{"[", "k", "]"}], "]"}]}]}], ")"}]}], ",", + "\[IndentingNewLine]", + RowBox[{"{", + RowBox[{"k", ",", "3"}], "}"}], ",", + RowBox[{"{", + RowBox[{"l", ",", "3"}], "}"}]}], "]"}], ",", + RowBox[{"{", + RowBox[{"j", ",", "3"}], "}"}]}], "]"}]}], "]"}], ",", + RowBox[{"{", + RowBox[{"idx", ",", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}], ",", + RowBox[{"{", + RowBox[{"1", ",", "3"}], "}"}]}], "}"}]}], "}"}]}], "]"}], + "]"}]}]}], "Input", + CellChangeTimes->{{3.9151174621572657`*^9, 3.915117836380859*^9}, { + 3.915118553005499*^9, 3.91511857446698*^9}, {3.915118608547143*^9, + 3.915118654115213*^9}, {3.9151226052477493`*^9, 3.915122626498413*^9}}, + CellLabel->"In[2]:=",ExpressionUUID->"ac1873dc-737e-41c9-b118-660858f86e16"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"-", "pm3"}], " ", "vm2"}], "+", + RowBox[{"pm2", " ", "vm3"}], "+", + RowBox[{"pr3", " ", + RowBox[{"(", + RowBox[{"vm2", "-", "vn2"}], ")"}]}], "+", + RowBox[{"pn3", " ", "vn2"}], "-", + RowBox[{"pr2", " ", + RowBox[{"(", + RowBox[{"vm3", "-", "vn3"}], ")"}]}], "-", + RowBox[{"pn2", " ", "vn3"}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"pm3", "-", "pn3"}], ")"}], " ", "vr2"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"pm2", "-", "pn2"}], ")"}], " ", "vr3"}]}], ",", + RowBox[{ + RowBox[{"pm3", " ", "vm1"}], "-", + RowBox[{"pm1", " ", "vm3"}], "-", + RowBox[{"pr3", " ", + RowBox[{"(", + RowBox[{"vm1", "-", "vn1"}], ")"}]}], "-", + RowBox[{"pn3", " ", "vn1"}], "+", + RowBox[{"pr1", " ", + RowBox[{"(", + RowBox[{"vm3", "-", "vn3"}], ")"}]}], "+", + RowBox[{"pn1", " ", "vn3"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"pm3", "-", "pn3"}], ")"}], " ", "vr1"}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"pm1", "-", "pn1"}], ")"}], " ", "vr3"}]}], ",", + RowBox[{ + RowBox[{ + RowBox[{"-", "pm2"}], " ", "vm1"}], "+", + RowBox[{"pm1", " ", "vm2"}], "+", + RowBox[{"pr2", " ", + RowBox[{"(", + RowBox[{"vm1", "-", "vn1"}], ")"}]}], "+", + RowBox[{"pn2", " ", "vn1"}], "-", + RowBox[{"pr1", " ", + RowBox[{"(", + RowBox[{"vm2", "-", "vn2"}], ")"}]}], "-", + RowBox[{"pn1", " ", "vn2"}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"pm2", "-", "pn2"}], ")"}], " ", "vr1"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"pm1", "-", "pn1"}], ")"}], " ", "vr2"}]}], ",", + RowBox[{ + RowBox[{"p33", " ", "v32"}], "-", + RowBox[{"p32", " ", "v33"}], "-", + RowBox[{"pm3", " ", "vm2"}], "+", + RowBox[{"pr3", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v32"}], "+", "vm2"}], ")"}]}], "+", + RowBox[{"pm2", " ", "vm3"}], "-", + RowBox[{"pr2", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v33"}], "+", "vm3"}], ")"}]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p33"}], "+", "pm3"}], ")"}], " ", "vr2"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p32"}], "+", "pm2"}], ")"}], " ", "vr3"}]}], ",", + RowBox[{ + RowBox[{ + RowBox[{"-", "p33"}], " ", "v31"}], "+", + RowBox[{"p31", " ", "v33"}], "+", + RowBox[{"pm3", " ", "vm1"}], "-", + RowBox[{"pr3", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v31"}], "+", "vm1"}], ")"}]}], "-", + RowBox[{"pm1", " ", "vm3"}], "+", + RowBox[{"pr1", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v33"}], "+", "vm3"}], ")"}]}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p33"}], "+", "pm3"}], ")"}], " ", "vr1"}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p31"}], "+", "pm1"}], ")"}], " ", "vr3"}]}], ",", + RowBox[{ + RowBox[{"p32", " ", "v31"}], "-", + RowBox[{"p31", " ", "v32"}], "-", + RowBox[{"pm2", " ", "vm1"}], "+", + RowBox[{"pr2", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v31"}], "+", "vm1"}], ")"}]}], "+", + RowBox[{"pm1", " ", "vm2"}], "-", + RowBox[{"pr1", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "v32"}], "+", "vm2"}], ")"}]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p32"}], "+", "pm2"}], ")"}], " ", "vr1"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "p31"}], "+", "pm1"}], ")"}], " ", "vr2"}]}]}], + "}"}]], "Output", + CellChangeTimes->{{3.915117823096376*^9, 3.915117838556246*^9}, + 3.9151186557424507`*^9, 3.915122629230597*^9, 3.915638309331313*^9}, + CellLabel->"Out[6]=",ExpressionUUID->"f499d4c9-b4d7-4b15-a15a-af6bf91c5d4b"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"eqns", "[", + RowBox[{"[", "1", "]"}], "]"}], "==", + RowBox[{ + RowBox[{"pm2", " ", "vm3"}], "-", + RowBox[{"pm3", " ", "vm2"}], "-", + RowBox[{"pn2", " ", "vn3"}], "+", + RowBox[{"pn3", " ", "vn2"}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{"pm2", "-", "pn2"}], ")"}], "vr3"}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"pm3", "-", "pn3"}], ")"}], "vr2"}], "-", + RowBox[{"pr2", + RowBox[{"(", + RowBox[{"vm3", "-", "vn3"}], ")"}]}], "+", + RowBox[{"pr3", + RowBox[{"(", + RowBox[{"vm2", "-", "vn2"}], ")"}]}]}]}]], "Input", + CellChangeTimes->{{3.9151178400600023`*^9, 3.9151179509525537`*^9}, { + 3.9151186603054*^9, 3.915118661144924*^9}, {3.915122634188809*^9, + 3.9151226550803223`*^9}}, + CellLabel->"In[7]:=",ExpressionUUID->"37492689-a26f-429f-8a4e-73540fcd3c63"], + +Cell[BoxData["True"], "Output", + CellChangeTimes->{3.915117953229287*^9, 3.9151186622289877`*^9, + 3.915122655881159*^9, 3.915638310475409*^9}, + CellLabel->"Out[7]=",ExpressionUUID->"d04fc64b-447b-4c19-8032-6dc8b6b0a6bd"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"coeffs", "=", + RowBox[{"CoefficientArrays", "[", + RowBox[{"eqns", ",", + RowBox[{"Flatten", "[", + RowBox[{"{", + RowBox[{"pr", ",", "vr"}], "}"}], "]"}]}], "]"}]}], + ";"}], "\[IndentingNewLine]", + RowBox[{"b", "=", + RowBox[{"-", + RowBox[{"coeffs", "[", + RowBox[{"[", "1", "]"}], "]"}]}]}], "\[IndentingNewLine]", + RowBox[{"A", "=", + RowBox[{"coeffs", "[", + RowBox[{"[", "2", "]"}], "]"}]}]}], "Input", + CellChangeTimes->{{3.9151180794188766`*^9, 3.9151180846936827`*^9}, { + 3.915118170443459*^9, 3.91511826547995*^9}, {3.915118296427291*^9, + 3.915118309224049*^9}, {3.915118362321619*^9, 3.9151183932776747`*^9}, { + 3.915118455304134*^9, 3.915118487067453*^9}, {3.915118666081003*^9, + 3.915118666935705*^9}, {3.9151227075835953`*^9, 3.9151227133990583`*^9}, { + 3.915122759276565*^9, 3.9151227898210087`*^9}, 3.915123124427953*^9}, + CellLabel->"In[8]:=",ExpressionUUID->"f0df0e70-2406-4622-8c2f-624978f182a5"], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{ + TagBox["SparseArray", + "SummaryHead"], "[", + DynamicModuleBox[{Typeset`open$$ = False, Typeset`embedState$$ = "Ready"}, + + TemplateBox[{ + PaneSelectorBox[{False -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxOpener"]], + ButtonFunction :> (Typeset`open$$ = True), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + + RasterBox[{{{0.5, 0., 0.}, {0.5, 0., 0.}, {0.5, 0., 0.}, {0.5, + 0., 0.}, {0.5, 0., 0.}, {0.5, 0., 0.}}}, {{0, 0}, {6, 1}}, {0, + 1}], AspectRatio -> 1, Axes -> False, Frame -> False, + FrameLabel -> {None, None}, FrameStyle -> Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["6", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", "6", "}"}], "SummaryItem"]}]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}], True -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxCloser"]], + ButtonFunction :> (Typeset`open$$ = False), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + + RasterBox[{{{0.5, 0., 0.}, {0.5, 0., 0.}, {0.5, 0., 0.}, {0.5, + 0., 0.}, {0.5, 0., 0.}, {0.5, 0., 0.}}}, {{0, 0}, {6, 1}}, {0, + 1}], AspectRatio -> 1, Axes -> False, Frame -> False, + FrameLabel -> {None, None}, FrameStyle -> Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["6", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", "6", "}"}], "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Default: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Density: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["1.`", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Elements:\"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["\"\"", "SummaryItem"]}]}, { + TagBox[ + TagBox[ + GridBox[{{ + RowBox[{ + RowBox[{"{", "1", "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"pm3", " ", "vm2"}], "-", + RowBox[{"pm2", " ", "vm3"}], "-", + RowBox[{"pn3", " ", "vn2"}], "+", + RowBox[{"pn2", " ", "vn3"}]}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", "2", "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{ + RowBox[{"-", "pm3"}], " ", "vm1"}], "+", + RowBox[{"pm1", " ", "vm3"}], "+", + RowBox[{"pn3", " ", "vn1"}], "-", + RowBox[{"pn1", " ", "vn3"}]}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", "3", "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"pm2", " ", "vm1"}], "-", + RowBox[{"pm1", " ", "vm2"}], "-", + RowBox[{"pn2", " ", "vn1"}], "+", + RowBox[{"pn1", " ", "vn2"}]}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", "4", "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{ + RowBox[{"-", "p33"}], " ", "v32"}], "+", + RowBox[{"p32", " ", "v33"}], "+", + RowBox[{"pm3", " ", "vm2"}], "-", + RowBox[{"pm2", " ", "vm3"}]}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + ItemBox[ + "\"\[VerticalEllipsis]\"", Alignment -> Center, + StripOnInput -> False]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}}, + DefaultBaseStyle -> "Column", + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], + "Column"], "SummaryItem"]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}]}, + Dynamic[Typeset`open$$], ImageSize -> Automatic]}, + "SummaryPanel"], + DynamicModuleValues:>{}], "]"}], + SparseArray[ + Automatic, {6}, 0, { + 1, {{0, 6}, {{1}, {2}, {3}, {4}, {5}, { + 6}}}, {$CellContext`pm3 $CellContext`vm2 - $CellContext`pm2 \ +$CellContext`vm3 - $CellContext`pn3 $CellContext`vn2 + $CellContext`pn2 \ +$CellContext`vn3, -$CellContext`pm3 $CellContext`vm1 + $CellContext`pm1 \ +$CellContext`vm3 + $CellContext`pn3 $CellContext`vn1 - $CellContext`pn1 \ +$CellContext`vn3, $CellContext`pm2 $CellContext`vm1 - $CellContext`pm1 \ +$CellContext`vm2 - $CellContext`pn2 $CellContext`vn1 + $CellContext`pn1 \ +$CellContext`vn2, -$CellContext`p33 $CellContext`v32 + $CellContext`p32 \ +$CellContext`v33 + $CellContext`pm3 $CellContext`vm2 - $CellContext`pm2 \ +$CellContext`vm3, $CellContext`p33 $CellContext`v31 - $CellContext`p31 \ +$CellContext`v33 - $CellContext`pm3 $CellContext`vm1 + $CellContext`pm1 \ +$CellContext`vm3, -$CellContext`p32 $CellContext`v31 + $CellContext`p31 \ +$CellContext`v32 + $CellContext`pm2 $CellContext`vm1 - $CellContext`pm1 \ +$CellContext`vm2}}], + Editable->False, + SelectWithContents->True, + Selectable->False]], "Output", + CellChangeTimes->{{3.915122777740242*^9, 3.9151227902701683`*^9}, + 3.915123125120616*^9, 3.915638311622476*^9}, + CellLabel->"Out[9]=",ExpressionUUID->"143301dc-11ac-4641-81c4-dd32a702d2f7"], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{ + TagBox["SparseArray", + "SummaryHead"], "[", + DynamicModuleBox[{Typeset`open$$ = False, Typeset`embedState$$ = "Ready"}, + + TemplateBox[{ + PaneSelectorBox[{False -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxOpener"]], + ButtonFunction :> (Typeset`open$$ = True), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[CompressedData[" +1:eJxTTMoPSmVmYGBgg2IQGwIe2DNgBZjiVuW742YpnbOfY7xoi/mPK/YvFik+ +Dlz1yp7W5ow0e6klPtLCbbDFFwCPiLS0 + "], {{0, 0}, {6, 6}}, {0, 1}], AspectRatio -> 1, Axes -> False, + Frame -> False, FrameLabel -> {None, None}, FrameStyle -> + Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["24", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"6", ",", "6"}], "}"}], "SummaryItem"]}]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}], True -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxCloser"]], + ButtonFunction :> (Typeset`open$$ = False), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[CompressedData[" +1:eJxTTMoPSmVmYGBgg2IQGwIe2DNgBZjiVuW742YpnbOfY7xoi/mPK/YvFik+ +Dlz1yp7W5ow0e6klPtLCbbDFFwCPiLS0 + "], {{0, 0}, {6, 6}}, {0, 1}], AspectRatio -> 1, Axes -> False, + Frame -> False, FrameLabel -> {None, None}, FrameStyle -> + Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["24", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"6", ",", "6"}], "}"}], "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Default: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Density: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0.6666666666666666`", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Elements:\"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["\"\"", "SummaryItem"]}]}, { + TagBox[ + TagBox[ + GridBox[{{ + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "3"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"vm2", "-", "vn2"}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"-", "vm3"}], "+", "vn3"}], ContentPadding -> + False, FrameMargins -> 0, StripOnInput -> True, + BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "5"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"pm3", "-", "pn3"}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "6"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"-", "pm2"}], "+", "pn2"}], ContentPadding -> + False, FrameMargins -> 0, StripOnInput -> True, + BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + ItemBox[ + "\"\[VerticalEllipsis]\"", Alignment -> Center, + StripOnInput -> False]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}}, + DefaultBaseStyle -> "Column", + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], + "Column"], "SummaryItem"]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}]}, + Dynamic[Typeset`open$$], ImageSize -> Automatic]}, + "SummaryPanel"], + DynamicModuleValues:>{}], "]"}], + SparseArray[ + Automatic, {6, 6}, 0, { + 1, {{0, 4, 8, 12, 16, 20, 24}, {{3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, { + 2}, {1}, {4}, {5}, {3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, {2}, {1}, { + 4}, {5}}}, {$CellContext`vm2 - $CellContext`vn2, -$CellContext`vm3 + \ +$CellContext`vn3, $CellContext`pm3 - $CellContext`pn3, -$CellContext`pm2 + \ +$CellContext`pn2, -$CellContext`vm1 + $CellContext`vn1, $CellContext`vm3 - \ +$CellContext`vn3, -$CellContext`pm3 + $CellContext`pn3, $CellContext`pm1 - \ +$CellContext`pn1, $CellContext`vm1 - $CellContext`vn1, -$CellContext`vm2 + \ +$CellContext`vn2, $CellContext`pm2 - $CellContext`pn2, -$CellContext`pm1 + \ +$CellContext`pn1, -$CellContext`v32 + $CellContext`vm2, $CellContext`v33 - \ +$CellContext`vm3, -$CellContext`p33 + $CellContext`pm3, $CellContext`p32 - \ +$CellContext`pm2, $CellContext`v31 - $CellContext`vm1, -$CellContext`v33 + \ +$CellContext`vm3, $CellContext`p33 - $CellContext`pm3, -$CellContext`p31 + \ +$CellContext`pm1, -$CellContext`v31 + $CellContext`vm1, $CellContext`v32 - \ +$CellContext`vm2, -$CellContext`p32 + $CellContext`pm2, $CellContext`p31 - \ +$CellContext`pm1}}], + Editable->False, + SelectWithContents->True, + Selectable->False]], "Output", + CellChangeTimes->{{3.915122777740242*^9, 3.9151227902701683`*^9}, + 3.915123125120616*^9, 3.9156383116332417`*^9}, + CellLabel->"Out[10]=",ExpressionUUID->"d0620467-d4a9-4321-a914-f53baf2be7d9"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"Normal", "[", "b", "]"}], "//", "InputForm"}], "//", + "TableForm"}]], "Input", + CellChangeTimes->{{3.9151227956372833`*^9, 3.9151228321242847`*^9}, { + 3.915123129139269*^9, 3.915123141110849*^9}}, + CellLabel->"In[11]:=",ExpressionUUID->"57c41424-d6ca-4c6f-87b7-1b5231fdf402"], + +Cell[BoxData[ + TagBox[ + InterpretationBox[ + StyleBox[ + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"pm3", "*", "vm2"}], " ", "-", " ", + RowBox[{"pm2", "*", "vm3"}], " ", "-", " ", + RowBox[{"pn3", "*", "vn2"}], " ", "+", " ", + RowBox[{"pn2", "*", "vn3"}]}], ",", " ", + RowBox[{ + RowBox[{"-", + RowBox[{"(", + RowBox[{"pm3", "*", "vm1"}], ")"}]}], " ", "+", " ", + RowBox[{"pm1", "*", "vm3"}], " ", "+", " ", + RowBox[{"pn3", "*", "vn1"}], " ", "-", " ", + RowBox[{"pn1", "*", "vn3"}]}], ",", " ", + RowBox[{ + RowBox[{"pm2", "*", "vm1"}], " ", "-", " ", + RowBox[{"pm1", "*", "vm2"}], " ", "-", " ", + RowBox[{"pn2", "*", "vn1"}], " ", "+", " ", + RowBox[{"pn1", "*", "vn2"}]}], ",", " ", + RowBox[{ + RowBox[{"-", + RowBox[{"(", + RowBox[{"p33", "*", "v32"}], ")"}]}], " ", "+", " ", + RowBox[{"p32", "*", "v33"}], " ", "+", " ", + RowBox[{"pm3", "*", "vm2"}], " ", "-", " ", + RowBox[{"pm2", "*", "vm3"}]}], ",", " ", + RowBox[{ + RowBox[{"p33", "*", "v31"}], " ", "-", " ", + RowBox[{"p31", "*", "v33"}], " ", "-", " ", + RowBox[{"pm3", "*", "vm1"}], " ", "+", " ", + RowBox[{"pm1", "*", "vm3"}]}], ",", " ", + RowBox[{ + RowBox[{"-", + RowBox[{"(", + RowBox[{"p32", "*", "v31"}], ")"}]}], " ", "+", " ", + RowBox[{"p31", "*", "v32"}], " ", "+", " ", + RowBox[{"pm2", "*", "vm1"}], " ", "-", " ", + RowBox[{"pm1", "*", "vm2"}]}]}], "}"}], + ShowStringCharacters->True, + NumberMarks->True], + InputForm[{$CellContext`pm3 $CellContext`vm2 - $CellContext`pm2 \ +$CellContext`vm3 - $CellContext`pn3 $CellContext`vn2 + $CellContext`pn2 \ +$CellContext`vn3, -$CellContext`pm3 $CellContext`vm1 + $CellContext`pm1 \ +$CellContext`vm3 + $CellContext`pn3 $CellContext`vn1 - $CellContext`pn1 \ +$CellContext`vn3, $CellContext`pm2 $CellContext`vm1 - $CellContext`pm1 \ +$CellContext`vm2 - $CellContext`pn2 $CellContext`vn1 + $CellContext`pn1 \ +$CellContext`vn2, -$CellContext`p33 $CellContext`v32 + $CellContext`p32 \ +$CellContext`v33 + $CellContext`pm3 $CellContext`vm2 - $CellContext`pm2 \ +$CellContext`vm3, $CellContext`p33 $CellContext`v31 - $CellContext`p31 \ +$CellContext`v33 - $CellContext`pm3 $CellContext`vm1 + $CellContext`pm1 \ +$CellContext`vm3, -$CellContext`p32 $CellContext`v31 + $CellContext`p31 \ +$CellContext`v32 + $CellContext`pm2 $CellContext`vm1 - $CellContext`pm1 \ +$CellContext`vm2}], + AutoDelete->True, + Editable->True], + Function[BoxForm`e$, + TableForm[BoxForm`e$]]]], "Output", + CellChangeTimes->{{3.915122798224374*^9, 3.915122832552765*^9}, { + 3.915123127365951*^9, 3.9151231414284477`*^9}, 3.915638312583153*^9}, + CellLabel-> + "Out[11]//TableForm=",ExpressionUUID->"558c25d1-5c0e-400f-8306-\ +01d25b822a70"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"Normal", "[", "A", "]"}]], "Input", + CellChangeTimes->{{3.9151228675720673`*^9, 3.9151228718332376`*^9}}, + CellLabel->"In[12]:=",ExpressionUUID->"7cc09c12-fad9-4a17-a771-4af23d56d99a"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"0", ",", + RowBox[{ + RowBox[{"-", "vm3"}], "+", "vn3"}], ",", + RowBox[{"vm2", "-", "vn2"}], ",", "0", ",", + RowBox[{"pm3", "-", "pn3"}], ",", + RowBox[{ + RowBox[{"-", "pm2"}], "+", "pn2"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"vm3", "-", "vn3"}], ",", "0", ",", + RowBox[{ + RowBox[{"-", "vm1"}], "+", "vn1"}], ",", + RowBox[{ + RowBox[{"-", "pm3"}], "+", "pn3"}], ",", "0", ",", + RowBox[{"pm1", "-", "pn1"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"-", "vm2"}], "+", "vn2"}], ",", + RowBox[{"vm1", "-", "vn1"}], ",", "0", ",", + RowBox[{"pm2", "-", "pn2"}], ",", + RowBox[{ + RowBox[{"-", "pm1"}], "+", "pn1"}], ",", "0"}], "}"}], ",", + RowBox[{"{", + RowBox[{"0", ",", + RowBox[{"v33", "-", "vm3"}], ",", + RowBox[{ + RowBox[{"-", "v32"}], "+", "vm2"}], ",", "0", ",", + RowBox[{ + RowBox[{"-", "p33"}], "+", "pm3"}], ",", + RowBox[{"p32", "-", "pm2"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{ + RowBox[{"-", "v33"}], "+", "vm3"}], ",", "0", ",", + RowBox[{"v31", "-", "vm1"}], ",", + RowBox[{"p33", "-", "pm3"}], ",", "0", ",", + RowBox[{ + RowBox[{"-", "p31"}], "+", "pm1"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"v32", "-", "vm2"}], ",", + RowBox[{ + RowBox[{"-", "v31"}], "+", "vm1"}], ",", "0", ",", + RowBox[{ + RowBox[{"-", "p32"}], "+", "pm2"}], ",", + RowBox[{"p31", "-", "pm1"}], ",", "0"}], "}"}]}], "}"}]], "Output", + CellChangeTimes->{3.915122872323306*^9, 3.9156383174212723`*^9}, + CellLabel->"Out[12]=",ExpressionUUID->"e801a570-f0cd-4b4c-8d9c-519c45a334bd"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MatrixForm", "/@", + RowBox[{"Normal", "[", + RowBox[{"{", + RowBox[{ + RowBox[{"-", "b"}], ",", "A"}], "}"}], "]"}]}]], "Input", + CellChangeTimes->{{3.91511867736012*^9, 3.915118682415257*^9}, { + 3.915118915614111*^9, 3.915118932784973*^9}, {3.915122663144535*^9, + 3.915122663662415*^9}, {3.915638319996628*^9, 3.915638414893429*^9}}, + CellLabel->"In[22]:=",ExpressionUUID->"910915ac-29d4-4614-aef8-e427a8dfbcd2"], + +Cell[BoxData[ + RowBox[{"{", + RowBox[{ + TagBox[ + RowBox[{"(", "\[NoBreak]", + TagBox[GridBox[{ + { + RowBox[{ + RowBox[{ + RowBox[{"-", "pm3"}], " ", "vm2"}], "+", + RowBox[{"pm2", " ", "vm3"}], "+", + RowBox[{"pn3", " ", "vn2"}], "-", + RowBox[{"pn2", " ", "vn3"}]}]}, + { + RowBox[{ + RowBox[{"pm3", " ", "vm1"}], "-", + RowBox[{"pm1", " ", "vm3"}], "-", + RowBox[{"pn3", " ", "vn1"}], "+", + RowBox[{"pn1", " ", "vn3"}]}]}, + { + RowBox[{ + RowBox[{ + RowBox[{"-", "pm2"}], " ", "vm1"}], "+", + RowBox[{"pm1", " ", "vm2"}], "+", + RowBox[{"pn2", " ", "vn1"}], "-", + RowBox[{"pn1", " ", "vn2"}]}]}, + { + RowBox[{ + RowBox[{"p33", " ", "v32"}], "-", + RowBox[{"p32", " ", "v33"}], "-", + RowBox[{"pm3", " ", "vm2"}], "+", + RowBox[{"pm2", " ", "vm3"}]}]}, + { + RowBox[{ + RowBox[{ + RowBox[{"-", "p33"}], " ", "v31"}], "+", + RowBox[{"p31", " ", "v33"}], "+", + RowBox[{"pm3", " ", "vm1"}], "-", + RowBox[{"pm1", " ", "vm3"}]}]}, + { + RowBox[{ + RowBox[{"p32", " ", "v31"}], "-", + RowBox[{"p31", " ", "v32"}], "-", + RowBox[{"pm2", " ", "vm1"}], "+", + RowBox[{"pm1", " ", "vm2"}]}]} + }, + GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.5599999999999999]}, + Offset[0.27999999999999997`]}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}}], + Column], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[BoxForm`e$]]], ",", + TagBox[ + RowBox[{"(", "\[NoBreak]", GridBox[{ + {"0", + RowBox[{ + RowBox[{"-", "vm3"}], "+", "vn3"}], + RowBox[{"vm2", "-", "vn2"}], "0", + RowBox[{"pm3", "-", "pn3"}], + RowBox[{ + RowBox[{"-", "pm2"}], "+", "pn2"}]}, + { + RowBox[{"vm3", "-", "vn3"}], "0", + RowBox[{ + RowBox[{"-", "vm1"}], "+", "vn1"}], + RowBox[{ + RowBox[{"-", "pm3"}], "+", "pn3"}], "0", + RowBox[{"pm1", "-", "pn1"}]}, + { + RowBox[{ + RowBox[{"-", "vm2"}], "+", "vn2"}], + RowBox[{"vm1", "-", "vn1"}], "0", + RowBox[{"pm2", "-", "pn2"}], + RowBox[{ + RowBox[{"-", "pm1"}], "+", "pn1"}], "0"}, + {"0", + RowBox[{"v33", "-", "vm3"}], + RowBox[{ + RowBox[{"-", "v32"}], "+", "vm2"}], "0", + RowBox[{ + RowBox[{"-", "p33"}], "+", "pm3"}], + RowBox[{"p32", "-", "pm2"}]}, + { + RowBox[{ + RowBox[{"-", "v33"}], "+", "vm3"}], "0", + RowBox[{"v31", "-", "vm1"}], + RowBox[{"p33", "-", "pm3"}], "0", + RowBox[{ + RowBox[{"-", "p31"}], "+", "pm1"}]}, + { + RowBox[{"v32", "-", "vm2"}], + RowBox[{ + RowBox[{"-", "v31"}], "+", "vm1"}], "0", + RowBox[{ + RowBox[{"-", "p32"}], "+", "pm2"}], + RowBox[{"p31", "-", "pm1"}], "0"} + }, + GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.7]}, + Offset[0.27999999999999997`]}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}}], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[BoxForm`e$]]]}], "}"}]], "Output", + CellChangeTimes->{{3.915118925164721*^9, 3.91511893321907*^9}, + 3.915122664247056*^9, 3.9156384153712463`*^9}, + CellLabel->"Out[22]=",ExpressionUUID->"09f46a2e-683b-478c-90b2-b29c250c110e"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData["A"], "Input", + CellChangeTimes->{{3.9156384371306543`*^9, 3.915638438323518*^9}}, + NumberMarks->False, + CellLabel->"In[23]:=",ExpressionUUID->"9fe567a3-d977-498b-98b0-140e153d724f"], + +Cell[BoxData[ + InterpretationBox[ + RowBox[{ + TagBox["SparseArray", + "SummaryHead"], "[", + DynamicModuleBox[{Typeset`open$$ = True, Typeset`embedState$$ = "Ready"}, + TemplateBox[{ + PaneSelectorBox[{False -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxOpener"]], + ButtonFunction :> (Typeset`open$$ = True), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[CompressedData[" +1:eJxTTMoPSmVmYGBgg2IQGwIe2DNgBZjiVuW742YpnbOfY7xoi/mPK/YvFik+ +Dlz1yp7W5ow0e6klPtLCbbDFFwCPiLS0 + "], {{0, 0}, {6, 6}}, {0, 1}], AspectRatio -> 1, Axes -> False, + Frame -> False, FrameLabel -> {None, None}, FrameStyle -> + Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["24", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"6", ",", "6"}], "}"}], "SummaryItem"]}]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}], True -> GridBox[{{ + PaneBox[ + ButtonBox[ + DynamicBox[ + FEPrivate`FrontEndResource["FEBitmaps", "SummaryBoxCloser"]], + ButtonFunction :> (Typeset`open$$ = False), Appearance -> None, + BaseStyle -> {}, Evaluator -> Automatic, Method -> + "Preemptive"], Alignment -> {Center, Center}, ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}]], + GraphicsBox[ + RasterBox[CompressedData[" +1:eJxTTMoPSmVmYGBgg2IQGwIe2DNgBZjiVuW742YpnbOfY7xoi/mPK/YvFik+ +Dlz1yp7W5ow0e6klPtLCbbDFFwCPiLS0 + "], {{0, 0}, {6, 6}}, {0, 1}], AspectRatio -> 1, Axes -> False, + Frame -> False, FrameLabel -> {None, None}, FrameStyle -> + Directive[ + Opacity[0.5], + Thickness[Tiny], + RGBColor[0.368417, 0.506779, 0.709798]], + FrameTicks -> {{None, None}, {None, None}}, GridLinesStyle -> + Directive[ + GrayLevel[0.5, 0.4]], ImageSize -> + Dynamic[{ + Automatic, + 3.5 (CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[ + Magnification])}], + Method -> { + "GridLinesInFront" -> True, "AxisPadding" -> Scaled[0.02], + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, + "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, + "DefaultPlotStyle" -> Automatic, "DomainPadding" -> + Scaled[0.02], "RangePadding" -> Scaled[0.05]}], + GridBox[{{ + RowBox[{ + TagBox["\"Specified elements: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["24", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Dimensions: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox[ + RowBox[{"{", + RowBox[{"6", ",", "6"}], "}"}], "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Default: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Density: \"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["0.6666666666666666`", "SummaryItem"]}]}, { + RowBox[{ + TagBox["\"Elements:\"", "SummaryItemAnnotation"], + "\[InvisibleSpace]", + TagBox["\"\"", "SummaryItem"]}]}, { + TagBox[ + TagBox[ + GridBox[{{ + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "3"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"vm2", "-", "vn2"}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "2"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"-", "vm3"}], "+", "vn3"}], ContentPadding -> + False, FrameMargins -> 0, StripOnInput -> True, + BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "5"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{"pm3", "-", "pn3"}], ContentPadding -> False, + FrameMargins -> 0, StripOnInput -> True, BaselinePosition -> + Baseline, ImageSize -> {{1, 300}, Automatic}], + LineBreakWithin -> False]}]}, { + RowBox[{ + RowBox[{"{", + RowBox[{"1", ",", "6"}], "}"}], "\[Rule]", + StyleBox[ + PaneBox[ + RowBox[{ + RowBox[{"-", "pm2"}], "+", "pn2"}], ContentPadding -> + False, FrameMargins -> 0, StripOnInput -> True, + BaselinePosition -> Baseline, + ImageSize -> {{1, 300}, Automatic}], LineBreakWithin -> + False]}]}, { + ItemBox[ + "\"\[VerticalEllipsis]\"", Alignment -> Center, + StripOnInput -> False]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}}, + DefaultBaseStyle -> "Column", + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}], + "Column"], "SummaryItem"]}}, + GridBoxAlignment -> { + "Columns" -> {{Left}}, "Rows" -> {{Automatic}}}, AutoDelete -> + False, GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{2}}, "Rows" -> {{Automatic}}}, + BaseStyle -> { + ShowStringCharacters -> False, NumberMarks -> False, + PrintPrecision -> 3, ShowSyntaxStyles -> False}]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Top}}}, + AutoDelete -> False, + GridBoxItemSize -> { + "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, + BaselinePosition -> {1, 1}]}, + Dynamic[Typeset`open$$], ImageSize -> Automatic]}, + "SummaryPanel"], + DynamicModuleValues:>{}], "]"}], + SparseArray[ + Automatic, {6, 6}, 0, { + 1, {{0, 4, 8, 12, 16, 20, 24}, {{3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, { + 2}, {1}, {4}, {5}, {3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, {2}, {1}, { + 4}, {5}}}, {$CellContext`vm2 - $CellContext`vn2, -$CellContext`vm3 + \ +$CellContext`vn3, $CellContext`pm3 - $CellContext`pn3, -$CellContext`pm2 + \ +$CellContext`pn2, -$CellContext`vm1 + $CellContext`vn1, $CellContext`vm3 - \ +$CellContext`vn3, -$CellContext`pm3 + $CellContext`pn3, $CellContext`pm1 - \ +$CellContext`pn1, $CellContext`vm1 - $CellContext`vn1, -$CellContext`vm2 + \ +$CellContext`vn2, $CellContext`pm2 - $CellContext`pn2, -$CellContext`pm1 + \ +$CellContext`pn1, -$CellContext`v32 + $CellContext`vm2, $CellContext`v33 - \ +$CellContext`vm3, -$CellContext`p33 + $CellContext`pm3, $CellContext`p32 - \ +$CellContext`pm2, $CellContext`v31 - $CellContext`vm1, -$CellContext`v33 + \ +$CellContext`vm3, $CellContext`p33 - $CellContext`pm3, -$CellContext`p31 + \ +$CellContext`pm1, -$CellContext`v31 + $CellContext`vm1, $CellContext`v32 - \ +$CellContext`vm2, -$CellContext`p32 + $CellContext`pm2, $CellContext`p31 - \ +$CellContext`pm1}}], + Editable->False, + SelectWithContents->True, + Selectable->False]], "Output", + CellChangeTimes->{3.915118511702025*^9, 3.9156384388404217`*^9}, + CellLabel->"Out[23]=",ExpressionUUID->"34069add-13e3-482c-a9cb-3a9a3bd2f4e3"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{"MatrixForm", "[", "A", "]"}]], "Input", + CellChangeTimes->{3.915638472499878*^9}, + NumberMarks->False, + CellLabel->"In[24]:=",ExpressionUUID->"dd04c395-109a-476d-be32-88009b6da3b7"], + +Cell[BoxData[ + TagBox[ + RowBox[{"(", "\[NoBreak]", GridBox[{ + {"0", + RowBox[{ + RowBox[{"-", "vm3"}], "+", "vn3"}], + RowBox[{"vm2", "-", "vn2"}], "0", + RowBox[{"pm3", "-", "pn3"}], + RowBox[{ + RowBox[{"-", "pm2"}], "+", "pn2"}]}, + { + RowBox[{"vm3", "-", "vn3"}], "0", + RowBox[{ + RowBox[{"-", "vm1"}], "+", "vn1"}], + RowBox[{ + RowBox[{"-", "pm3"}], "+", "pn3"}], "0", + RowBox[{"pm1", "-", "pn1"}]}, + { + RowBox[{ + RowBox[{"-", "vm2"}], "+", "vn2"}], + RowBox[{"vm1", "-", "vn1"}], "0", + RowBox[{"pm2", "-", "pn2"}], + RowBox[{ + RowBox[{"-", "pm1"}], "+", "pn1"}], "0"}, + {"0", + RowBox[{"v33", "-", "vm3"}], + RowBox[{ + RowBox[{"-", "v32"}], "+", "vm2"}], "0", + RowBox[{ + RowBox[{"-", "p33"}], "+", "pm3"}], + RowBox[{"p32", "-", "pm2"}]}, + { + RowBox[{ + RowBox[{"-", "v33"}], "+", "vm3"}], "0", + RowBox[{"v31", "-", "vm1"}], + RowBox[{"p33", "-", "pm3"}], "0", + RowBox[{ + RowBox[{"-", "p31"}], "+", "pm1"}]}, + { + RowBox[{"v32", "-", "vm2"}], + RowBox[{ + RowBox[{"-", "v31"}], "+", "vm1"}], "0", + RowBox[{ + RowBox[{"-", "p32"}], "+", "pm2"}], + RowBox[{"p31", "-", "pm1"}], "0"} + }, + GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}}, + GridBoxSpacings->{"Columns" -> { + Offset[0.27999999999999997`], { + Offset[0.7]}, + Offset[0.27999999999999997`]}, "Rows" -> { + Offset[0.2], { + Offset[0.4]}, + Offset[0.2]}}], "\[NoBreak]", ")"}], + Function[BoxForm`e$, + MatrixForm[ + SparseArray[ + Automatic, {6, 6}, 0, { + 1, {{0, 4, 8, 12, 16, 20, 24}, {{3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, { + 2}, {1}, {4}, {5}, {3}, {2}, {5}, {6}, {3}, {1}, {4}, {6}, {2}, {1}, { + 4}, {5}}}, {$CellContext`vm2 - $CellContext`vn2, -$CellContext`vm3 + \ +$CellContext`vn3, $CellContext`pm3 - $CellContext`pn3, -$CellContext`pm2 + \ +$CellContext`pn2, -$CellContext`vm1 + $CellContext`vn1, $CellContext`vm3 - \ +$CellContext`vn3, -$CellContext`pm3 + $CellContext`pn3, $CellContext`pm1 - \ +$CellContext`pn1, $CellContext`vm1 - $CellContext`vn1, -$CellContext`vm2 + \ +$CellContext`vn2, $CellContext`pm2 - $CellContext`pn2, -$CellContext`pm1 + \ +$CellContext`pn1, -$CellContext`v32 + $CellContext`vm2, $CellContext`v33 - \ +$CellContext`vm3, -$CellContext`p33 + $CellContext`pm3, $CellContext`p32 - \ +$CellContext`pm2, $CellContext`v31 - $CellContext`vm1, -$CellContext`v33 + \ +$CellContext`vm3, $CellContext`p33 - $CellContext`pm3, -$CellContext`p31 + \ +$CellContext`pm1, -$CellContext`v31 + $CellContext`vm1, $CellContext`v32 - \ +$CellContext`vm2, -$CellContext`p32 + $CellContext`pm2, $CellContext`p31 - \ +$CellContext`pm1}}]]]]], "Output", + CellChangeTimes->{3.915118531459881*^9, 3.915638472917214*^9}, + CellLabel-> + "Out[24]//MatrixForm=",ExpressionUUID->"8cea2472-ac4d-4995-9da7-\ +c9d8b633daf2"] +}, Open ]] +}, +WindowSize->{837.75, 683.25}, +WindowMargins->{{405.75, Automatic}, {Automatic, 174.75}}, +FrontEndVersion->"13.3 for Linux x86 (64-bit) (June 3, 2023)", +StyleDefinitions->"Default.nb", +ExpressionUUID->"7b77b48c-53d7-488f-ab46-71e143a8767a" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[580, 22, 251, 4, 22, "Input",ExpressionUUID->"03f87126-b5d8-4089-b938-c38b96d229ea"], +Cell[834, 28, 8941, 189, 53, "Output",ExpressionUUID->"6be7c123-ca55-402d-ac1c-d8a1a3dd6091"] +}, Open ]], +Cell[CellGroupData[{ +Cell[9812, 222, 4029, 114, 119, "Input",ExpressionUUID->"ac1873dc-737e-41c9-b118-660858f86e16"], +Cell[13844, 338, 3887, 123, 105, "Output",ExpressionUUID->"f499d4c9-b4d7-4b15-a15a-af6bf91c5d4b"] +}, Open ]], +Cell[CellGroupData[{ +Cell[17768, 466, 850, 24, 22, "Input",ExpressionUUID->"37492689-a26f-429f-8a4e-73540fcd3c63"], +Cell[18621, 492, 222, 3, 25, "Output",ExpressionUUID->"d04fc64b-447b-4c19-8032-6dc8b6b0a6bd"] +}, Open ]], +Cell[CellGroupData[{ +Cell[18880, 500, 997, 22, 53, "Input",ExpressionUUID->"f0df0e70-2406-4622-8c2f-624978f182a5"], +Cell[19880, 524, 11496, 232, 53, "Output",ExpressionUUID->"143301dc-11ac-4641-81c4-dd32a702d2f7"], +Cell[31379, 758, 11192, 227, 53, "Output",ExpressionUUID->"d0620467-d4a9-4321-a914-f53baf2be7d9"] +}, Open ]], +Cell[CellGroupData[{ +Cell[42608, 990, 325, 7, 22, "Input",ExpressionUUID->"57c41424-d6ca-4c6f-87b7-1b5231fdf402"], +Cell[42936, 999, 2864, 65, 70, "Output",ExpressionUUID->"558c25d1-5c0e-400f-8306-01d25b822a70"] +}, Open ]], +Cell[CellGroupData[{ +Cell[45837, 1069, 208, 3, 22, "Input",ExpressionUUID->"7cc09c12-fad9-4a17-a771-4af23d56d99a"], +Cell[46048, 1074, 1776, 52, 56, "Output",ExpressionUUID->"e801a570-f0cd-4b4c-8d9c-519c45a334bd"] +}, Open ]], +Cell[CellGroupData[{ +Cell[47861, 1131, 450, 9, 22, "Input",ExpressionUUID->"910915ac-29d4-4614-aef8-e427a8dfbcd2"], +Cell[48314, 1142, 3848, 114, 107, "Output",ExpressionUUID->"09f46a2e-683b-478c-90b2-b29c250c110e"] +}, Open ]], +Cell[CellGroupData[{ +Cell[52199, 1261, 195, 3, 22, "Input",ExpressionUUID->"9fe567a3-d977-498b-98b0-140e153d724f"], +Cell[52397, 1266, 11134, 225, 145, "Output",ExpressionUUID->"34069add-13e3-482c-a9cb-3a9a3bd2f4e3"] +}, Open ]], +Cell[CellGroupData[{ +Cell[63568, 1496, 205, 4, 22, "Input",ExpressionUUID->"dd04c395-109a-476d-be32-88009b6da3b7"], +Cell[63776, 1502, 2986, 76, 98, "Output",ExpressionUUID->"8cea2472-ac4d-4995-9da7-c9d8b633daf2"] +}, Open ]] +} +] +*) + diff --git a/2023/src/day24.cpp b/2023/src/day24.cpp index 81416df..2320f5c 100644 --- a/2023/src/day24.cpp +++ b/2023/src/day24.cpp @@ -6,9 +6,14 @@ *****************************************************************************/ #include "day24.hpp" -#include "lib.hpp" // for parse_args, DEBUG -#include // for cout, cerr -#include // for vector +#include "gauss_elim.hpp" // for gauss_elim, solve_upper_triangular, RowPermuter +#include "lib.hpp" // for parse_args, DEBUG +#include "unit_test/pretty_print.hpp" // for repr +#include // for round +#include // for int64_t +#include // for cout, cerr +#include // for vector +// IWYU pragma: no_include // for fill_n constexpr long MIN_X = 200000000000000, MAX_X = 400000000000000; constexpr long MIN_Y = 200000000000000, MAX_Y = 400000000000000; @@ -23,7 +28,7 @@ int part_1(const std::vector &stones) { } const auto &[x, y] = result.value(); if (x >= MIN_X && x <= MAX_X && y >= MIN_Y && y <= MAX_Y) { - if constexpr (aoc::DEBUG) { + if constexpr (aoc::DEBUG && false) { std::cerr << "Hailstone A: " << *it_a << "\n"; std::cerr << "Hailstone B: " << *it_b << "\n"; std::cerr << "Hailstones' paths will cross inside the test " @@ -37,12 +42,53 @@ int part_1(const std::vector &stones) { return count; } +std::int64_t part_2(const std::vector &stones) { + using value_t = long double; + using namespace aoc::math; + + // keep trying different pairs of stones until one succeeds (should only + // take a few tries) + for (std::size_t i = 0; i < stones.size(); ++i) { + for (std::size_t j = i + 1; j < stones.size(); ++j) { + for (std::size_t k = 0; k < stones.size(); ++k) { + for (std::size_t l = j + 1; l < stones.size(); ++l) { + auto [A, b] = aoc::day24::make_system( + stones, {i, j}, {k, l}); + if constexpr (aoc::DEBUG) { + std::cerr << "A:\n" + << pretty_print::repr(A) << "\n" + << "b: " << pretty_print::repr(b) << "\n"; + } + std::optional rp = gauss_elim(A, b); + if constexpr (aoc::DEBUG) { + std::cerr << "after Gaussian elimination:\n" + << "A:\n" + << pretty_print::repr(A) << "\n" + << "b: " << pretty_print::repr(b) << "\n"; + } + if (rp) { + auto x = solve_upper_triangular(A, b, *rp); + if constexpr (aoc::DEBUG) { + std::cerr << "x: " << pretty_print::repr(x) << "\n"; + } + return std::round(x[0]) + + std::round(x[1]) + + std::round(x[2]); + } + } + } + } + } + assert(false); +} + int main(int argc, char **argv) { std::ifstream infile = aoc::parse_args(argc, argv); std::vector stones = aoc::day24::read_stones(infile); std::cout << part_1(stones) << "\n"; + std::cout << part_2(stones) << "\n"; return 0; } diff --git a/2023/src/day24.hpp b/2023/src/day24.hpp index 15dc56e..f6ecf22 100644 --- a/2023/src/day24.hpp +++ b/2023/src/day24.hpp @@ -8,18 +8,23 @@ #ifndef DAY24_HPP_PKLXENFE #define DAY24_HPP_PKLXENFE -#include "lib.hpp" // for expect_input -#include // for copysign -#include // for istream, ostream -#include // for optional -#include // for pair, move, make_pair -#include // for vector +#include "ds/grid.hpp" // for Grid +#include "lib.hpp" // for expect_input +#include // for assert +#include // for copysign +#include // for size_t +#include // for int64_t +#include // for initializer_list +#include // for istream, ostream +#include // for optional +#include // for pair, move, make_pair +#include // for vector namespace aoc::day24 { struct Hailstone { - double px, py, pz; - double vx, vy, vz; + std::int64_t px, py, pz; + std::int64_t vx, vy, vz; }; std::istream &operator>>(std::istream &is, Hailstone &stone) { @@ -59,11 +64,15 @@ find_intersection_xy(const Hailstone &a, const Hailstone &b) { * Simplify@First@Solve[y-#<>"py"==(#<>"vy"/#<>"vx")(x-#<>"px")&/@{"a.","b."},{x,y}], * "\n"] */ - double x = (a.py * a.vx * b.vx - a.px * a.vy * b.vx - a.vx * b.py * b.vx + - a.vx * b.px * b.vy) / + // cast the large position values to doubles, so we don't get integer + // overflow + double apx = a.px, apy = a.py; + double bpx = b.px, bpy = b.py; + double x = (apy * a.vx * b.vx - apx * a.vy * b.vx - a.vx * bpy * b.vx + + a.vx * bpx * b.vy) / (-(a.vy * b.vx) + a.vx * b.vy); - double y = (a.vy * b.py * b.vx - a.py * a.vx * b.vy + a.px * a.vy * b.vy - - a.vy * b.px * b.vy) / + double y = (a.vy * bpy * b.vx - apy * a.vx * b.vy + apx * a.vy * b.vy - + a.vy * bpx * b.vy) / (a.vy * b.vx - a.vx * b.vy); if (std::copysign(1.0, x - a.px) != std::copysign(1.0, a.vx) || @@ -75,6 +84,62 @@ find_intersection_xy(const Hailstone &a, const Hailstone &b) { return std::make_pair(x, y); } +template +std::pair, std::vector> +make_system(const std::vector &stones, + const std::pair &pair_1, + const std::pair &pair_2) { + aoc::ds::Grid A(6, 6, 0); + std::vector b(6, 0); + aoc::ds::Grid identity(6, 6, 0); + const auto p = [&stones](int idx, int coord) { + switch (coord) { + case 0: + return stones[idx].px; + case 1: + return stones[idx].py; + case 2: + return stones[idx].pz; + default: + assert(false); + } + }; + const auto v = [&stones](int idx, int coord) { + switch (coord) { + case 0: + return stones[idx].vx; + case 1: + return stones[idx].vy; + case 2: + return stones[idx].vz; + default: + assert(false); + } + }; + // formula from https://codegolf.stackexchange.com/a/160375 + const auto eps = [](int i, int j, int k) { + return (i - j) * (j - k) * (k - i) / 2; + }; + for (std::size_t i = 0; const auto &[m, n] : {pair_1, pair_2}) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t l = 0; l < 3; ++l) { + T sign = eps(j, k, l); + if (sign == 0) { + continue; + } + b[i * 3 + j] += + sign * (p(m, k) * v(m, l) - p(n, k) * v(n, l)); + A.at(k, i * 3 + j) += sign * (v(m, l) - v(n, l)); + A.at(l + 3, i * 3 + j) += sign * (p(m, k) - p(n, k)); + } + } + } + ++i; + } + return {A, b}; +} + std::vector read_stones(std::istream &is) { std::vector stones; Hailstone stone{}; diff --git a/2023/src/day24.py b/2023/src/day24.py index 870b99e..e269790 100644 --- a/2023/src/day24.py +++ b/2023/src/day24.py @@ -11,10 +11,16 @@ import z3 from scipy.optimize import check_grad, minimize +np.set_printoptions(linewidth=300) + MIN_X, MAX_X = 200000000000000, 400000000000000 MIN_Y, MAX_Y = MIN_X, MAX_X +IArray = npt.NDArray[np.int64] +DEBUG = True + + @dataclass(frozen=True) class Hailstone: px: int @@ -25,13 +31,13 @@ class Hailstone: vz: int @cached_property - def pos(self) -> npt.NDArray[np.int64]: + def pos(self) -> IArray: arr = np.array([self.px, self.py, self.pz], dtype=np.int64) arr.flags.writeable = False return arr @cached_property - def vel(self) -> npt.NDArray[np.int64]: + def vel(self) -> IArray: arr = np.array([self.vx, self.vy, self.vz], dtype=np.int64) arr.flags.writeable = False return arr @@ -99,7 +105,278 @@ def part_1(lines: list[str]) -> int: return count -def make_equations(stones: list[Hailstone]) -> tuple[list[Any], list[Any]]: +FArray = npt.NDArray[np.float64] + + +def part_2(lines: list[str]) -> int: + stones = parse(lines) + sol = part_2_linalg(stones) + # sol = part_2_z3(stones) + # sol = part_2_scipy(stones) + correct_sol = None + if len(lines) == 5: + correct_sol = 47 + elif len(lines) == 300: + correct_sol = 769840447420960 + if correct_sol is not None: + assert sol == correct_sol, f"{sol} != {correct_sol}" + return sol + + +def make_levi_civita() -> IArray: + eps = np.zeros((3, 3, 3), dtype=int) + indices = (0, 1, 2) + for _ in range(3): + eps[indices] = 1 + eps[indices[::-1]] = -1 + indices = tuple(np.roll(indices, 1)) # type: ignore[assignment] + return eps + + +def make_linear_system( + stones: list[Hailstone], index_pairs: tuple[tuple[int, int], tuple[int, int]] +) -> tuple[IArray, IArray]: + """Returns (A, b), suitable for np.linalg.solve(A, b).""" + eps = make_levi_civita() + + assert len(index_pairs) == 2 + assert all(len(set(pair)) == 2 for pair in index_pairs) + assert set(index_pairs[0]) != set(index_pairs[1]) + A = np.zeros((6, 6), dtype=int) + b = np.zeros(6, dtype=int) + p = np.stack([stone.pos for stone in stones]) + v = np.stack([stone.vel for stone in stones]) + for i, (m, n) in enumerate(index_pairs): + for j in range(3): + for k in range(3): + for l in range(3): # noqa: E741 + b[i * 3 + j] += eps[j, k, l] * ( + p[m, k] * v[m, l] - p[n, k] * v[n, l] + ) + A[i * 3 + j, k] += eps[j, k, l] * (v[m, l] - v[n, l]) + A[i * 3 + j, l + 3] += eps[j, k, l] * (p[m, k] - p[n, k]) + return A, b + + +def part_2_linalg(stones: list[Hailstone]) -> int: + index_pairs = ((0, 1), (2, 3)) + A, b = make_linear_system(stones, index_pairs) + # pm1, pm2, pm3 = stones[index_pairs[0][0]].pos + # vm1, vm2, vm3 = stones[index_pairs[0][0]].vel + # pn1, pn2, pn3 = stones[index_pairs[0][1]].pos + # vn1, vn2, vn3 = stones[index_pairs[0][1]].vel + if DEBUG: + print(f"A:\n{A}") + print(f"b: {b}") + # assert -b[0] == pm2 * vm3 - pm3 * vm2 - pn2 * vn3 + pn3 * vn2 + # assert np.array_equal(A[1], [vm3 - vn3, 0, vn1 - vm1, pn3 - pm3, 0, pm1 - pn1]) + # assert -b[1] == pm3 * vm1 - pm1 * vm3 - pn3 * vn1 + pn1 * vn3 + # assert b[1] == pm1 * vm3 - pm3 * vm1 - pn1 * vn3 + pn3 * vn1 + + # assert np.array_equal(A[0], [0, -vm3 + vn3, vm2 - vn2, 0, pm3 - pn3, -pm2 + pn2]) + # assert np.array_equal(A[1], [vm3 - vn3, 0, -vm1 + vn1, -pm3 + pn3, 0, pm1 - pn1]) + # assert np.array_equal(A[2], [-vm2 + vn2, vm1 - vn1, 0, pm2 - pn2, -pm1 + pn1, 0]) + # assert b[0] == pm3 * vm2 - pm2 * vm3 - pn3 * vn2 + pn2 * vn3 + # assert b[1] == -(pm3 * vm1) + pm1 * vm3 + pn3 * vn1 - pn1 * vn3 + # assert b[2] == pm2 * vm1 - pm1 * vm2 - pn2 * vn1 + pn1 * vn2 + A, b = gauss_elim(A.astype(object), b.astype(object)) + if DEBUG: + print("log2(A):") + print( + np.array( + [[math.log2(abs(x)) if x != 0 else math.nan for x in row] for row in A] + ) + ) + print( + "log2(b):", np.array([math.log2(abs(x)) if x != 0 else math.nan for x in b]) + ) + print("after Gaussian elimination:") + print(f"A:\n{A}") + print(f"b: {b}") + try: + x = np.linalg.solve(A, b).round().astype(np.int64) + except (TypeError, OverflowError): + x = solve_upper_triangular(A, b) + if DEBUG: + print(f"x: {x}") + return cast(int, x[:3].sum()) + + +def solve_upper_triangular(A: IArray, b: IArray) -> IArray: + b = b.copy() + x = np.zeros_like(b) + n = x.shape[0] + for i in range(n - 1, -1, -1): + for j in range(i + 1, n): + b[i] -= A[i, j] * x[j] + if b.dtype.kind in "iu" or (b.dtype.kind == "O" and isinstance(b[i], int)): + # b is an integer + print(f"checking {b[i]} % {A[i, i]}...") + assert b[i] % A[i, i] == 0 + x[i] = b[i] // A[i, i] + else: + # b is not an integer + x[i] = b[i] / A[i, i] + return x + + +def partial_pivot_max(A: IArray | FArray, b: IArray | FArray, i: int) -> bool: + """Partial pivot at row i, swapping with the row with maximum absolute + value in that column. + + Return False if no non-zero pivot was found. + """ + pivot = cast(int, i + np.argmax(np.abs(A[i:, i]))) + if A[pivot, i] == 0: + # entire column is zero + print(f"warning: column {i} is all zeros") + return False + # swap rows + if pivot != i: + if DEBUG: + print(f"swapping rows {i} and {pivot}") + A[[pivot, i]] = A[[i, pivot]] + b[[pivot, i]] = b[[i, pivot]] + return True + + +def partial_pivot_first(A: IArray | FArray, b: IArray | FArray, i: int) -> bool: + """Partial pivot at row i, swapping with the first row with a non-zero value. + + Return False if no non-zero pivot was found. + """ + pivot = next((j for j in range(i, A.shape[0]) if A[j, i] != 0), None) + if pivot is None: + # entire column is zero + print(f"warning: column {i} is all zeros") + return False + # swap rows + if pivot != i: + if DEBUG: + print(f"swapping rows {i} and {pivot}") + A[[pivot, i]] = A[[i, pivot]] + b[[pivot, i]] = b[[i, pivot]] + return True + + +# the following functions are based on Turner 1995, "A simplified fraction-free +# integer Gauss elimination algorithm" (https://apps.dtic.mil/sti/citations/ADA313755) + + +def gauss_elim(ai: IArray | FArray, bi: IArray | FArray) -> tuple[FArray, FArray]: + """Algorithm 1 from Turner 1995, plus partial pivoting.""" + a = ai.astype(np.float64) + b = bi.astype(np.float64) + n = a.shape[0] + for i in range(n - 1): + if not partial_pivot_max(a, b, i): + continue + for j in range(i + 1, n): + m = a[j, i] / a[i, i] + a[j, i] = 0 + b[j] -= m * b[i] + a[j, i + 1 :] -= m * a[i, i + 1 :] + return a, b + + +def gauss_elim_gcd(a: IArray, b: IArray) -> tuple[IArray, IArray]: + """Algorithm 5 from Turner 1995, plus partial pivoting.""" + n = a.shape[0] + for i in range(n - 1): + if not partial_pivot_first(a, b, i): + continue + for j in range(i + 1, n): + p = math.gcd(a[i, i], a[j, i]) + alpha = a[i, i] // p + gamma = a[j, i] // p + b[j] = alpha * b[j] - gamma * b[i] + for k in range(i + 1, n): + a[j, k] = alpha * a[j, k] - gamma * a[i, k] + a[j, i] = 0 + return a, b + + +def gauss_elim_ff(a: IArray, b: IArray) -> tuple[IArray, IArray]: + """Algorithm 6 from Turner 1995, plus partial pivoting.""" + n = a.shape[0] + for i in range(n - 1): + if not partial_pivot_first(a, b, i): + continue + for j in range(i + 1, n): + b[j] = a[i, i] * b[j] - a[j, i] * b[i] + for k in range(i + 1, n): + a[j, k] = a[i, i] * a[j, k] - a[j, i] * a[i, k] + a[j, i] = 0 + if i >= 1: # removal of common factors + for j in range(i + 1, n): + b[j] //= a[i - 1, i - 1] + for k in range(i + 1, n): + a[j, k] //= a[i - 1, i - 1] + return a, b + + +def gauss_elim_ff_gcd(a: IArray, b: IArray) -> tuple[IArray, IArray]: + """Algorithm 6 from Turner 1995, plus partial pivoting and full-row GCD reduction.""" + n = a.shape[0] + for i in range(n): + if not partial_pivot_first(a, b, i): + continue + for j in range(i + 1, n): + b[j] = a[i, i] * b[j] - a[j, i] * b[i] + for k in range(i + 1, n): + a[j, k] = a[i, i] * a[j, k] - a[j, i] * a[i, k] + a[j, i] = 0 + if i >= 1: # removal of common factors + for j in range(i + 1, n): + b[j] //= a[i - 1, i - 1] + for k in range(i + 1, n): + a[j, k] //= a[i - 1, i - 1] + p = math.gcd(abs(b[i]), *(abs(x) for x in a[i, i:] if x != 0)) + if p > 1: + a[i] //= p + b[i] //= p + if DEBUG: + print(f"reduced row {i} by a common factor of 2^{math.log2(p)} ({p})") + + return a, b + + +def bareiss_algorithm(A: IArray, b: IArray) -> tuple[IArray, IArray]: + M = np.hstack([A, b[:, None]]) + n = M.shape[0] + + for k in range(n - 1): + # if k > 0 and M[k - 1, k - 1] == 0: + # for i in range(k, n): + # if M[i, k - 1] == 0: + # continue + # # swap rows k-1 and i + # M[[k - 1, i]] = M[[i, k - 1]] + if not partial_pivot_first(M[:, :n], M[:, n], k - 1): + continue + for i in range(k + 1, n): + for j in range(k + 1, n): + numer = M[i, j] * M[k, k] - M[i, k] * M[k, j] + if k > 0: + denom = M[k - 1, k - 1] + else: + denom = 1 + if numer != 0: + assert denom != 0 + assert numer % denom == 0 + M[i, j] = numer // denom + else: + M[i, j] = 0 + + # if len(swaps) % 2 == 1: + # M[:] *= -1 + print(M) + A[:] = M[:, :n] + b[:] = M[:, n] + return A, b + + +def make_equations_z3(stones: list[Hailstone]) -> tuple[list[Any], list[Any]]: equations: list[Any] = [] rock_pos = [z3.Int(f"pr{coord}") for coord in "xyz"] rock_vel = [z3.Int(f"vr{coord}") for coord in "xyz"] @@ -119,7 +396,16 @@ def make_equations(stones: list[Hailstone]) -> tuple[list[Any], list[Any]]: return equations, variables -FArray = npt.NDArray[np.float64] +def part_2_z3(stones: list[Hailstone]) -> int: + equations, variables = make_equations_z3(stones) + + s = z3.Solver() + s.add(*equations) + for t in variables[6:]: + s.add(t >= 0) + s.check() + m = s.model() + return sum(m[var].as_long() for var in variables[:3]) @dataclass(frozen=True) @@ -257,24 +543,6 @@ def closest_approach(pv1: FArray, p2: FArray, v2: FArray) -> tuple[float, FArray return sq_dist.val, sq_dist.eps -def part_2(lines: list[str]) -> int: - stones = parse(lines) - # return part_2_z3(stones) - return part_2_scipy(stones) - - -def part_2_z3(stones: list[Hailstone]) -> int: - equations, variables = make_equations(stones) - - s = z3.Solver() - s.add(*equations) - for t in variables[6:]: - s.add(t >= 0) - s.check() - m = s.model() - return sum(m[var].as_long() for var in variables[:3]) - - def func(x, stones): value = 0.0 jac = np.zeros(6) @@ -295,6 +563,7 @@ def part_2_scipy(stones: list[Hailstone]) -> int: stone_count += 1 x = sol.x.round().astype(np.int64) + print(x) return cast(int, x[:3].sum()) diff --git a/2023/src/gauss_elim.hpp b/2023/src/gauss_elim.hpp new file mode 100644 index 0000000..3979b6e --- /dev/null +++ b/2023/src/gauss_elim.hpp @@ -0,0 +1,260 @@ +/****************************************************************************** + * File: gauss_elim.hpp + * + * Author: Eric T. Johnson (yut23) + * Created: 2024-01-30 + *****************************************************************************/ + +#ifndef GAUSS_ELIM_HPP_SVFEFUHA +#define GAUSS_ELIM_HPP_SVFEFUHA + +#include "ds/grid.hpp" // for Grid +#include "lib.hpp" // for DEBUG +#include "util/util.hpp" // for always_false // IWYU pragma: keep +#include // for assert +#include // for signed_integral, floating_point +#include // for size_t, abs +#include // for ostream, cerr +#include // for gcd +#include // for optional +#include // for swap +#include // for vector +// IWYU pragma: no_include // for fill_n + +namespace aoc::math { +struct RowPermuter { + std::vector row_order; + + explicit RowPermuter(int size) : row_order(size) { + for (std::size_t i = 0; i < row_order.size(); ++i) { + row_order[i] = i; + } + } + + void swap_rows(std::size_t i, std::size_t j) { + if (i != j) { + if constexpr (aoc::DEBUG) { + std::cerr << "swapping rows " << i << " and " << j << "\n"; + } + std::swap(row_order[i], row_order[j]); + } + } + std::size_t size() const { return row_order.size(); } + + template + T &operator()(aoc::ds::Grid &grid, std::size_t i, std::size_t j) const { + return grid[grid.get_index(j, row_order[i])]; + } + template + const T &operator()(const aoc::ds::Grid &grid, std::size_t i, + std::size_t j) const { + return grid[grid.get_index(j, row_order[i])]; + } + template + T &operator()(std::vector &vec, std::size_t i) const { + return vec[row_order[i]]; + } + template + const T &operator()(const std::vector &vec, std::size_t i) const { + return vec[row_order[i]]; + } +}; + +namespace detail { +/** + * Partial pivot at row i, swapping with the row with the maximum absolute value + * in that column. + * + * Returns false if no non-zero pivot was found. + */ +template +bool partial_pivot_max(const aoc::ds::Grid &A, RowPermuter &rp, + std::size_t i) { + std::size_t pivot = i; + T max_value = std::abs(rp(A, i, i)); + for (std::size_t j = i; j < rp.size(); ++j) { + T curr_value = std::abs(rp(A, j, i)); + if (curr_value > max_value) { + max_value = curr_value; + pivot = j; + } + } + if (max_value == 0) { + std::cerr << "warning: column " << i + << " is all zeros below the diagonal\n"; + return false; + } + rp.swap_rows(i, pivot); + return true; +} + +/** + * Partial pivot at row i, swapping with the first row with a non-zero value. + * + * Returns false if no non-zero pivot was found. + */ +template +bool partial_pivot_first(const aoc::ds::Grid &A, RowPermuter &rp, + std::size_t i) { + std::size_t pivot; + for (pivot = i; pivot < rp.size(); ++pivot) { + if (rp(A, pivot, i) != 0) { + break; + } + } + if (pivot == rp.size()) { + std::cerr << "warning: column " << i + << " is all zeros below the diagonal\n"; + return false; + } + rp.swap_rows(i, pivot); + return true; +} + +} // namespace detail + +/** + * Standard Gaussian elimination on floating-point numbers. + */ +template +std::optional gauss_elim_floating_point(aoc::ds::Grid &A, + std::vector &b) { + std::size_t n = A.height; + assert(b.size() == n); + assert(A.width == static_cast(n)); + RowPermuter rp(n); + + for (std::size_t i = 0; i < n - 1; ++i) { + if (!detail::partial_pivot_max(A, rp, i)) { + return {}; + } + for (std::size_t j = i + 1; j < n; ++j) { + T m = rp(A, j, i) / rp(A, i, i); + rp(A, j, i) = 0; + rp(b, j) -= m * rp(b, i); + for (std::size_t k = i + 1; k < n; ++k) { + rp(A, j, k) -= m * rp(A, i, k); + } + } + } + + return rp; +} + +/** + * Fraction-free Gaussian elimination with partial pivoting, following Turner + * 1995, "A simplified fraction-free integer Gauss elimination algorithm" + * (https://apps.dtic.mil/sti/citations/ADA313755) + */ +template +std::optional gauss_elim_fraction_free(aoc::ds::Grid &A, + std::vector &b) { + std::size_t n = A.height; + assert(b.size() == n); + assert(A.width == static_cast(n)); + RowPermuter rp(n); + + for (std::size_t i = 0; i < n; ++i) { + if (!detail::partial_pivot_first(A, rp, i)) { + return {}; + } + const T &Aii = rp(A, i, i); + for (std::size_t j = i + 1; j < n; ++j) { + T &Aji = rp(A, j, i); + rp(b, j) = Aii * rp(b, j) - Aji * rp(b, i); + for (std::size_t k = i + 1; k < n; ++k) { + rp(A, j, k) = Aii * rp(A, j, k) - Aji * rp(A, i, k); + } + Aji = 0; + } + // remove known common factor: previous diagonal + if (i >= 1) { + const T &denom = rp(A, i - 1, i - 1); + for (std::size_t j = i + 1; j < n; ++j) { + rp(b, j) /= denom; + for (std::size_t k = i + 1; k < n; ++k) { + rp(A, j, k) /= denom; + } + } + } + // remove all common factors from row i + T factor = rp(b, i); + for (std::size_t j = i; j < n; ++j) { + if (factor == 1) { + // exit early if there are no common factors + break; + } + factor = std::gcd(factor, rp(A, i, j)); + } + if (factor > 1) { + rp(b, i) /= factor; + for (std::size_t j = 1; j < n; ++j) { + rp(A, i, j) /= factor; + } + if constexpr (aoc::DEBUG) { + std::cerr << "reduced row " << i << " by a common factor of " + << factor << "\n"; + } + } + } + + return rp; +} + +template +std::optional gauss_elim(aoc::ds::Grid &A, std::vector &b) { + if constexpr (std::signed_integral) { + return gauss_elim_fraction_free(A, b); + } else if constexpr (std::floating_point) { + return gauss_elim_floating_point(A, b); + } else { + static_assert(util::always_false, + "data type must be signed integral or floating-point"); + } +} + +template +std::vector solve_upper_triangular(const aoc::ds::Grid &A, + std::vector &b, + const RowPermuter &rp) { + std::size_t n = rp.size(); + assert(A.height == static_cast(n)); + assert(A.width == static_cast(n)); + assert(b.size() == n); + std::vector x(n, 0); + for (std::size_t i = n; i-- > 0;) { + for (std::size_t j = i + 1; j < n; ++j) { + rp(b, i) -= rp(A, i, j) * x[j]; + } + if constexpr (std::signed_integral) { + assert(rp(b, i) % rp(A, i, i) == 0); + } + x[i] = rp(b, i) / rp(A, i, i); + } + return x; +} + +// instantiate templates in an anonymous namespace, so static analyzers will +// check these functions +namespace { +template +void _lint_helper_template() { + aoc::ds::Grid A(5, 5); + std::vector b(5); + auto rp = gauss_elim(A, b); + if (rp) { + solve_upper_triangular(A, b, *rp); + } +} +[[maybe_unused]] void _lint_helper() { + _lint_helper_template(); + _lint_helper_template(); + _lint_helper_template(); + _lint_helper_template(); + _lint_helper_template(); +} +} // namespace + +} // namespace aoc::math + +#endif /* end of include guard: GAUSS_ELIM_HPP_SVFEFUHA */ diff --git a/2023/src/util/util.hpp b/2023/src/util/util.hpp index 557825d..62d2673 100644 --- a/2023/src/util/util.hpp +++ b/2023/src/util/util.hpp @@ -52,6 +52,10 @@ struct CaptureStream { StreamRedirector redir; }; +// to be used in static_assert inside constexpr if +template +inline constexpr bool always_false = false; + } // namespace util #ifdef __GNUG__