MultiLinear and Linear function
- To: mathgroup at smc.vnet.net
- Subject: [mg25540] MultiLinear and Linear function
- From: "Arturas Acus" <acus at itpa.lt>
- Date: Sat, 7 Oct 2000 03:35:43 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Dear group, Here was a question how to make a function linear. Below is the solution from (I think Noncommutative Algebra package, but not sure): SetLinear[a__] := (Function[x, x[0] := 0; x[y_ + z_] := x[y] + x[z]; x[c_ y_] := c x[y] /; NumberQ[c]; x[y_/c_] := (1/c) x[y] /; NumberQ[c]; x[c_] := c x[1] /; NumberQ[c] && Not[TrueQ[c == 1]]; x[-y_] := -x[y]; LinearQ[x] = True;] /@ {a}); It works fine, but is only applied to function of multiple variables. Bolow is my solution for MultiLinear function. It works, but is not so elegant as example bekow. Probably anybody knows a better approach? makePattern[x_, y_, {n_Integer, {m_Integer}}] := Module[{z, p1, p2}, p1 = Table[Unique[], {n - 1}]; p2 = Table[Unique[], {z, n + 1, m}]; ReplaceAll[ Function[y, x[Sequence @@ Flatten[Pattern[#, Blank[]] & /@ p1], y, Sequence @@ Flatten[Pattern[#, Blank[]] & /@ p2]]], Pattern -> myPattern]] SetMultiLinear[ s__Symbol, {i_Integer, {l_Integer}}] := (Function[x, Module[{pureF, locvar}, pureF = makePattern[x, locvar, {i, {l}}]; SetDelayed @@ {ReplaceAll[ Evaluate[pureF[y_ + z_], myPattern -> Pattern]], ReplaceAll[Evaluate[pureF[y] + pureF[z]], myPattern[a_, Blank[]] :> a]}; SetDelayed @@ {ReplaceAll[ Evaluate[pureF[c_*y_], myPattern -> Pattern]], ReplaceAll[Evaluate[c*pureF[y]], myPattern[a_, Blank[]] :> a] /; NumberQ[c]}; SetDelayed @@ {ReplaceAll[ Evaluate[pureF[y_/c_], myPattern -> Pattern]], ReplaceAll[Evaluate[(1/c)*pureF[y]], myPattern[a_, Blank[]] :> a] /; NumberQ[c]}; SetDelayed @@ {ReplaceAll[ Evaluate[pureF[c_], myPattern -> Pattern]], ReplaceAll[Evaluate[c*pureF[1]], myPattern[a_, Blank[]] :> a] /; NumberQ[c] && Not[TrueQ[c === 1]]}; LinearQ[x, {i, {l}}] = True; ]; ] /@ {s}) /; Greater[l, 1] SetMultiLinear[s__Symbol, {All, {l_Integer}}] := Map[SetMultiLinear[s, {#, {l}}] &, Range[l]] Example of usage: Make Commutator and AntiCommutator linear functions of both variables: SetMultiLinear[Commutator,AntiCommutator,{All,{2}}]. Make f be linear in 3-th its argument of total 5: SetMultiLinear[f,{3,{5}}]. Better solution welcome Dr. Arturas Acus Institute of Theoretical Physics and Astronomy Gostauto 12, 2600,Vilnius Lithuania E-mail: acus at itpa.lt Fax: 370-2-225361 Tel: 370-2-612906
- Follow-Ups:
- Re: MultiLinear and Linear function
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: MultiLinear and Linear function