Hi Pierre,

On Sun, Jul 26, 2009 at 5:31 AM, pca<[email protected]> wrote:
>
> Dear all,
>
> I have been puzzled, and annoyed, by an unexpected side-effect.  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 !
> print d_(constants) #--> 6 : the side-effect 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 side-effect 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.

Is the following what you're looking for?

----------------------------------------------------------------------
| Sage Version 4.1, Release Date: 2009-07-09                         |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: var("v, d, t");
sage: equation = v == d/t
sage: solution = solve(equation, d, solution_dict=True)
sage: solution
[{d: t*v}]
sage: sol_d = solution[0][d]; sol_d
t*v
sage: sol_d.substitute(v=2)
2*t
sage: sol_d.substitute(t=3)
3*v
sage: sol_d.substitute(t=3, v=2)
6
sage: sol_d
t*v

-- 
Regards
Minh Van Nguyen

--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to