Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
On Fri, Jun 1, 2012 at 12:30 PM, Bharath M R wrote: > Hi, > I was trying to implement interval arithmetic using numpy for plotting. I > could not possibly find a way > to **round up** a floating point value. ie sin(<1, 1>) = <0.841, 0.842> > rounded to 3 decimals. I would like How about round dow

Re: [sympy] rounding up floating points.

2012-06-01 Thread Joachim Durchholz
Am 01.06.2012 09:25, schrieb Chris Smith: How about round down and then add your interval width? You'll add a rounding unit if the input value happens to be exact. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to

Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
On Fri, Jun 1, 2012 at 1:25 PM, Joachim Durchholz wrote: > Am 01.06.2012 09:25, schrieb Chris Smith: >> >> How about round down and then add your interval width? > > > You'll add a rounding unit if the input value happens to be exact. > Can the interval have zero width? If so then, yes, and b cou

Re: [sympy] rounding up floating points.

2012-06-01 Thread Joachim Durchholz
Am 01.06.2012 08:45, schrieb Bharath M R: Hi, I was trying to implement interval arithmetic using numpy for plotting. I could not possibly find a way to **round up** a floating point value. Use math.ceil. I.e. multiply with the scale factor, math.ceil, then divide again. > ie sin(<1, 1>) =<0.8

Re: [sympy] rounding up floating points.

2012-06-01 Thread Bharath M R
round does not necessarily round down. It rounds to the nearest floating point, which can be greater than the original floating point value and hence might introduce errors into lower bound of the interval. -- You received this message because you are subscribed to the Google Groups "sympy" g

Re: [sympy] rounding up floating points.

2012-06-01 Thread Bharath M R
> > On a tangent, for code that uses machine floats/doubles, do not round to > decimals, round to binary digits. > Otherwise, your interval bounds will be inaccurate due to rounding > issues between decimal and binary, making it useless to control > algorithmic inaccuracy. > Exactly my pro

Re: [sympy] rounding up floating points.

2012-06-01 Thread Joachim Durchholz
Am 01.06.2012 09:45, schrieb Chris Smith: On Fri, Jun 1, 2012 at 1:25 PM, Joachim Durchholz wrote: Am 01.06.2012 09:25, schrieb Chris Smith: How about round down and then add your interval width? You'll add a rounding unit if the input value happens to be exact. Can the interval have zer

Re: [sympy] rounding up floating points.

2012-06-01 Thread Aaron Meurer
I should point out that Bharath is using Numpy, so if anyone knows of a solution using that, that will work too. Aaron Meurer On Jun 1, 2012, at 2:01 AM, Joachim Durchholz wrote: > Am 01.06.2012 09:45, schrieb Chris Smith: >> On Fri, Jun 1, 2012 at 1:25 PM, Joachim Durchholz wrote: >>> Am 01.0

[sympy] Getting rid of String parameters for raises()

2012-06-01 Thread Joachim Durchholz
Hi all, I recently had a pull request added that allows people to use raises(ZeroDivisionError, lambda: 1/0) instead of raises(ZeroDivisionError, "1/0") The advantage is that it runs faster because the test code does not need a separate compiler run, and code analysis tools can see what fun

[sympy] Expansion of (x+y)**2 etc.

2012-06-01 Thread Saurabh Jha
Hi, I noticed that the expansions like (x+y)**2 etc. when evaluated do not return expanded form, like (x**2+ y**2 2*x*y) in sympy. Can someone please tell me if the issue is raised before and give me the link in the issues list as I am unable to find it in issue tracker. Thank you, -Saurabh Jha

Re: [sympy] rounding up floating points.

2012-06-01 Thread Joachim Durchholz
Am 01.06.2012 09:58, schrieb Bharath M R: Exactly my problem. Multiplying and using ceil might cause inaccuracy. Is it possible to round to the nearest floating point value, but rounding up. Something like `round`, but which always rounds up or rounds down. You seem to be assuming that round(n)

Re: [sympy] Expansion of (x+y)**2 etc.

2012-06-01 Thread Aaron Meurer
This is the intended behavior. If you want the expanded form, call expand() on the expression. Aaron Meurer On Jun 1, 2012, at 2:21 AM, Saurabh Jha wrote: > Hi, > > I noticed that the expansions like (x+y)**2 etc. when evaluated do not > return expanded form, like (x**2+ y**2 2*x*y) in sympy.

Re: [sympy] Getting rid of String parameters for raises()

2012-06-01 Thread Tom Bachmann
Hi, if it is consensus that the lambda: syntax should be preferred over strings (imho its ugly), then I'd say just make it a hard error [after fixing all existing instances, of course] - this way no new instances are introduced. Best, Tom On 01.06.2012 09:12, Joachim Durchholz wrote: Hi al

Re: [sympy] Getting rid of String parameters for raises()

2012-06-01 Thread Aaron Meurer
A warning is just as good as an exception to our test runner (i.e., neither should be raised while running the tests). So option B is not really an option. I don't really care what we do otherwise. raises() is private API, so we can do whatever we want with it. Aaron Meurer On Fri, Jun 1, 2012

Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
mpmath.libmp.libmpf has rounding and conversion tools Are you working with python floats? Will this work: def interval(f, dec): m = 10**dec ff = math.floor(f*m)/m if f == ff: return f, f return ff, ff+1/m -- You received this message because you are subscribed to the Google Groups "symp

Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
Or perhaps this is better: >>> def interval(x,n): ... m=10**-n ... i = int(x/m) # how many m in x? ... a = i*m ... if a == x: return x, x ... return (a, a+m) if x > 0 else (a, a-m) ... >>> interval(.37512,3) (0.375, 0.376) >>> interval(.375,3) (0.375, 0.375) -- You received this message bec

Re: [sympy] rounding up floating points.

2012-06-01 Thread krastanov.ste...@gmail.com
Not much better, however: array = np.ceil(1000*array)/1000 On 1 June 2012 08:45, Bharath M R wrote: > Hi, > I was trying to implement interval arithmetic using numpy for plotting. I > could not possibly find a way > to **round up** a floating point value. ie sin(<1, 1>) = <0.841, 0.842> > rounde

Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
On Fri, Jun 1, 2012 at 1:01 PM, krastanov.ste...@gmail.com wrote: > Not much better, however: > > array = np.ceil(1000*array)/1000 > > On 1 June 2012 08:45, Bharath M R wrote: >> Hi, >> I was trying to implement interval arithmetic using numpy for plotting. I >> could not possibly find a way >> t

Re: [sympy] rounding up floating points.

2012-06-01 Thread krastanov.ste...@gmail.com
My first example was using numpy (as Aaron asked) and uses the multiply/ceil/divide method as Joachim suggested. For doing plotting I doubt that higher accuracy is necessary. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send e

Re: [sympy] rounding up floating points.

2012-06-01 Thread Chris Smith
> My first example was using numpy (as Aaron asked) and uses the (Sorry. I didn't mean to direct the comment to you in particular, I was just adding to the thread.) -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to s

Re: [sympy] rounding up floating points.

2012-06-01 Thread krastanov.ste...@gmail.com
On 1 June 2012 17:24, Chris Smith wrote: >> My first example was using numpy (as Aaron asked) and uses the > > (Sorry. I didn't mean to direct the comment to you in particular, I > was just adding to the thread.) > :) Don't worry, I did not took it that way. I just noticed that Aaron was asking f

Re: [sympy] dict( list_of_Equalities ) should work?

2012-06-01 Thread Aaron Meurer
I thought this too, but the consensus was to make it not do it. For example, what would (x + y).subs(Eq(x, y)) return? See http://code.google.com/p/sympy/issues/detail?id=2677. Aaron Meurer On Wed, May 30, 2012 at 10:36 AM, krastanov.ste...@gmail.com wrote: > Do you agree? It would be useful fo

[sympy] Morphism Pretty Printing

2012-06-01 Thread Sergiu Ivanov
Hello, I have written my last exam in this exam session, so I am now fully concentrated upon my category theory module project [0]. I am currently creating the basic classes I will later need. Among these classes is the class Morphism. A morphism is, in its most abstract form, a named arrow fro

Re: [sympy] Morphism Pretty Printing

2012-06-01 Thread Aaron Meurer
On Jun 1, 2012, at 1:25 PM, Sergiu Ivanov wrote: > Hello, > > I have written my last exam in this exam session, so I am now fully > concentrated upon my category theory module project [0]. > > I am currently creating the basic classes I will later need. Among > these classes is the class Morphis

Re: [sympy] Morphism Pretty Printing

2012-06-01 Thread Sergiu Ivanov
On Fri, Jun 1, 2012 at 10:44 PM, Aaron Meurer wrote: > On Jun 1, 2012, at 1:25 PM, Sergiu Ivanov wrote: >> >> Do you think that a morphism called f from object A to object B should >> be represented as >> >>  Morphism(Object("A"), Object("B"), "f") >> >> where Object is the class representing obj

Re: [sympy] dict( list_of_Equalities ) should work?

2012-06-01 Thread krastanov.ste...@gmail.com
What about making Eq iterable? It will permit the use of zip on a list of Eq. On 1 June 2012 20:48, Aaron Meurer wrote: > I thought this too, but the consensus was to make it not do it.  For > example, what would (x + y).subs(Eq(x, y)) return? See > http://code.google.com/p/sympy/issues/detail?id

Re: [sympy] dict( list_of_Equalities ) should work?

2012-06-01 Thread krastanov.ste...@gmail.com
Never mind, you agreed not to do it on the issue page. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For m

Re: [sympy] dict( list_of_Equalities ) should work?

2012-06-01 Thread Aaron Meurer
What you need to consider is if Eq is really an iterable container or not. You can always convert it to one--or indeed, any Basic object into one--using .args. It's also straight forward enough to combine this with list comprehensions for functions like zip(). Personally, I don't think it is, but

Re: [sympy] rounding up floating points.

2012-06-01 Thread Bharath M R
I will use np.ceil and np.truncate to get it done. Hopefully it won't affect the plots. @smichr I wanted the lower bound to round down and the upper bound to round up. Something like this. sin<1, 1.1> = <0.841, 0.892> I think using the ceil and floor(np.truncate) is the best option. -- You recei

Re: [sympy] beautify error messages

2012-06-01 Thread Aaron Meurer
I agree. This is better suited for IPython. Otherwise, it's just going to be a constant race to use whatever method instead of just "raise Exception(...)". Also, if someone wants to catch a specific error by the message, it is probably easier if the message is all in one line by default (i.e., t