RobinHankin / clifford

5 stars 0 forks source link

extraction gotcha #99

Closed RobinHankin closed 3 months ago

RobinHankin commented 3 months ago
library("clifford")
x <- 5 + 6*e(1)
x
#> Element of a Clifford algebra, equal to
#> + 5 + 6e_1
x[0]
#> Element of a Clifford algebra, equal to
#> scalar ( 5 )
x[0,drop=TRUE]
#> Element of a Clifford algebra, equal to
#> + 5 + 6e_1

Above, x[0] works as expected but x[0,drop=TRUE] gives an unexpected result (here I wanted 5).

RobinHankin commented 3 months ago

Also:

suppressMessages(library("clifford"))
x <- 5 + 6*e(1) - 7*e(1:3)
x
#> Element of a Clifford algebra, equal to
#> + 5 + 6e_1 - 7e_123
getcoeffs(x,1)
#> [1] 6
getcoeffs(x,0)
#> [1] 0

The second call to getcoeffs() is seriously unexpected: I was trying to get 5 (which would indeed be returned by x[0]). Actually, direct use of getcoeffs() to find the constant is awkward: you need to use getcoeffs(x,list(numeric(0))) to get the 5.

In any event, none of this is documented at ?Extract.clifford.