Hi @shivamvats,

The updates regarding the

The updates regarding the

`Polynomial`

class is that:- test_polynomial.cpp is sent in, could you check on that?
- I have integrated with Visitor pattern with not much thought, just as to not break the builds.
- Made use of map_uint_mpz instead of map_uint_integer.

We need to discuss the next tasks in hand.

I am currently implementing the printer, then tests for add_poly and printer. Shouldn't take long.

Would this replacement for add_poly work?

```
RCP<const Polynomial> add_poly(const Polynomial &a, const Polynomial &b) {
map_uint_mpz dict;
for(auto &it : a.dict_)
dict[it.first] = it.second;
for(auto &it : b.dict_)
dict[it.first] += it.second;
RCP<const Polynomial> c = polynomial(a.var_, std::move(dict));
return c;
}
```

@certik seems to have efficiency concerns there, so I am considering a replacement.

Are you sure this is a correct replacement?

dict[it.first] is by default zero, if not initialized before.

Still I would like to test and only then change

I didn't know that.

```
void test_add_poly(){
std::string x = "x";
map_uint_mpz adict = {{0, 1}, {1, 2}, {2, 1}};
map_uint_mpz bdict = {{0, 2}, {1, 3}, {2, 4}};
RCP<const Polynomial> a = polynomial(x, std::move(adict));
RCP<const Polynomial> b = polynomial(x, std::move(bdict));
RCP<const Polynomial> c = add_poly(a, b);
assert(c->degree == 2);
assert(c->var_ == "x");
}
```

Is there a mistake in here?

Error report: https://gist.github.com/Sumith1896/c12b34cf09545035a48f

Does your latest commit work?

that is passing

This error would not have been when add_poly was using RCP arguments

I am doing a mistake with passing of variables, I need to figure it out.

Oh wait, you have used it.

Did you make any changes to

`add_poly`

?
If I had made any changes or not

No I haven't. You should still try though, something might have crept in.

Try using

`const Polynomial poly1(str, std::move(dict));`

tests pass

How do I even test the whole dict?

If you notice the test_add_poly(), it has

```
assert(c->degree == 2);
assert(c->var_ == "x");
```

I also want test for

`c->dict_`

I'd rather suggest getting the printer ready and testing the output

So should I get in my current

`test_add_poly()`

or keep it pending?
You can push the tests after adiing printer

iirc dict.cpp already has a printing function I believe, can be used for testing purposes atleast

Any other thing you want to discuss about the class?

I think we can discuss the changes as you push

Thanks, that's it for now I think.

Do you know if we are enforcing immutability with objects in symengine?

Also there's a line in

`cwrapper.h`

`typedef basic_struct basic[1];`

And further we have referred to as

`basic`

. Not sure how this works. Is this a pointer to `basic_struct`

? If yes we could have used`typedef basic_struct* basic;`

@abinashmeher999, that's a trick from gmp library to pass by reference in C.

@Sumith1896 @shivamvats since you are introducing a new data structure called

For example,

`map_uint_mpz`

you should introduce a function to check for equality and to compare.For example,

`map_basic_basic`

has a method to check equality, `map_basic_basic_eq`

and a method to compare `map_basic_basic_compare`

I have noticed that only maps with Basic involved have these methods.

Hence I didn't implement when I introduced the map_unit_mpz.

If you are going to use them in different places (

`__eq__`

method, tests, etc.) then you should have one function to do it
@isuruf I still don't get this. Can you direct me somewhere?

If that is the case will this work

`basic result = (basic)malloc(sizeof(basic_struct));`

yes, it should work, but you shouldn't allocate on the heap like that.

```
basic result;
basic_init(result);
```

is the recommended way

@isuruf the situation is somewhat like this

```
static VALUE cbasic_add(VALUE self, VALUE operand2){
basic this, basic_operand2;
basic result = (basic)malloc(sizeof(basic_struct));//here I am allocating on the heap
basic_init(result);
Data_Get_Struct(self, basic_struct, this);
Data_Get_Struct(operand2, basic_struct, basic_operand2);
basic_add(result, this, basic_operand2);
return Data_Make_Struct(self, basic_struct, rb_gc_mark, cbasic_release, result);
}
```

I am wrapping `result`

with ruby C API. We want the pointer to be valid outside the function. In that case I will need the pointer to be allocated on the heap. Or is there some similar workaroud?

I'm not sure. You'll have to work with the

`basic_struct`

. If you have time, take a look at the gmp ruby gem, `https://github.com/srawlins/gmp/blob/master/ext/ruby_gmp.h`

I have come across that earlier, but I haven't delved deeper into the structure. I will go through it. Thanks!

In GMP,

`mpz_t`

is an array of 1 `MP_INT`

struct. They have used the struct `MP_INT`

everywhere.
Thanks @isuruf ! :smiley: Now I know what to look for.