RobinHankin / partitions

R package for integer partitions
9 stars 5 forks source link

conjugate of the empty partition #9

Closed stla closed 4 years ago

stla commented 5 years ago

Hello,

conjugate(NULL) and conjugate(c()) return an error. It would be nice if they returned integer(0).

RobinHankin commented 5 years ago

hello again stla, great to hear from you! I am fascinated by edge cases, thanks for this.

If v is a partition we have max(conjugate(v)) == length(v) so having conjugate(NULL) evaluating to integer(0) would be inconsistent with this: the LHS would be undefined and the RHS zero. But on the other hand we might say that conjugate(v)[1] == length(v) and here your suggestion would have a LHS of NA and a RHS of 0.

Currently, we have conjugate(n) returning rep(1,n) which includes n=0 so conjugate(0) returns integer(0)...and one consequence of your suggestion would be that conjugate(0) == conjugate(NULL). So we would have two distinct (?) partitions with the same (?) conjugate, which would not (?) be desirable (?).

Do you have any comment on the above reasoning? I'd say that current package behaviour is unhelpful at best and should be changed, but perhaps a more informative error message is the best that we could hope for.

stla commented 5 years ago

Hello Robin,

Me too, I love edge cases ^^

one consequence of your suggestion would be that conjugate(0) == conjugate(NULL). So we would have two distinct (?) partitions with the same (?) conjugate, which would not (?) be desirable (?).

I disagree that the partition 0 is distinct to NULL. The partition c(x1, x2, 0 ,0 ,0) is identical to the partition c(x1,x2). Trailing zeros should be droppable.

So the "true" empty partition in R should be integer(0), or c(), or NULL. And I have just checked that conjugate(integer(0)) also returns an error (another one). This is not nice I think, because the empty partition is self-conjugate, and one has

> conjugate(0)
integer(0) # the true empty partition !

We should have conjugate(conjugate(x)) = x for a self-conjugate partition.

At least, conjugate(x) should return a partition. And currently conjugate(0) returns integer(0), which is not seen as a partition for your package because we cannot apply conjugate on it.

stla commented 5 years ago

We should have conjugate(conjugate(x)) = x for a self-conjugate partition.

Stupid of me, conjugate(conjugate(x)) = x for any partition x.

But I meant it's not normal that conjugate(conjugate(0)) returns an error.