These are chat archives for symengine/symengine

7th
Jul 2016
Srajan Garg
@srajangarg
Jul 07 2016 09:40

@isuruf
This is the kind of structure I'm thinking of right now
First approach :

template<typename T>
struct SymEnginePoly
{
    T f() { return x; }
};

struct IntPoly
{
    int x;
    virtual int f() = 0;
};

struct DoulePoly
{
    double x;
    virtual double f() = 0;
};

struct SymIntPoly : public IntPoly, public SymEnginePoly<int>
{
};

But this won't work obviously
What can I do to achieve this^ (I'm not familiar with multiple inheritance)
One class has the members, and definitions. Other class has all the implementations of those functions.

Second approach :

template<typename T>
struct TPoly
{    
    T x;
    virtual T f() = 0;
};

template<typename T>
struct SymEnginePoly : public TPoly<T>
{
    T f() { return this->x; }
};

struct SymIntPoly : public SymEnginePoly<int>
{
};

Here the TPoly class resebles some sort of UNonExprPoly class
I want to work with the first approach, because then Rat and Int polys are allowed to have different properties/methods

Srajan Garg
@srajangarg
Jul 07 2016 10:09
The first approach also makes sense, because then expr polys can be just struct UExprPoly : public SymEnginePoly<Expr>, (EDIT : or struct UExprPoly : public ExprPoly, public SymEnginePoly<Expr> if that is later needed) which is not possible in the second case (because all int and rat specific methods will exist in TPoly, and can't be inherited by expr polys)
Srajan Garg
@srajangarg
Jul 07 2016 10:30
How does this look (third approach) :
template<typename Poly>
struct SymEnginePoly
{
    using T = typename Poly::coef;
    T f() { return this->x; }
};

struct IntPoly
{
    int x;
    typedef int coef;
    virtual int f() = 0;
};

struct DoulePoly
{
    double x;
    typedef double coef;
    virtual double f() = 0;
};

struct SymIntPoly : public IntPoly, public SymEnginePoly<IntPoly>
{
};
The second approach may seem better intitally, because UIntPolyBase and URatPolyBase are essentially going to have the same methods(signatures) in them (as of yet), which may feel tempting to templatize. But I feel this^ is the way to go
Isuru Fernando
@isuruf
Jul 07 2016 10:35
Where is UPolyBase and UIntPolyBase ?
Srajan Garg
@srajangarg
Jul 07 2016 10:36
UExprPolyBase will have to be made
Isuru Fernando
@isuruf
Jul 07 2016 10:36
Sorry. edited
Srajan Garg
@srajangarg
Jul 07 2016 10:37
Yes, so in the above example, IntPoly is actually UIntPolyBase : public UPolyBase
Just simplified
DoublePoly si similarly URatPolyBase : public UPolyBase
And now, a particular polynomial class will decide, wether it is Int/Rat? and what Implementation to use Sym/Pir/Flint
Like SymIntPoly
Isuru Fernando
@isuruf
Jul 07 2016 10:40
SymIntPoly : public IntPoly, public SymEnginePoly<IntPoly> looks good
let me know when you have an implementation
Srajan Garg
@srajangarg
Jul 07 2016 10:45
However, I'm still a little doubtful about wether URatPolyBase and UIntPolyBase should be different? (or just be a same template)
I can't think of any different functionalities in these two types of polys

I'm contradiciting my earlier statement though

The second approach may seem better intitally, because UIntPolyBase and URatPolyBase are essentially going to have the same methods(signatures) in them (as of yet), which may feel tempting to templatize. But I feel this^ is the way to go

So, it will be like SymIntPoly : public NonExprPolyBase<int/rat>, public SymEnginePoly<int/rat>
Isuru Fernando
@isuruf
Jul 07 2016 10:52
I think it's better to have two classes but you can have a common base for both
Srajan Garg
@srajangarg
Jul 07 2016 10:55
I see, best of both
Thanks
Abhinav Agarwal
@abhinavagarwal07
Jul 07 2016 11:07
@isuruf do we include symbench in talk ?