Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hold context #10035

Closed
kcrisman opened this issue Sep 29, 2010 · 28 comments
Closed

Hold context #10035

kcrisman opened this issue Sep 29, 2010 · 28 comments

Comments

@kcrisman
Copy link
Member

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

Depends on #23820

CC: @burcin @eviatarbach

Component: symbolics

Author: Ralf Stephan

Branch/Commit: 3ad332c

Reviewer: Emmanuel Charpentier

Issue created by migration from https://trac.sagemath.org/ticket/10035

@jasongrout
Copy link
Member

comment:1

Can you give a code sample of what you mean?

@kcrisman
Copy link
Member Author

comment:2

Replying to @jasongrout:

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.

@burcin
Copy link

burcin commented Oct 1, 2010

comment:3

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

@jasongrout
Copy link
Member

comment:4

That would be awesome!

@jpflori
Copy link

jpflori commented Oct 5, 2010

comment:5

Replying to @jasongrout:

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

@kcrisman
Copy link
Member Author

kcrisman commented Sep 8, 2011

comment:6

#11776 seems to be asking for something very similar.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@kcrisman
Copy link
Member Author

comment:10

An interesting use case for this showed up at this tex.SX question.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@rwst
Copy link

rwst commented Dec 25, 2014

comment:13

Replying to @jpflori:

Replying to @jasongrout:

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.

@rwst
Copy link

rwst commented Jun 24, 2015

comment:14

See pynac/pynac#76

@rwst rwst modified the milestones: sage-6.4, sage-6.8 Jun 24, 2015
@rwst
Copy link

rwst commented Aug 30, 2017

comment:16

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

@rwst
Copy link

rwst commented Aug 30, 2017

comment:17

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.

@rwst
Copy link

rwst commented Aug 31, 2017

Branch: u/rws/create_hold_context

@rwst
Copy link

rwst commented Aug 31, 2017

Commit: 18b6c7a

@rwst
Copy link

rwst commented Aug 31, 2017

Dependencies: pynac-0.7.11

@rwst
Copy link

rwst commented Aug 31, 2017

Author: Ralf Stephan

@rwst
Copy link

rwst commented Aug 31, 2017

New commits:

18b6c7a10035: hold context

@rwst rwst modified the milestones: sage-6.8, sage-8.2 Aug 31, 2017
@kcrisman
Copy link
Member Author

comment:20

Ordinarily I'd just say well done and leave it at that. But what to do with the "old" hold stuff? Keep, deprecate, side-by-side - 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.

@rwst
Copy link

rwst commented Sep 1, 2017

comment:21

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 pynac-0.7.11 is merged.

@rwst
Copy link

rwst commented Sep 1, 2017

comment:22

Or even with context(x > 0, simplify):

@rwst
Copy link

rwst commented Sep 1, 2017

comment:23

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()

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 1, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

3ad332c10035: hold.start/stop

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 1, 2017

Changed commit from 18b6c7a to 3ad332c

@rwst
Copy link

rwst commented Sep 10, 2017

Changed dependencies from pynac-0.7.11 to #23820

@rwst

This comment has been minimized.

@rwst rwst changed the title Create hold context Hold context Sep 23, 2017
@rwst rwst modified the milestones: sage-8.2, sage-8.1 Sep 23, 2017
@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Oct 25, 2017

Reviewer: Emmanuel Charpentier

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Oct 25, 2017

comment:27

On top of 8.1beta9 + #24026 + #23990 + #23923 + #24088 + their dependencies running on Debian Testing on core i7 + 16 GB RAM, passes ptestlong with no error whatsoever.

==>positive_review

@rwst
Copy link

rwst commented Oct 26, 2017

comment:28

Thanks.

@vbraun
Copy link
Member

vbraun commented Oct 29, 2017

Changed branch from u/rws/create_hold_context to 3ad332c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants