#11776: Holding an expression unevaluated: Something like hold_all() would be 
nice.
---------------------------+------------------------------------------------
   Reporter:  Pap          |          Owner:  jason     
       Type:  enhancement  |         Status:  new       
   Priority:  minor        |      Milestone:  sage-4.7.2
  Component:  misc         |       Keywords:            
Work_issues:               |       Upstream:  N/A       
   Reviewer:               |         Author:            
     Merged:               |   Dependencies:            
---------------------------+------------------------------------------------

Comment(by Pap):

 Replying to [comment:1 nbruin]:

 > Given that `expression` is already evaluated (leading to a simplified
 expression) before `hold_all` even gets a hold of it, this approach is a
 little problematic.

 I know, that's why I suggested a different approach in the end of the Sage
 worksheet I posted (http://test.sagenb.org/home/pub/6). Something like

 {{{
 unevaluated_expr=hold_all( integrate(x^2+1,x) + diff(tan(x),x) )
 }}}
 then a command to evaluate it, if needed, say

 {{{
 evaluated_expr=evaluate(unevaluated_expr)

 }}}
 So one could pretty print the unevaluated expression, together with the
 the evaluated one with

 {{{
 join(["$",unevaluated_expr,"=",evaluated_expr,"$"])

 }}}
 Note that such a functionality is pretty much standard in many Computer
 Algebra systems. Maxima, for example, suspends evaluation if an expression
 is preceded by a single quote, and has a very convenient function called
 `ev()` to evaluate the expression (or even parts of it) later on, so one
 could use

 {{{
 unevaluated_expr : '( integrate(x^2+1,x) + diff(tan(x),x) )
 evaluated_expr : ev(unevaluated_expr)
 print(unevaluated_expr,"=",evaluated_expr)
 }}}
 where everything inside `'(...)` is not evaluated. The same thing can be
 done in Mathematica and even yacas. I was actually surprised Sage doesn't
 have an easy way to do the same.

 > The basic feature is already available, but perhaps not very convenient
 for your taste. See `sin(pi,hold=True)`. Currently this isn't available
 for integrals etc., but there is
 `sage.calculus.calculus.dummy_integrate(x^2+1,x)` It is very reasonable to
 ask for `integrate(x^2+1,x,hold=True)` to be synonymous with that.

 Well, the very basic feature is already available, indeed, but not for
 every function and not in a way one could call "convenient". Furthermore,
 `integrate()` was just an example. I didn't know about the package
 `dummy_integrate` (and I have no means to know which functions accept
 `hold=True` and which don't). But anyway, it only solves the issue for
 that particular (and very simple) example. I am thinking of something more
 general and more powerful.

 > You can already do` def held(f): return lambda *args: f(*args,hold=True)
 sin=held(sin) cos=held(cos) sin(pi)^2+cos(pi)^2 ` one could have a package
 inert_symbolic_functions that has (essentially) those declarations, so
 that a ` from held_symbolic_functions import * ` would give you a "held"
 environment. With a little namespace injection magic one could probably
 also use that to implement ` with held_function_context:
 expr=sin(pi)^2+cos(pi)^2 ` which is probably the closest to what you
 request, subject to being doable in python.

 Well, doable, but sounds like reinventing the wheel, in my humble
 opinion. Not to mention it works only for functions that accept
 `hold=True`, and I have no idea how I will suspend evaluation of operators
 that way.

 Given the fact that Sage makes heavy use of LaTeX's power to typeset
 expressions perfectly (while Maxima or Mathematica either don't use LaTeX,
 or use it only with the aid of external programs), it is a pity we can't
 use that power to create educational worksheets, pretty much like books,
 where printing an expression unevaluated together with the corresponding
 evaluated one is a must. It is actually one of the first things I try to
 do as a test in every CAS I am learning.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11776#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" 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/sage-trac?hl=en.

Reply via email to