subs.Rd
Substitute symbols in a freealg
object for numbers or other
freealg
objects
subs(...)
subsu(S1,S2,r)
Returns a freealg
object.
Function subs()
substitutes variables for freealg
objects
(coerced if necessary) using natural R idiom. Observe that this type
of substitution is sensitive to order:
> subs("ax",a="1+x",x="1+a")
free algebra element algebraically equal to
+ 2 + 3*a + 1*aa
> subs("ax",x="1+a",a="1+x")
free algebra element algebraically equal to
+ 2 + 3*x + 1*xx
Functions subsu()
is a lower-level formal function, not really
intended for the end-user. Function subsu()
takes S1
and
substitutes occurrences of symbol r
with S2
.
No equivalent to mvp::subvec()
is currently implemented.
Function subs()
is one place in the package where the use of
letters
is effectively hard-wired in. Idiom such as
subs("abccc",b="1+3x")
is very nice, but identifies “b” with 2. Note that argument
r
of subsu()
is canonically an integer but a single
character is interpreted as a letter
. See also the note
at freealg.Rd
.
subs("abccc",b="1+3x")
#> free algebra element algebraically equal to
#> + accc + 3axccc
subs("aaaa",a="1+x") # binomial
#> free algebra element algebraically equal to
#> + 1 + 4x + 6xx + 4xxx + xxxx
subs("abA",b=31)
#> free algebra element algebraically equal to
#> + 31
subs("1+a",a="A") # can substitute for an inverse
#> free algebra element algebraically equal to
#> + 1 + A
subs("A",a="1+x") # inverses are not substituted for
#> free algebra element algebraically equal to
#> + A
## Sequential substitution works:
subs("abccc",b="1+3x",x="1+d+2e")
#> free algebra element algebraically equal to
#> + 4accc + 3adccc + 6aeccc
subs(rfalg(),a=rfalg())
#> free algebra element algebraically equal to
#> + 42aaa + 6ac + 12acaa + 48b + 7bc + 24c + 21caaa + 196caaabaaa + 28caaabac +
#> 56caaabacaa + 231caaabb + 112caaabc + 168caaabcbb + 3cac + 6cacaa + 56cacaabaaa
#> + 8cacaabac + 16cacaabacaa + 66cacaabb + 32cacaabc + 48cacaabcbb + 28cacbaaa +
#> 4cacbac + 8cacbacaa + 33cacbb + 16cacbc + 24cacbcbb + 24cb + 36cbb + 224cbbaaa
#> + 32cbbac + 64cbbacaa + 264cbbb + 128cbbc + 192cbbcbb + 12cc + 7ccb + 112ccbaaa
#> + 16ccbac + 32ccbacaa + 150ccbb + 168ccbbbaaa + 24ccbbbac + 48ccbbbacaa +
#> 198ccbbbb + 96ccbbbc + 144ccbbbcbb + 64ccbc + 96ccbcbb