RobinHankin / hyper2

https://robinhankin.github.io/hyper2/
5 stars 3 forks source link

gotcha #208

Closed RobinHankin closed 1 year ago

RobinHankin commented 1 year ago

Following issue #148:

suppressMessages(library("hyper2"))
suppressMessages(library("partitions"))
a <- multiset(c(1,1,2,2,3))
a[] <- letters[a]
a
#>                                                                 
#> [1,] a a a a a a a a a a a a b b b b b b b b b b b b c c c c c c
#> [2,] a a a b b b b b b c c c a a a a a a b b b c c c a a a b b b
#> [3,] b b c a a b b c c a b b a a b b c c a a c a a b a b b a a b
#> [4,] b c b b c a c a b b a b b c a c a b a c a a b a b a b a b a
#> [5,] c b b c b c a b a b b a c b c a b a c a a b a a b b a b a a
(H <- do.call("sum",apply(a,2,ordervec2supp3)))
#> log(a^45 * (a + b)^-30 * (a + b + c)^-66 * (a + c)^-9 * b^45 * (b +
#> c)^-9 * c^24)

Created on 2023-06-26 with reprex v2.0.2

Above I would expect a hyper3 object but get a hyper2 object. Look:

suppressMessages(library("hyper2"))
suppressMessages(library("partitions"))
a <- multiset(c(1,1,2,2,3))
a[] <- letters[a]     #as before

jj <- apply(a,2,ordervec2supp3)
jj[[1]]
#> log( (a=1)^2 * (a=1, b=2, c=1)^-1 * (a=2, b=2, c=1)^-1 * (b=1)^2 *
#> (b=1, c=1)^-1 * (b=2, c=1)^-1)
do.call("sum",jj)
#> log(a^45 * (a + b)^-30 * (a + b + c)^-66 * (a + c)^-9 * b^45 * (b +
#> c)^-9 * c^24)
Reduce("sum" ,jj)
#> log(a^45 * (a + b)^-30 * (a + b + c)^-66 * (a + c)^-9 * b^45 * (b +
#> c)^-9 * c^24)
Reduce("+"   ,jj)
#> log( (a=1)^48 * (a=1, b=1)^-12 * (a=1, b=1, c=1)^-12 * (a=1, b=2)^-6 *
#> (a=1, b=2, c=1)^-12 * (a=1, c=1)^-6 * (a=2)^-3 * (a=2, b=1)^-6 * (a=2,
#> b=1, c=1)^-12 * (a=2, b=2)^-6 * (a=2, b=2, c=1)^-30 * (a=2, c=1)^-3 *
#> (b=1)^48 * (b=1, c=1)^-6 * (b=2)^-3 * (b=2, c=1)^-3 * (c=1)^24)

Created on 2023-06-26 with reprex v2.0.2

Above we see that only the final call, Reduce("+",jj) actually gives a hyper3 object. What is going on here?

RobinHankin commented 1 year ago

Before I forget, it's worth observing that the hyper3 object is does indeed return an evaluate that is symmetric between a, b,c:

suppressMessages(library("hyper2"))
suppressMessages(library("partitions"))
a <- multiset(c(1,1,2,2,3))
a[] <- letters[a]
H <- Reduce("+",apply(a,2,ordervec2supp3))
maxp(H)
#>         a         b         c 
#> 0.3333333 0.3333333 0.3333333

Created on 2023-06-26 with reprex v2.0.2