Skip to contents

Concatenates its arguments to give a single free object

Usage

# S3 method for class 'free'
sum(..., na.rm = FALSE)

Arguments

...

Objects of class free, to be summed

na.rm

Boolean, indicating whether to ignore NA entries (currently ignored)

Details

Concatenates its arguments and gives a single element of the free group. It works nicely with rev(), see the examples.

Author

Robin K. S. Hankin

Note

The package uses additive notation, but it is easy to forget this and wonder why idiom like prod(rfree()) does not work as desired. Of course, the package using additive notation means that one probably wants sum(rfree()).

Examples


(x <- rfree(10,3))
#>  [1] a^6           b^-1.c        b^2.c^3.a     a^-2.c^-3     b^-2.c^-3    
#>  [6] b.a^-5        a^-3.b^3.c^-3 b^3.a^-3      c^-3.b^4      c^-4.b^2     
sum(x)
#> [1] a^6.b^-1.c.b^2.c^3.a^-1.c^-3.b^-2.c^-3.b.a^-8.b^3.c^-3.b^3.a^-3.c^-3.b^4.c^-4.b^2
abelianize(sum(x))
#> [1] a^-6.b^12.c^-12

(y <- rfree(10,6))
#>  [1] b^3.a^-1.c^-2.e^4.b         f^-2.d^6.b^-4.a^5.c^-3.b^-3
#>  [3] a^-1.b^-2.f.c^-4.b^-6.a^-2  e^3.c^2.a^-3.c^6.b^-6      
#>  [5] b^5.f^4.c^-2.d^-3.b^-1.e^6  f^-6.a^2.e^2.b^-2          
#>  [7] e^-5.b^-4.f^-3.d^-6.b^-5    b^-4.f^-2.a^-3.c^-1.a^2    
#>  [9] a^-3.e^-7.f^2.c^-5.b^4      b^-2.f^6.c^6.f^-3.e^-1     

sum(x,y)
#> [1] a^6.b^-1.c.b^2.c^3.a^-1.c^-3.b^-2.c^-3.b.a^-8.b^3.c^-3.b^3.a^-3.c^-3.b^4.c^-4.b^5.a^-1.c^-2.e^4.b.f^-2.d^6.b^-4.a^5.c^-3.b^-3.a^-1.b^-2.f.c^-4.b^-6.a^-2.e^3.c^2.a^-3.c^6.b^-1.f^4.c^-2.d^-3.b^-1.e^6.f^-6.a^2.e^2.b^-2.e^-5.b^-4.f^-3.d^-6.b^-9.f^-2.a^-3.c^-1.a^-1.e^-7.f^2.c^-5.b^2.f^6.c^6.f^-3.e^-1
sum(x,y) == sum(sum(x),sum(y))
#> [1] TRUE
x+y  # not the same!
#>  [1] a^6.b^3.a^-1.c^-2.e^4.b               
#>  [2] b^-1.c.f^-2.d^6.b^-4.a^5.c^-3.b^-3    
#>  [3] b^2.c^3.b^-2.f.c^-4.b^-6.a^-2         
#>  [4] a^-2.c^-3.e^3.c^2.a^-3.c^6.b^-6       
#>  [5] b^-2.c^-3.b^5.f^4.c^-2.d^-3.b^-1.e^6  
#>  [6] b.a^-5.f^-6.a^2.e^2.b^-2              
#>  [7] a^-3.b^3.c^-3.e^-5.b^-4.f^-3.d^-6.b^-5
#>  [8] b^3.a^-3.b^-4.f^-2.a^-3.c^-1.a^2      
#>  [9] c^-3.b^4.a^-3.e^-7.f^2.c^-5.b^4       
#> [10] c^-4.f^6.c^6.f^-3.e^-1                

sum(x,-x)
#> [1] a^6.b^-1.c.b^2.c^3.a^-1.c^-3.b^-2.c^-3.b.a^-8.b^3.c^-3.b^3.a^-3.c^-3.b^4.c^-4.b^2.a^-6.c^-1.b.a^-1.c^-3.b^-2.c^3.a^2.c^3.b^2.a^5.b^-1.c^3.b^-3.a^6.b^-7.c^3.b^-2.c^4
sum(x,rev(-x))
#> [1] 0

z <- alpha(26)
stopifnot(sum(x^z) == sum(x)^z)