Loading...

sagesupport@googlegroups.com
[Prev] Thread [Next]  [Prev] Date [Next]
[sagesupport] Re: sideeffect when evaluating a function William Stein Sat Jul 25 13:30:09 2009
On Sat, Jul 25, 2009 at 12:31 PM, pca<[EMAIL PROTECTED]> wrote: > > Dear all, > > I have been puzzled, and annoyed, by an unexpected sideeffect. It > can be demonstrated in the notebook by the following example. It > models the speed as distance / time, then solve for the distance, then > evaluate the distance with different arguments: > > var('v d t') > equation = v == d / t > solution = solve(equation, d, solution_dict = True) > d_ = solution[0][d]; print d_ #> t*v > constants= {v: 2} > print d_(constants, t=3) #> 6 > # BEWARE: the previous call has the side effect that t=3 in later > evaluation ! This is *definitely* a bug in Sage. I've made this trac #6622: http://trac.sagemath.org/sage_trac/ticket/6622 Here's how to workaround it (namely, put "dict(constants)" instead of "constants"): sage: var('v t') sage: f = v*t sage: s = {v: 2} sage: f(dict(s), t=3) 6 sage: s {v: 2} William > print d_(constants) #> 6 : the sideeffect is apparent here ! > print d_ #> t*v > > I would expect d_(constants) to result in t*2, but instead its using a > previous assignment of t to yield 6 ! > > I'm using Sage for an engineering pblm, and I find it useful to > separate constants from arguments. The side effect is thus annoying > to me: is there any other way to evaluate a function with constants > and arguments, without any sideeffect with the arguments ? I'm new > to this forum, so not sure if it has been raised before. Sorry if > there is an easy answer. > > Thanks in advance. > PC > > > >  William Stein Associate Professor of Mathematics University of Washington http://wstein.org ~~~~~~~~~ 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/sagesupport URLs: http://www.sagemath.org ~~~~~~~~~
 [sagesupport] sideeffect when evaluating a function pca 2009/07/25
 [sagesupport] Re: sideeffect when evaluating a function Minh Nguyen 2009/07/25
 [sagesupport] Re: sideeffect when evaluating a function pca 2009/07/25
 [sagesupport] Re: sideeffect when evaluating a function William Stein 2009/07/25 <=
 [sagesupport] Re: sideeffect when evaluating a function pca 2009/07/25