1
$\begingroup$

I am using v12.2.0 on Win7-x64.

The difference between case 1 and case 2 is that the list being partitioned has 5 elements vs 4 elements, respectively.

Clear["Global`*"]
Partition[{a, b, c, d, e}, 3, 1, {3, 1}, {x, y}]

{{x, y, a}, {y, a, b}, {a, b, c}, {b, c, d}, {c, d, e}, {d, e, y}, {e, y, x}}

Partition[{a, b, c, d}, 3, 1, {3, 1}, {x, y}]

{{x, y, a}, {y, a, b}, {a, b, c}, {b, c, d}, {c, d, x}, {d, x, y}}

Question

Why is the cyclic padding different at the tail end of the output list for the two cases? Thank you for your help in advance.

$\endgroup$
2
  • $\begingroup$ Similar to 255119 that I just discovered. $\endgroup$
    – Syed
    Apr 1 at 10:47
  • $\begingroup$ Somewhat similar 50877. $\endgroup$
    – Syed
    Apr 10 at 12:22

1 Answer 1

2
$\begingroup$

To my understanding Partition constructs an underlying list of repeating sublists of {x,y} which's parts are used to fill in for padding. This I gleaned from this example in the documentation:

https://wolfram.com/xid/0bn6cgi-da1

Let's take an example and mark those positions that will get replaced with "?":

Partition[{a, b,c,d}, 3, 1, {3, 1}, "?"]

{{"?", "?", a}, {"?", a, b}, {a, b, c}, {b, c, d}, {c, d, "?"}, {d, "?", "?"}}

When we construct the corresponding "fill-in"-list with repeating units of {x,y} it will look like this:

Partition[{x, y}, 3, 1, {5, 1}]

{{x, y, x}, {y, x, y}, {x, y, x}, {y, x, y}, {x, y, x}, {y, x, y}}

Putting the "fill in"-list below the desired output of Partition one can easily see where x and y are replacing the corresponding "?":

{{"?", "?", a}, {"?", a, b}, {a, b, c}, {b, c, d}, {c, d, "?"}, {d, "?", "?"}}

{{x, y, x}, {y, x, y}, {x, y, x}, {y, x, y}, {x, y, x}, {y, x, y}}

Which would match your output from above.

The same happens for your other example. Replace {x,y} with "?" and have a look:

Partition[{a, b, c, d, e}, 3, 1, {3, 1}, "?"]

{{"?", "?", a}, {"?", a, b}, {a, b, c}, {b, c, d}, {c, d, e}, {d, e, "?"}, {e, "?", "?"}}

Compare it with the corresponding "fill-in"-list:

{{"?", "?", a}, {"?", a, b}, {a, b, c}, {b, c, d}, {c, d, e}, {d, e, "?"}, {e, "?", "?"}}

{{x, y, x}, {y, x, y}, {x, y, x}, {y, x, y}, {x, y, x}, {y, x, y},{x, y, x}}

Here you can see that the parts of the "fill-in"-list are y and y,x for filling the last two sublists in your example.

$\endgroup$
2
  • $\begingroup$ Thanks for your answer. I appreciate it very much. I can't phrase my lack of understanding clearly yet but roughly: Does the padlist always start at the first element such as x and then the padlist is repeated to create the fill-in list, no matter what the location kL is? Please allow me to study and experiment with it further. $\endgroup$
    – Syed
    Mar 28 at 18:30
  • $\begingroup$ @Syed You can check out the tutorial on Partition here: reference.wolfram.com/language/tutorial/… While I do believe to understand why the padding at the end of the list looks the way it does, I do not yet quite grasp why the beginning is doing what it's doing. I'd need to experiment myself and wrap my head around this. $\endgroup$
    – rowsi
    Mar 29 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.