I am new to Mathematica, so I am sorry if this is a bit of a stupid question but I really am stumped.
I am trying to define a function in Mathematica that does a very specific thing, but for some reason Mathematica keeps crashing while testing it. After messing around a bit I have found where the problem lies: when trying to evaluate a simple For
loop Mathematica keeps crashing (to the point where I have to force close it with Task Manager). See the image below:
vectorBasis
is a function defined below. As you can see, Length[vectorBasis[perm]]
is simply the number 3, so I really feel like the For
-loop should print the numbers 1, 2, and 3. But this completely crashes Mathematica.
Can anyone explain to me why this happens and how I can avoid it? Thanks!
Edit: Someone asked for a copy paste-able code, so here it is:
perm = {2,3,4}
vectorBasis[perm]
Length[vectorBasis[perm]]
For[i = 1, i <= Length[vectorBasis[perm]], i++, Print[i]]
The reason that I hadn't included it is that for this to be evaluate-able you need the function vectorBasis
, which relies on functions from the amplituhedronBoundaries package (paper). The definitions might be a bit convoluted, but they seem to work:
<<amplituhedronBoundaries`
arrayToVec[array_, dimension_] := Module[{EmptyVec = ConstantArray[0, dimension]}, For[i = 1, i <= Length[array], i++, EmptyVec = placePart[EmptyVec, array[[i]] -> 1]]; EmptyVec]
vectorBasis[permutation_] := arrayToVec[#, Length[permutation]] & /@ hypBasis[topCell[Length[permutation], permK[permutation]]]
where hypBasis
, topCell
and permK
are defined in the package I linked above.
For
loops are usually mutually exclusive undertakings ;) There are much better ways that you should learn. $\endgroup$