Clifford base names WAS: Re: [GiNaC-list] How can I get a
GiNaC::ex's name
Sheplyakov Alexei
varg at theor.jinr.ru
Fri May 25 15:42:32 CEST 2007
Hello!
On Thu, 2007-05-24 at 14:50 -0400, Warren Weckesser wrote:
> This works for me:
>
> string s = ex_to<symbol>(E).get_name();
>
Firstly, I'd like to note that GiNaC expressions do not have any
"names" at all. Only symbols have "names" which serve merely as
a printing representation. Two different symbols may have the same
name, as in
symbol x("x"), y("x"); // valid code
or
namespace A {
symbol x("x");
}
namespace B {
symbol x("x");
}
So your code will work if (and only if) E is a symbol. And it is good
idea to check if E is indeed symbol, since ex_to<T> functions are unsafe
(as documented in the manual), e.g.
string s = "dunno";
if (is_a<symbol>(E))
s = ex_to<symbol>(E).get_name();
On Fri, May 25, 2007 at 10:48:44AM +0200, Javier Ros Ganuza wrote:
> I have a similar problem, if I define the clifford units this way,
>
> varidx nu(symbol("nu", "\\nu"), 3);
> ex basis1 = clifford_unit(mu, diag_matrix(lst(1, 1, 1)),0);
>
> ex e00 = basis1.subs(mu == 0),
> e01 = basis1.subs(mu == 1),
> e02 = basis1.subs(mu == 2);
>
> Then they are ploted
>
> cout << e00 << endl;
>
> Like this
>
> e~0
> I want to rename using symbol.set_name(string), but
> when I do
>
> cout << ex_to<symbol>(e00).get_name() << endl;
This should segfault. e00 is not a symbol, it is element of Clifford
algebra. So ex_to<symbol> is meaningless here...
> Anything gets plotted.
Well, some sunny day it may even print something. Probably you are
lucky :)
> So I suspect that e00 is not a symbol an then,
It is definitely not a symbol. It is an element of Clifford algebra.
> It woul be interesting to have this posibility, tough elements of
> diferent basis are right now plotted in the same way.
I don't think renaming symbols will help here.
> Basis1 e00, plots as e~0
>
> Basis2 e10, plots as e~0
> Nevertheless if plotting in latex style, units are plotted in a
> different way.
Indeed. And this is
$ cat test.cpp
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main(int argc, char** argv) {
varidx nu(symbol("nu", "\\nu"), 3);
ex basis1 = clifford_unit(nu, diag_matrix(lst(1, 1, 1)), 0);
ex basis2 = clifford_unit(nu, diag_matrix(lst(3, 1, 2)), 1);
ex e10 = basis1.subs(nu == 0),
e20 = basis2.subs(nu == 1);
cout << latex <<
"e10 = " << e10 << endl <<
"e20 = " << e20 << endl << dflt <<
"e10 = " << e10 << endl <<
"e20 = " << e20 << endl;
return 0;
}
$ g++ test.cpp; ./a.out
e10 = \clifford[0]{e}^{{0} }
e20 = \clifford[0]{e}^{{1} }
e10 = e~0
e20 = e~1
> How can I deal with this?.
May be make both formats print the same (well, almost) thing, like
this patch does:
diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp
index c7ce8d3..56ae54f 100644
--- a/ginac/clifford.cpp
+++ b/ginac/clifford.cpp
@@ -203,6 +203,7 @@ void clifford::do_print_dflt(const print_dflt & c, unsigned level) const
seq[0].print(c, precedence());
c.s << "\\";
} else
+ c.s << "e[" << int(representation_label) << "]";
this->print_dispatch<inherited>(c, level);
}
Best regards,
Alexei
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20070525/7af7093c/attachment.pgp
More information about the GiNaC-list
mailing list