[GiNaC-list] table and exhashmap

Sheplyakov Alexei varg at theor.jinr.ru
Sun Feb 18 18:38:23 CET 2007


Hi,

On Mon, Feb 19, 2007 at 12:29:55AM +0800, Jerome BENOIT wrote:

> I am new in GiNaC and in C++ (but very familiar with another CAS and C).
> 
> I would like to implement a function which returns table.
> Unless I missed something, there is no ready to use table object
> in GiNaC.

I guess you want to use GiNaC::exmap (and [re-]read your favourite C++
textbook, at least the chapter which describes STL containers, in
particular associative arrays).

For example,

#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;

exmap foo(const ex& x, const ex& y)
{
  exmap something;
	something[x] = x + y/2;
	something[y] = cos(x);
	return something;
}

int main(int argc, char** argv)
{
	symbol x("x"), y("y");
	exmap tbl;
	tbl = foo(x-y, 2*y);
	for (exmap::const_iterator i=tbl.begin(); i!=tbl.end(); ++i)
	 cout << i->first << " => " << i->second << endl;
	// will print something like:
	// 2*y => cos(-y+x)
	// -y+x => x 
  
	return 0;
}

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/20070218/c80a6d0d/attachment.pgp


More information about the GiNaC-list mailing list