Opened 12 years ago
Closed 5 years ago
#10035 closed enhancement (fixed)
Hold context
Reported by:  KarlDieter Crisman  Owned by:  Burcin Erocal 

Priority:  major  Milestone:  sage8.1 
Component:  symbolics  Keywords:  
Cc:  Burcin Erocal, Eviatar Bach  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 12 years ago by
comment:2 Changed 12 years ago by
Cc:  Burcin Erocal 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 12 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:5 followup: 13 Changed 12 years ago by
comment:7 Changed 9 years ago by
Cc:  Eviatar Bach added 

comment:8 Changed 9 years ago by
Milestone:  sage5.11 → sage5.12 

comment:9 Changed 9 years ago by
Milestone:  sage6.1 → sage6.2 

comment:10 Changed 9 years ago by
An interesting use case for this showed up at this tex.SX question.
comment:11 Changed 8 years ago by
Milestone:  sage6.2 → sage6.3 

comment:12 Changed 8 years ago by
Milestone:  sage6.3 → sage6.4 

comment:13 Changed 8 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:15 Changed 7 years ago by
Milestone:  sage6.4 → sage6.8 

Priority:  minor → major 
comment:16 Changed 5 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 5 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 5 years ago by
Branch:  → u/rws/create_hold_context 

comment:19 Changed 5 years ago by
Authors:  → Ralf Stephan 

Commit:  → 18b6c7ad1b34bca2d52834f19ce6863c477ee690 
Dependencies:  → pynac0.7.11 
Milestone:  sage6.8 → sage8.2 
New commits:
18b6c7a  10035: hold context

comment:20 Changed 5 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 5 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:23 Changed 5 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 5 years ago by
Commit:  18b6c7ad1b34bca2d52834f19ce6863c477ee690 → 3ad332c9baddebc3c438409d3abec69d3b1f118a 

Branch pushed to git repo; I updated commit sha1. New commits:
3ad332c  10035: hold.start/stop

comment:25 Changed 5 years ago by
Dependencies:  pynac0.7.11 → #23820 

comment:26 Changed 5 years ago by
Description:  modified (diff) 

Milestone:  sage8.2 → sage8.1 
Status:  new → needs_review 
Summary:  Create hold context → Hold context 
comment:27 Changed 5 years ago by
Reviewers:  → Emmanuel Charpentier 

Status:  needs_review → positive_review 
comment:29 Changed 5 years ago by
Branch:  u/rws/create_hold_context → 3ad332c9baddebc3c438409d3abec69d3b1f118a 

Resolution:  → fixed 
Status:  positive_review → closed 
Can you give a code sample of what you mean?