About non commutative transformations in GiNaC
Hello, I wrote a program to do calculations with non commutative variables in GiNaC. But when I made attempt to apply noncommutative rule I got error: terminate called after throwing an instance of 'std::logic_error' what(): add::eval(): sum of non-commutative objects has non-zero numeric term Below is simple example of program with program output. How to change the class ncsymbol so that it was possible to apply rules like a*ap==ap*a+1? Best regards Petrov A.B. -------------------------------------------------------------------- Output for program: Starting: ./test2 e1: a*ap*a terminate called after throwing an instance of 'std::logic_error' what(): add::eval(): sum of non-commutative objects has non-zero numeric term *** Crashed with return code: 0 *** ------------------------------------------------------------------ Program: #include <iostream> using namespace std; #include<ginac/ginac.h> using namespace GiNaC; class ncsymbol : public symbol { GINAC_DECLARE_REGISTERED_CLASS(ncsymbol, symbol) public: ncsymbol(const string &s); protected: unsigned return_type() const { return return_types::noncommutative_composite; } }; GINAC_IMPLEMENT_REGISTERED_CLASS(ncsymbol, symbol) ncsymbol::ncsymbol() { } ncsymbol::ncsymbol(const string &s) : inherited(s) { } int ncsymbol::compare_same_type(const basic &other) const { GINAC_ASSERT(is_a<ncsymbol>(other)); const ncsymbol *o = static_cast<const ncsymbol *>(&other); if (serial==o->serial) return 0; return serial < o->serial ? -1 : 1; } void calc_example(){ ncsymbol a("a"),ap("ap"); ex e1 = a*ap*a; cout << "e1: " << e1 << endl; e1 = e1.subs(a*ap==ap*a+1); cout << "e1 subs: " << e1 << endl; } int main(int argc, char** argv) { calc_example(); return 0; }
Hi,
On Mon, 23 Jan 2017 00:35:56 +0500, abpetrov <abpetrov@ufacom.ru> said: ABP> Below is simple example of program with program output. How to ABP> change the class ncsymbol so that it was possible to apply ABP> rules like a*ap==ap*a+1?
If you need just an implementation of the Heisenberg commutation relations you can use clifford class for this. GiNaC clifford class can handle both anti-commutators (proper Clifford algebras) and commutators. The attached example show this: "+1" at the end of definition of e tells to use commutators. Many years ago I derived a class lie_algebra from the class clifford, it was able to represent an arbitrary Lie algebra. At that time it was badly written (messing with some pointers) and it does not work with the current GiNaC (as I have discovered yesterday). Yet, that can be done properly. However, the speed for large commutators was not great, Singular is doing this much better. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
It works. Thank you for your answer. But important question remains. Can I get latex output for a and ap like a^{- i_1 ... i_n}_{j_1 ... j_n} with contravariant and covariant indexes? For ncsymbol class I can do it. When I tried to do it with clifford with program cout << latex << endl; cout << indexed(a,nu) << endl; I got next result: {\clifford[0]{e}_{{0} }}_{{\nu} } It contains excess symbols like {\clifford[0]{e}_{{0} }} and don't contains a^{-} or a^{+} On 01/23/2017 03:32 PM, Vladimir V. Kisil wrote:
Hi,
On Mon, 23 Jan 2017 00:35:56 +0500, abpetrov <abpetrov@ufacom.ru> said: ABP> Below is simple example of program with program output. How to ABP> change the class ncsymbol so that it was possible to apply ABP> rules like a*ap==ap*a+1?
If you need just an implementation of the Heisenberg commutation relations you can use clifford class for this. GiNaC clifford class can handle both anti-commutators (proper Clifford algebras) and commutators. The attached example show this: "+1" at the end of definition of e tells to use commutators.
Many years ago I derived a class lie_algebra from the class clifford, it was able to represent an arbitrary Lie algebra. At that time it was badly written (messing with some pointers) and it does not work with the current GiNaC (as I have discovered yesterday). Yet, that can be done properly. However, the speed for large commutators was not great, Singular is doing this much better.
Best wishes, Vladimir
Hi,
On Wed, 25 Jan 2017 00:21:11 +0500, abpetrov <abpetrov@ufacom.ru> said: ABP> Can I get latex output for a and ap like ABP> a^{- i_1 ... i_n}_{j_1 ... j_n} with contravariant and ABP> covariant indexes?
ABP> For ncsymbol class I can do it. When I tried to do it with ABP> clifford with program ABP> cout << latex << endl; cout << indexed(a,nu) << endl; ABP> I got next result: ABP> {\clifford[0]{e}_{{0} }}_{{\nu} } ABP> It contains excess symbols like {\clifford[0]{e}_{{0} }} and ABP> don't contains a^{-} or a^{+} Here is a quote from the tutorial with some ideas: LaTeX output for Clifford units looks like '\clifford[1]{e}^{{\nu}}', where '1' is the 'representation_label' and '\nu' is the index of the corresponding unit. This provides a flexible typesetting with a suitable definition of the '\clifford' command. For example, the definition \newcommand{\clifford}[1][]{e} typesets all Clifford units identically, while the alternative definition \newcommand{\clifford}[2][]{\ifcase #1 #2\or \tilde{#2} \or \breve{#2} \fi} prints units with 'representation_label=0' as 'e', with 'representation_label=1' as '\tilde{e}' and with 'representation_label=2' as '\breve{e}'. Alternatively, you can use a tool like sed to modify GiNaC output to something suitable. Best wishes, Vladimir -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
Thank you for your answer. I will try regular expressions in program. Best regards Petrov A.B. On 01/25/2017 12:41 AM, Vladimir V. Kisil wrote:
Hi,
On Wed, 25 Jan 2017 00:21:11 +0500, abpetrov <abpetrov@ufacom.ru> said: ABP> Can I get latex output for a and ap like ABP> a^{- i_1 ... i_n}_{j_1 ... j_n} with contravariant and ABP> covariant indexes?
ABP> For ncsymbol class I can do it. When I tried to do it with ABP> clifford with program
ABP> cout << latex << endl; cout << indexed(a,nu) << endl;
ABP> I got next result:
ABP> {\clifford[0]{e}_{{0} }}_{{\nu} }
ABP> It contains excess symbols like {\clifford[0]{e}_{{0} }} and ABP> don't contains a^{-} or a^{+}
Here is a quote from the tutorial with some ideas:
LaTeX output for Clifford units looks like '\clifford[1]{e}^{{\nu}}', where '1' is the 'representation_label' and '\nu' is the index of the corresponding unit. This provides a flexible typesetting with a suitable definition of the '\clifford' command. For example, the definition \newcommand{\clifford}[1][]{e} typesets all Clifford units identically, while the alternative definition \newcommand{\clifford}[2][]{\ifcase #1 #2\or \tilde{#2} \or \breve{#2} \fi} prints units with 'representation_label=0' as 'e', with 'representation_label=1' as '\tilde{e}' and with 'representation_label=2' as '\breve{e}'.
Alternatively, you can use a tool like sed to modify GiNaC output to something suitable.
Best wishes, Vladimir
participants (2)
-
abpetrov
-
Vladimir V. Kisil