On Fri, Oct 31, 2008 at 6:39 AM, Brian Granger <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I am continuing some work that Ondrej and I started this week
> implementing quantum operators in sympy.  I am building a Dagger class
> that does the hermitian conjugate.  In the canonize method, the Dagger
> operator need to test what type of object has been passed to Dagger.
> From there it 1) either actually takes the dagger if it knows how or
> 2) just leaves Dagger unevaluated.  So, I need to test for various
> types of objects.
>
> The common way of testing the type of object you get in sympy is to
> use the attributes like is_number, is_real, etc.  But, I have two, no
> three problems with this:
>
> 1.  Only subclasses of Basic have these attributes.  Matrices (and any
> other immutable type) don't inherit from Basic and so they don't have
> all these attributes.

I agree with Brian here.  This "some objects are basic others are not"
design is confusing, unfortunately there are not many design docs
around so I don't know if this was intentional or not.

>
> 2.  There is no is_complex attribute in basic.  This brings up another
> ?: how are complex number represented in sympy?

The is_complex attribute comes from the assumptions, although this
seems to be broken.  You can simpify a built-in complex to play
around, in the example b.is_complex should be true:

In [1]: a = complex(3,2)

In [2]: a
Out[2]: (3+2j)

In [3]: type(a)
Out[3]: <type 'complex'>

In [4]: b = sympify(a)

In [5]: type(b)
Out[5]: <class 'sympy.core.add.Add'>

In [6]: b
Out[6]: 3 + 2*I

In [7]: b.is_complex

In [8]: b.args[1].args[1]
Out[8]: I

In [9]: type(b.args[1].args[1])
Out[9]: <class 'sympy.core.numbers.ImaginaryUnit'>

In [10]: i = b.args[1].args[1]

In [11]: i.is_complex
Out[11]: True


>
> 3.  For custom object types, like my operators, I have to add custom
> code to my Dagger class that does things like:
>
> if isinstance(QuantumOperator):
>   # take Dagger of operator
>
> Is this the best way of going about this?

Its the only way I know unless you add some new property
(is_QuantumOperator) to Basic.

-- Andy

>
> Cheers,
>
> Brian
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to