Re: Re: Factorising operators??
- To: mathgroup at smc.vnet.net
- Subject: [mg30992] Re: [mg30978] Re: [mg30959] Factorising operators??
- From: Andrzej Kozlowski <andrzej at bekkoame.ne.jp>
- Date: Sat, 29 Sep 2001 20:43:36 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Looking again at my message below I can see now a error or rather a misprint. In fact there are two possibilities. If you want the variable always to be x you should define f as: f[(m_:1) a[x] +(n_:1)b[x]+c_:0] :=(m a + n b+c)[x] If on the other hand you want to allow arbitrary variable names you could use: f[(m_:1) a[x_Symbol] +(n_:1)b[x_Symbol]+c_:0] :=(m a + n b+c)[x] Andrzej On Saturday, September 29, 2001, at 05:18 PM, Andrzej Kozlowski wrote: > I think the easiest way is as follows: > > In[1]:= > Unprotect[Plus]; > > In[2]:= > (m_:1) a[x] +(n_:1)b[x_]+c_:0 :=(m a + n b+c)[x] > > In[3]:= > Protect[Plus]; > > In[4]:= > 3a[x]+5b[x]+2 > > Out[4]= > (2+3 a+5 b)[x] > > In[5]:= > a[x]+5b[x] > > Out[5]= > (a+5 b)[x] > > One should always think twice before modifying such basic built in > functions as Plus. You might therefore prefer to use a different > approach. You might for example define a function f, that will transform > your expression only when you apply f to it: > > In[2]:= > f[(m_:1) a[x] +(n_:1)b[x_]+c_:0] :=(m a + n b+c)[x] > > In[3]:= > f[3a[x]+5b[x]+2] > > Out[3]= > (2+3 a+5 b)[x] > > Or you might even find it convenient to use f as a transformation > function in Simplify: > > In[6]:= > Simplify[3a[x]+5b[x]+2,TransformationFunctions->{Automatic,f}] > > Out[6]= > (2+3 a+5 b)[x] > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > > On Friday, September 28, 2001, at 04:55 PM, Mat Bowen wrote: > >> Hello, >> >> I'm new to mathematica and looking for help with the following: >> >> I have two operators, a and b, that function as approximations to first >> and >> second order derivatives. I can write (a+b)[x] and then use >> Through[%,Plus] >> to generate a[x]+b[x] but I want to do the reverse, ie. Get mathematica >> to >> output (a+b)[x] if I give it a[x]+b[x]. Is there any way (preferably >> simple) >> to do this which will also work with more general cases ie. >> a[x]+5b[x]+const >> c[x] should produce (a+5b+const)[x] >> >> Thanks, >> Mat Bowen >> >> >> > > >