Evaluating a symbolic expression for a Graph

asked 2013-02-14 07:50:33 -0500

patronics gravatar image

updated 2013-02-14 07:50:51 -0500

I'm able to do this:

sage: f = function('radius', nargs=1, evalf_func=Graph.radius)
sage: f(graphs.HouseGraph())

But not this:

sage: var('G')
sage: expr = f(G)
sage: expr.subs(G=graphs.HouseGraph())
TypeError: no canonical coercion from <class 'sage.graphs.graph.Graph'> to Symbolic Ring

What am I missing? Is it not possible to use symbolic expressions like this?

edit retag flag offensive close merge delete


The substitution is implemented in the stricter "sense of algebra". The instance expr is namely

sage: expr.__class__
<type 'sage.symbolic.expression.Expression'>

sage: expr

sage: expr.__dict__
<dictproxy {'__doc__': None,
 '__module__': 'sage.categories.commutative_rings',
 '_reduction': (<built-in function getattr>,
  (Category of commutative rings, 'element_class')),
 '_sage_src_lines_': <staticmethod object at 0x7f28c20399b8>}>

sage: expr.subs??

(Python allows better ways to call a known function on a known argument, and explicit is better then implicit. Why this contorsion by subs?)

dan_fulea gravatar imagedan_fulea ( 2017-03-29 15:23:16 -0500 )edit