Hi. I'm trying to use list as input. List as output prints {expr1,expr2,..}, list.nops() is varying. When I write list as: parser reader; somelist=reader(cin); where input to cin: {expr1,expr2,..} at the end shift-D It returns somelist={expr1,expr2,..}, somelist.nops()=1. When accessing the 2nd and higher element of list, program gets segmentation fault.
On 03/01/2015 11:38 AM, soppon wrote:
Hi. I'm trying to use list as input. List as output prints {expr1,expr2,..}, list.nops() is varying. When I write list as: parser reader; somelist=reader(cin); where input to cin: {expr1,expr2,..} at the end shift-D It returns somelist={expr1,expr2,..}, somelist.nops()=1. When accessing the 2nd and higher element of list, program gets segmentation fault.
Please do provide a minimal sample program when reporting bugs. Thanks. -richard. -- Richard B. Kreckel <http://in.terlu.de/~kreckel/>
On 03/01/2015 05:53 AM, Richard B. Kreckel wrote:
On 03/01/2015 11:38 AM, soppon wrote:
Hi. I'm trying to use list as input. List as output prints {expr1,expr2,..}, list.nops() is varying. When I write list as: parser reader; somelist=reader(cin); where input to cin: {expr1,expr2,..} at the end shift-D It returns somelist={expr1,expr2,..}, somelist.nops()=1. When accessing the 2nd and higher element of list, program gets segmentation fault. Please do provide a minimal sample program when reporting bugs. Thanks.
-richard. #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC;
int main() { symbol xs("x"); lst expr; parser reader; expr=reader("{x,x}"); cout <<"list " << expr << endl; cout <<"number of elements "<< expr.nops() << endl; cout <<"1st el " <<expr[0] << endl; cout <<"2nd el, error " <<expr[1]<< endl; return 0; }
On 03/01/2015 12:25 PM, soppon wrote:
#include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC;
int main() { symbol xs("x"); lst expr; parser reader; expr=reader("{x,x}"); cout <<"list " << expr << endl; cout <<"number of elements "<< expr.nops() << endl; cout <<"1st el " <<expr[0] << endl; cout <<"2nd el, error " <<expr[1]<< endl; return 0; }
Your list expr has only one element, which is itself a list with two elements. best wishes -richy. -- Richard B. Kreckel <http://in.terlu.de/~kreckel/>
On Sun, 01 Mar 2015 13:07:15 +0100, "Richard B. Kreckel" <kreckel@in.terlu.de> said:
RK> On 03/01/2015 12:25 PM, soppon wrote: >> #include <iostream> #include <ginac/ginac.h> using namespace std; >> using namespace GiNaC; >> >> int main() { symbol xs("x"); lst expr; parser reader; >> expr=reader("{x,x}"); cout <<"list " << expr << endl; cout >> <<"number of elements "<< expr.nops() << endl; cout <<"1st el " >> <<expr[0] << endl; cout <<"2nd el, error " <<expr[1]<< endl; >> return 0; } RK> Your list expr has only one element, which is itself a list with RK> two elements. As was already suggested, a plain list may be obtained by: expr=ex_to<lst>(reader("{x,x}")); -- 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/
On 03/01/2015 07:14 AM, Vladimir V. Kisil wrote:
On Sun, 01 Mar 2015 13:07:15 +0100, "Richard B. Kreckel" <kreckel@in.terlu.de> said: RK> On 03/01/2015 12:25 PM, soppon wrote: >> #include <iostream> #include <ginac/ginac.h> using namespace std; >> using namespace GiNaC; >> >> int main() { symbol xs("x"); lst expr; parser reader; >> expr=reader("{x,x}"); cout <<"list " << expr << endl; cout >> <<"number of elements "<< expr.nops() << endl; cout <<"1st el " >> <<expr[0] << endl; cout <<"2nd el, error " <<expr[1]<< endl; >> return 0; }
RK> Your list expr has only one element, which is itself a list with RK> two elements.
As was already suggested, a plain list may be obtained by:
expr=ex_to<lst>(reader("{x,x}")); Thanks a lot for casting. Have a nice day.
On Sun, 01 Mar 2015 05:38:41 -0500, soppon <gvitbsord@aol.com> said:
soppon> Hi. I'm trying to use list as input. List as output prints soppon> {expr1,expr2,..}, list.nops() is varying. When I write list soppon> as: parser reader; somelist=reader(cin); where input to cin: soppon> {expr1,expr2,..} at the end shift-D It returns soppon> somelist={expr1,expr2,..}, somelist.nops()=1. When soppon> accessing the 2nd and higher element of list, program gets soppon> segmentation fault. I am not completely sure, but the following example may give you a hint: ex l1=lst(a,b,c); lst l2=l1; In this case l1.nops()=3, but l2.nops()=1, because l2 has the only element equal to l1 as a whole. To get thing right you may use: ex l1=lst(a,b,c); lst l2=ex_to<lst>(l1); To analyse situation use somelist.dbgprint() or even somelist.dbgprinttree(). -- 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/
On 03/01/2015 06:01 AM, Vladimir V. Kisil wrote:
On Sun, 01 Mar 2015 05:38:41 -0500, soppon <gvitbsord@aol.com> said: soppon> Hi. I'm trying to use list as input. List as output prints soppon> {expr1,expr2,..}, list.nops() is varying. When I write list soppon> as: parser reader; somelist=reader(cin); where input to cin: soppon> {expr1,expr2,..} at the end shift-D It returns soppon> somelist={expr1,expr2,..}, somelist.nops()=1. When soppon> accessing the 2nd and higher element of list, program gets soppon> segmentation fault.
I am not completely sure, but the following example may give you a hint:
ex l1=lst(a,b,c); lst l2=l1;
In this case l1.nops()=3, but l2.nops()=1, because l2 has the only element equal to l1 as a whole. To get thing right you may use:
ex l1=lst(a,b,c); lst l2=ex_to<lst>(l1);
To analyse situation use somelist.dbgprint() or even somelist.dbgprinttree(). I didn't see dbgprint() in tutorial, so i use tree for debug. #include <iostream> #include <ginac/ginac.h> using namespace std; using namespace GiNaC;
int main() { symbol xs("x"); lst expr,ep; parser reader; expr=reader("{x,x}"); ep=xs,xs; cout<<expr<<tree << endl; //get {{x,x}} cout<<ep<<tree << endl; //some hash table return 0; }
participants (3)
-
Richard B. Kreckel
-
soppon
-
Vladimir V. Kisil