doit is a pretty standard way to implement this pattern. You can make
it work by implementing _eval_doit. expand is also OK (just implement
_eval_expand_hint for whatever hint name makes sense, see the
docstring of expand().

Aaron Meurer

On Wed, Sep 10, 2014 at 9:52 AM, Simon Hirscher <[email protected]> wrote:
> Hi,
>
> I'm working on an extension for sympy.diffgeom. Since expressions
> often get very complicated in differential geometry, it sometimes
> makes sense to e.g. simply keep a tensor as the indexed symbol it
> is, sometimes one inserts its actual components' values (and
> tries to simplify further). Put differently, my mathematical
> objects (mostly tensors) carry names but also have values and I'd
> like to let the user decide when he wants use what and enable him
> to replace names by their values later on (without the need for
> him to use replace()/subs() because this requires way too much
> manual effort).
>
> Basically, this is the analogy of the famous pitfall:
>
>>>> x, y = symbols('x, y')
>>>> y = x + 2
>>>> x = 2
>>>> y
> x + 2
>
> whereas I would actually like to provide a way to do exactly
> this: Replace the symbol 'x' by its value later on.
>
> (Obviously, this would allow lazy calculation of tensor
> components. Hence, the user could build expressions involving
> tensors without needing to calculate all of their components
> first – after all, he might only need some of them.)
>
> So: Are there any best practices in this regard or is there even
> a general function in SymPy to expand/evaluate such abstract
> symbols in terms of their (still abstract/non-numerical) values?
>
> I imagine something like this:
>
>>>> R[0, 1, 0, 1]
> R_{0101}
>>>> R[0, 1, 0, 1].expand() (or .eval()/.doit()/.compute() or something)
> <some complicated expression in terms of coordinate functions>
>
> Thank you for your time!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/878ulr1q9u.fsf%40simonhirscher.de.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2Bvkr7mjkfP8JE7uZNGBodupbeFaupNGGrAdC5kUV6zkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to