Opened 11 years ago
Closed 4 years ago
#10035 closed enhancement (fixed)
Hold context
Reported by:  kcrisman  Owned by:  burcin 

Priority:  major  Milestone:  sage8.1 
Component:  symbolics  Keywords:  
Cc:  burcin, eviatarbach  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Emmanuel Charpentier 
Report Upstream:  N/A  Work issues:  
Branch:  3ad332c (Commits, GitHub, GitLab)  Commit:  3ad332c9baddebc3c438409d3abec69d3b1f118a 
Dependencies:  #23820  Stopgaps: 
Description (last modified by )
Now that Pynac will support 'hold' of symbolic expressions, like
sage: tan(pi/12,hold=True) tan(1/12*pi)
we might want a 'context' for this. The ticket enables the following:
sage: tan(1/12*pi) sqrt(3) + 2 sage: with hold: ....: tan(1/12*pi) ....: tan(1/12*pi) sage: with hold: ....: sin(0) ....: cos(0) ....: sin(0) cos(0) sage: hold.start() sage: sin(0) sin(0) sage: cos(0) cos(0) sage: hold.stop() sage: sin(0) 0
Change History (29)
comment:1 followup: ↓ 2 Changed 11 years ago by
comment:2 in reply to: ↑ 1 Changed 11 years ago by
 Cc burcin added
Replying to jason:
Can you give a code sample of what you mean?
No, because this is really a followup to another ticket. I'll cc: Burcin in, though he probably already gets it given the component. I imagine something like
sage: context('hold') # or whatever the usual syntax is for such things  Sage doesn't have any yet sage: a = tan(pi/12) sage: a tan(pi/12)
as opposed to evaluating it.
comment:3 Changed 11 years ago by
I was thinking of something like:
sage: with hold: ....: t = tan(pi/2) ....: sage: t tan(pi/12) sage: tan(pi/12) sqrt(3) + 2
comment:4 followup: ↓ 5 Changed 11 years ago by
That would be awesome!
comment:5 in reply to: ↑ 4 ; followup: ↓ 13 Changed 11 years ago by
comment:6 Changed 10 years ago by
#11776 seems to be asking for something very similar.
comment:7 Changed 9 years ago by
 Cc eviatarbach added
comment:8 Changed 8 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:9 Changed 8 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:10 Changed 8 years ago by
An interesting use case for this showed up at this tex.SX question.
comment:11 Changed 8 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:12 Changed 7 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:13 in reply to: ↑ 5 Changed 7 years ago by
Replying to jpflori:
Replying to jason:
That would be awesome!
But with such a construction it is not obvious how to simplify 't' without going through Maxima as suggested in #10034
sage: with hold: ....: t = tan(pi/2) ....: sage: t tan(pi/12) sage: t.eval() #or t.unhold() or whatever sqrt(3) + 2
You are going through Maxima because the simplify...
functions do this. So improve these by replacing Maxima. It has nothing to do with the question of a global hold context.
comment:14 Changed 7 years ago by
comment:15 Changed 7 years ago by
 Milestone changed from sage6.4 to sage6.8
 Priority changed from minor to major
comment:16 Changed 4 years ago by
The construction would look like:
sage: class hold_class: ....: def __enter__(self): print('entered') ....: def __exit__(self, *args): print('exited') ....: sage: hold = hold_class() sage: with hold: ....: x^2 ....: entered x^2 exited
comment:17 Changed 4 years ago by
So we can actually use a global state (e.g. a boolean hold state inside Pynac) and via the Python with
ensure that it is always set locally.
comment:18 Changed 4 years ago by
 Branch set to u/rws/create_hold_context
comment:19 Changed 4 years ago by
 Commit set to 18b6c7ad1b34bca2d52834f19ce6863c477ee690
 Dependencies set to pynac0.7.11
 Milestone changed from sage6.8 to sage8.2
New commits:
18b6c7a  10035: hold context

comment:20 Changed 4 years ago by
Ordinarily I'd just say well done and leave it at that. But what to do with the "old" hold stuff? Keep, deprecate, sidebyside  should we transform old examples into this one, not, leave that to another ticket that may or may not get attention ... I assume you have thoughts on this so this is just for the purposes of hearing them, I don't have a strong opinion other than that a decision would have to be made, this patch alone wouldn't suffice. THANK YOU for this.
comment:21 Changed 4 years ago by
I think the best strategy is to keep the old functionality but replace doctests in tutorials and introductory docstrings (another ticket). As there will be more such contexts a syntax for multiple settings like with context(hold, eval_fp, simplify):
seems best.
Please review this whenever pynac0.7.11 is merged.
comment:22 Changed 4 years ago by
Or even with context(x > 0, simplify):
comment:23 Changed 4 years ago by
Note however that the Python directive with
interactively acts on its content all at once. That is,
sage: with hold: ....: sin(0) ....: cos(0) ....: sin(0) cos(0)
Maybe we should provide start()/stop()
so people can do
sage: mycontext1 = context(...) sage: mycontext2 = context(...) sage: with mycontext1: ........ sage: mycontext2.start() ... sage: mycontext2.stop()
comment:24 Changed 4 years ago by
 Commit changed from 18b6c7ad1b34bca2d52834f19ce6863c477ee690 to 3ad332c9baddebc3c438409d3abec69d3b1f118a
Branch pushed to git repo; I updated commit sha1. New commits:
3ad332c  10035: hold.start/stop

comment:25 Changed 4 years ago by
 Dependencies changed from pynac0.7.11 to #23820
comment:26 Changed 4 years ago by
 Description modified (diff)
 Milestone changed from sage8.2 to sage8.1
 Status changed from new to needs_review
 Summary changed from Create hold context to Hold context
comment:27 Changed 4 years ago by
 Reviewers set to Emmanuel Charpentier
 Status changed from needs_review to positive_review
comment:28 Changed 4 years ago by
Thanks.
comment:29 Changed 4 years ago by
 Branch changed from u/rws/create_hold_context to 3ad332c9baddebc3c438409d3abec69d3b1f118a
 Resolution set to fixed
 Status changed from positive_review to closed
Can you give a code sample of what you mean?