RobinHankin / hyper2

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

zero power sum #218

Closed RobinHankin closed 3 months ago

RobinHankin commented 7 months ago

if the powers of a hyper2 object do not sum to zero, this is likely to be a coding error but there is no centralised discussion of the issue.

RobinHankin commented 6 months ago

reopening, hyper3 objects return an error:

library("hyper2")
#> Loading required package: cubature
a <- hyper3()
a["x"] <- 1
a
#> Error in print.hyper3(x): sum(powers(x)) == 0 is not TRUE

and they should return a warning, same as for hyper2 objects [if you want this to be an error, use options(warn=99)]

RobinHankin commented 4 months ago

reopening, zero power issue breaks inst/grad_weight.Rmd.

RobinHankin commented 3 months ago

Also the zero power issue breaks inst/rock_paper_scissors_monster.Rmd. After source() ing every chunk above defineproflikeh3, I get:

 H3seven(1.888)
log( (t1=1)^32 * (t1=1, t2=1.888)^-21 * (t1=1.888)^13 * (t1=1.888, t7=1)^-18 * (t2=1)^12 *
(t2=1, t3=1.888)^-15 * (t2=1.888)^5 * (t3=1)^10 * (t3=1, t4=1.888)^-16 * (t3=1.888)^9 *
(t4=1)^12 * (t4=1, t5=1.888)^-18 * (t4=1.888)^11 * (t5=1)^10 * (t5=1, t6=1.888)^-14 *
(t5=1.888)^12 * (t6=1)^8 * (t6=1, t7=1.888)^-11 * (t6=1.888)^9 * (t7=1)^5 * (t7=1.888)^7)
Warning message:
In print.hyper3(x) : powers have nonzero sum
> summary(H3seven(1.888))
A hyper3 object of size 7.
pnames:  t1 t2 t3 t4 t5 t6 t7 
Number of brackets: 21 
Sum of powers: 42 

Table of bracket lengths:
 1  2 
14  7 

Table of powers:
-21 -18 -16 -15 -14 -11   5   7   8   9  10  11  12  13  32 
  1   2   1   1   1   1   2   1   1   2   2   1   3   1   1 

Table of weights:
    1 1.888 
   14    14 
> 

Obviously a problem in H3seven() [and not, as claimed, a "known R bug"].

RobinHankin commented 3 months ago

Commit 7957bdd is a good example of this: it is a clear coding error [at one point I wanted to use setNames() for creating named vectors rather than jj <- 1:3; names(jj) <- c("a","b","c") and evidently I did this but forgot to remove the previous line. A perfectly understandable (and common) error! ] See how flagging the violation of the zero-sum power condition allowed me to trap this error.

RobinHankin commented 3 months ago

File grad_weight.Rmd was fixed in commit 83799cf.