[Date Index] [Thread Index] [Author Index]
Problem with Times. Bug ????
Hello, I am trying to implement a fast non-commutative operation under Mma to work with non-commutative algebras (see a previous post). Among the things I tried, one was to redefine the Times operation in order to make it non- commutative on a certain class of objects, and to reimplement the commutativity for all other standard objects for which Times is usually commutative. I know that this is _highly_ discouraged by the authors of Mma. I tried various implementations, and got contradictory or inconsistent results, I tracked down the problem and found this : In:= b a Out= a b ! this is the standard order, Times is ! commutative In:= Unprotect[Times]; In:= ClearAttributes[Times,Orderless] ! This removes the commutativity of Times In:= b a Out= b a ! OK, it doesn't commute anymore In:= a_*(b_+c_):=a*b + a*c; ! This introduces the left ditributivity ! of Times on Plus In:= 2 (1 + b a) Out= 2 + b a ! the result is as expected. In:= 2 (1 - b a) Out= 2 - 2 a b ! ???? the expression In matches the pattern ! on the left handside of In, but in the ! replacement process Mma seems to have forgotten ! that Times is not commutative anymore !!! Is this a bug ? Is it due to a specific implementation of Times in the Kernel of Mma, so that Times does not tolerate modifications of its attributes ? Thanks for your answers, Adriano Barenco ============================================== Adriano Barenco Inst. for Micro- and Optoelectronics Dept. of Physics Swiss Fed. Inst. of Technology (EPFL) PHB-Ecublens CH-1015 Lausanne (Switzerland) email: barenco at eldpa.epfl.ch ==============================================