RobinHankin / clifford

https://robinhankin.github.io/clifford/
5 stars 0 forks source link

replace method infelicity #90

Open RobinHankin opened 1 year ago

RobinHankin commented 1 year ago
suppressPackageStartupMessages(library("clifford"))
(a <- clifford(sapply(seq_len(7),seq_len),seq_len(7)))
#> Element of a Clifford algebra, equal to
#> + 1e_1 + 2e_12 + 3e_123 + 4e_1234 + 5e_12345 + 6e_123456 + 7e_1234567
grades(a)
#> A disord object with hash 185ca524fb71fa2ae28566b137978e475c1aa00f and elements
#> [1] 1 2 3 4 5 6 7
#> (in some order)
a[grades(a) < 4]
#> Element of a Clifford algebra, equal to
#> + 1e_1 + 2e_12 + 3e_123
a[grades(a) < 4] <- 0 
#> Error in is_ok_clifford(terms, coeffs): all(term_elements > 0) is not TRUE

Above, a[grades(a) < 4] works fine, but the subsequent replacement, while having a very reasonable interpretation, does not. Quite apart from it not working, the error message is unhelpful. As it says in Extract.Rd, it is possible to achieve the desired result by manipulating the coefficients of Clifford object a:

suppressPackageStartupMessages(library("clifford"))
(a <- clifford(sapply(seq_len(7),seq_len),seq_len(7)))
#> Element of a Clifford algebra, equal to
#> + 1e_1 + 2e_12 + 3e_123 + 4e_1234 + 5e_12345 + 6e_123456 + 7e_1234567
coeffs(a)[grades(a) < 4] <- 0
a
#> Element of a Clifford algebra, equal to
#> + 4e_1234 + 5e_12345 + 6e_123456 + 7e_1234567

What objects jj would be sensible on the right hand side of a replacement expression like a[grades(a) < 4] <- jj? One could make a case for any clifford object with terms all of which have grade less than 4, and zero in particular would be sensible. But writing such functionality does not seem at all easy. One would need to allow a[grades(a) < 4] <- 1000*e(1:3) (and modify a accordingly) while trapping ambiguous or meaningless idiom such as a[grades(a) < 4] <- 1000*e(1:4)