If I try your example at home with sage-3.3, I obtain: sage: time dizSub=G_igr_d.subs(paramsd) CPU times: user 0.03 s, sys: 0.00 s, total: 0.03 s Wall time: 0.03 s sage: dizsub (0.00497512437811*s*(s + 1058537.10173)/(s*((s + 22.4212271973)*(s + 1058537.10173) + 127669181.574) - (606.060606061 - 1212.12121212*Duty)* (90909.0909091*Duty - 45454.5454545)*(s + 1058537.10173)) + 1053270.74799*s/(s*((s + 22.4212271973)*(s + 1058537.10173) + 127669181.574) - (606.060606061 - 1212.12121212*Duty)* (90909.0909091*Duty - 45454.5454545)*(s + 1058537.10173)))* (1212.12121212*Vb + 9.09090909091) - 90909.0909091*ILf* (0.00497512437811*(1212.12121212*Duty - 606.060606061)*(s + 1058537.10173)/(s*((s + 22.4212271973)*(s + 1058537.10173) + 127669181.574) - (606.060606061 - 1212.12121212*Duty)* (90909.0909091*Duty - 45454.5454545)*(s + 1058537.10173)) - 1053270.74799*(606.060606061 - 1212.12121212*Duty)/(s*((s + 22.4212271973)*(s + 1058537.10173) + 127669181.574) - (606.060606061 - 1212.12121212*Duty)*(90909.0909091*Duty - 45454.5454545)*(s + 1058537.10173)))
On Feb 24, 10:18 pm, Maurizio <maurizio.gran...@gmail.com> wrote: > excuse me guys, I didn't want to bother you with my long example (I > thought that could be a good idea to give something reproducible) , > but can you at least tell me some reason why in my case the subs with > the dictionary is so slow (especially with respect to the substitution > with equations)? > > thanks > > Maurizio > > On 23 Feb, 09:35, Maurizio <maurizio.gran...@gmail.com> wrote: > > > People, please let me understand this! Let me give you my example so > > that you can help me recognizing where is my mistake > > > I've this function: > > > G_igr_d ( <class 'sage.calculus.calculus.SymbolicArithmetic'> ) > > > (2*Iin*rCb/Lf + 2*Vb/Lf)*(s*rCf*(1/(Cf*rCf + Cf*Rs) + s)/((rCf + > > Rs)*(s*((1/(Cf*rCf + Cf*Rs) + s)*(2*rCf*rQ/(Lf*rCf + Lf*Rs) + > > 2*Rs*rQ/(Lf*rCf + Lf*Rs) + rCf*rLf/(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(Cf*rCf + Cf*Rs) + > > s))) - (1/Lf - 2*Duty/Lf)*Rs/((rCf + Rs)*(Cf*rCf + Cf*Rs)*(s*((1/ > > (Cf*rCf > > + Cf*Rs) + s)*(2*rCf*rQ/(Lf*rCf + Lf*Rs) + 2*Rs*rQ/(Lf*rCf + Lf*Rs) + > > rCf*rLf/(Lf*rCf + Lf*Rs) + Rs*rLf/(Lf*rCf + Lf*Rs) + > > 2*Iin*rCb*rCf/(Lf*rCf + Lf*Rs) + Rs*rCf/(Lf*rCf + Lf*Rs) + > > Rs*2*Iin*rCb/(Lf*rCf + Lf*Rs) + s) + Rs^2/((Cf*rCf + Cf*Rs)*(Lf*rCf + > > Lf*Rs))) - (2*Duty/Cb - 1/Cb)*(1/Lf - 2*Duty/Lf)*(1/(Cf*rCf + Cf*Rs) + > > s))))/Cb > > > and > > > params = [ > > rCf == 1*m_, Cf == 4.7*u_, > > rCb == 10*m_, Cb == 22*u_, > > rLf == 1*m_, Lf == 1.65*m_, > > rQ == 10*m_, > > Iin == 300/400, > > Rs == 0.2, > > Vrms == 220, > > Vgr_pk == 220*sqrt(2), > > ] > > > paramsd = { > > "rCf" : 1*m_, "Cf" :4.7*u_, > > "rCb" :10*m_, "Cb" :22*u_, > > "rLf" :1*m_, "Lf" :1.65*m_, > > "rQ" :10*m_, > > "Iin" :300/400, > > "Rs" :0.2, > > "Vrms" :220, > > "Vgr_pk" :220*sqrt(2), > > > } > > > NOTE: the m_, u_, etc. are just the multipliers previously defined in > > a .sage file (m_ = 1e-3, u_ = 1e-6, etc.) > > > They are exactly the same subset > > > If I do > > > time dizSub = G_igr_d.subs(paramsd) > > CPU time: 14.40 s, Wall time: 31.44 s > > > time G_id = subList(G_igr_d,params) > > CPU time: 1.17 s, Wall time: 5.59 s > > > Why is it so? Please note that this has been done with SAGE : 'SAGE > > Version 3.1.2, Release Date: 2008-09-19' > > > I've tried out this at home (but with simpler expressions) with the > > latest SAGE, and the subs with the dictionary actually was faster. > > > Thank you > > > Maurizio > > > On Feb 21, 4:48 pm, Robert Bradshaw <rober...@math.washington.edu> > > wrote: > > > > On Feb 21, 2009, at 3:30 AM, Maurizio wrote: > > > > > That was the way I used to do it when I discovered the solution_dict > > > > param. > > > > > So, I started using the dictionaries to do substitution even in > > > > complex expressions... The result was to wait so much time! > > > > > On the contrary, I found that the subs(expr, x=<value>) was SOOOO much > > > > faster (are the dictionaries so slow to deal with?). > > > > > So, I implemented a subList function, where I can pass an expression, > > > > and a list of substitution, in the very same way that the solve() > > > > function returns the results. > > > > > So, now I put all my subsets of numerical values in list like this: > > > > set = [x == 10, y == 20, z == 30, ...] > > > > and do the substitution like this: > > > > result = subList(expr, set) > > > > > Within the function, I just iterate the subs(expr, x = <value>) on the > > > > number of list elements. > > > > > This seems to me much faster than using dictionaries, especially for > > > > complex expressions. > > > > If this is the case, this is clearly a bug. > > > > - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---