Re: define a new object or use the existing?
- To: mathgroup at smc.vnet.net
- Subject: [mg24377] Re: define a new object or use the existing?
- From: zhl67 at my-deja.com
- Date: Wed, 12 Jul 2000 23:13:17 -0400 (EDT)
- References: <8k9irm$fqq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <8k9irm$fqq at smc.vnet.net>, Maris =?iso-8859-1?Q?T=F5nso?= <maris at tpu.ee> wrote: > Hi! > > I am trying to write a program which could handle noncommutative twisted > polynomials. A noncommutative polynomial has a form > > p(delta) = pn**delta^n + ... + p2**delta^2 + p1**delta + p0, > > where ** denotes noncommutative multiplication. I can not decide, which > is better way to represent an object pi**delta^i : to define additional > rules for function NonCommutativeMulitply or to build a special new > object on > this purpose, for example Twisted[pi,i]. > > You will probably say that it depends on concrete circumstances or > there is no difference in principle; but I still hope you can give some > comments > on this problem. > > And the other problem: If I choose to build a new object when I would > like object > Twisted[p, n] > in StandardForm to be printed as > p delta^n. > One way to get it is to use Format and Postfix: > Format[Twisted[p_,n_]] := Postfix[{p}, delta^n ] > But this solution does not satisfy me. > > I would like to know if there exists a elegant way to define the > formatting for the object Twisted so that > Twisted[p+q, n] would printed as (p+q) delta^n (not p+q delta^n) and > Twisted[1, n] would printed as delta^n (not 1 delta^n). > > Thanks for any advices. > > Maris Tonso > Tallinn, Estonia > > First Question: it DOES depends on how much you would your program to do and which environment you would your program to work in. In fact I would preferr to add new rules to the existing function NonCommutativeMultiply if the program is assumed to be a general purpose noncommutative polynomial program, and that it is not assumed to work jointly with other existing programs of the same kind (e.g. the NCAlgebra package from math source). However, if you wish your program to work on top of NCAlgebra or any other packages which contains a lot of additional rules for NonCommutativeMultiply, it is better to define your new function! Second Question: I would use MakeBoxes to do the job. Here is am example (which I actually use for my noncommutative multiply function which I named Diamond to take advantage of the built-in infix form operator): Diamond /: MakeBoxes[Diamond[x_, y___], TraditionalForm] := RowBox[{RowBox[{If[Head[x]===Plus, Seq["(",MakeBoxes[x,TraditionalForm],")"], MakeBoxes[x,TraditionalForm] ]/.Seq->Sequence}], If[Length[{y}] === 0, "", Seq["\[Diamond]",MakeBoxes[Diamond[y], TraditionalForm]] ]/.Seq->Sequence} ] Liu Zhao Sent via Deja.com http://www.deja.com/ Before you buy.