pepper: Combine variables in every possible order

pepperR Documentation

Combine variables in every possible order

Description

Given a list of variables, construct every term comprising only those variables; function pepper() returns a free algebra object equal to the sum of these terms.

The function is named for a query from an exam question set by Sarah Marshall in which she asked how many ways there are to arrange the letters of word “pepper”, the answer being \left({6\atop 1\,2\,3}\right)=\frac{6!}{1!2!3!}=60.

Function multiset() in the partitions package gives related functionality; for the record, one way to reproduce pepper("pepper") would be

    apply(matrix(c("p","e","r")[multiset(c(1,1,1,2,2,3))],nrow=6),2,paste,collapse="")
  

Usage

pepper(v)

Arguments

v

Variables to combine. If a character string, coerce to variable numbers

Author(s)

Robin K. S. Hankin

See Also

linear

Examples

pepper(c(1,1,1,1,1,1,2))  # 6 a's and 1 b
pepper(c(1,2,2,2,3))      # 1 a, 3 b's and 1 c
pepper("pepper")

RobinHankin/freealg documentation built on Dec. 24, 2024, 3:16 a.m.