Re: Modifying the value of a float-like object

2009-05-01 Thread smichr
On May 1, 11:13 am, smichr wrote: > Also, this approach is limited in that only variables can be arguments > to functions, not node expressions. If x and d are variables, x/d > becomes an expression and you cannot compute sin(x/d). Or am I missing > something? > Note to self...it's best to restar

Re: Modifying the value of a float-like object

2009-04-30 Thread smichr
On Apr 18, 4:21 pm, eric.le.bi...@spectro.jussieu.fr wrote: > On Apr 15, 5:33 pm, Arnaud Delobelle wrote: > > I adjusted your code in a few ways, and put the result > athttp://code.activestate.com/recipes/576721/(with due credit): > > 1) There was a strange behavior, which is fixed (by performing

Re: Modifying the value of a float-like object

2009-04-24 Thread C or L Smith
I happened across the recent discussion and found it very interesting as I have been dusting off and trying to get ready a module that I had made that created a number class that handled numeric values and uncertainties in computations by computing (via overloaded operators) a new value and unce

Re: Modifying the value of a float-like object

2009-04-18 Thread Eric . Le . Bigot
On Apr 15, 5:33 pm, Arnaud Delobelle wrote: > I still don't think mutable floats are necessary.  Here is an approach > below - I'll let the code speak because I have to do some shopping! Hats off to you, Arnaud! I'm very impressed by the ideas found in your code. :) Your UExpr object is almost

Re: Modifying the value of a float-like object

2009-04-16 Thread Eric . Le . Bigot
Th^H^H On Apr 16, 5:51 am, a...@pythoncraft.com (Aahz) wrote: > In article <3b01d8f1-6a77-4374-b1c2-25bee7cdf...@x3g2000yqa.googlegroups.com>, > >   wrote: > > >Steven, I'd appreciate if you could refrain from criticizing so > >bluntly so many points.  I'd be great if you trusted me more for > >kn

Re: Modifying the value of a float-like object

2009-04-15 Thread Aahz
In article <3b01d8f1-6a77-4374-b1c2-25bee7cdf...@x3g2000yqa.googlegroups.com>, wrote: > >Steven, I'd appreciate if you could refrain from criticizing so >bluntly so many points. I'd be great if you trusted me more for >knowing what I'm talking about; I've been a programmer for 25 years, >now, an

Re: Re: Modifying the value of a float-like object

2009-04-15 Thread Dave Angel
Steven D'Aprano wrote: Oh nonsense. Many programming languages have mutable floats. That's irrelevant. Python doesn't. So introducing one will quite likely alter the OP's code's behavior. It doesn't matter if it's possible, it matters whether the existing code's behav

Re: Modifying the value of a float-like object

2009-04-15 Thread Dan Goodman
eric.le.bi...@spectro.jussieu.fr wrote: I initially tried to create a Float_ref class that inherits from numpy.array, so that objects of the new class behave like numpy.array in calculations, but also contain an "uncertainty" atribute, but this is apparently not allowed ("cannot create 'builtin_f

Re: Modifying the value of a float-like object

2009-04-15 Thread Suraj Barkale
spectro.jussieu.fr> writes: > > Hello, > > Is there a way to easily build an object that behaves exactly like a > float, but whose value can be changed? The goal is to maintain a list > [x, y,…] of these float-like objects, and to modify their value on the > fly (with something like x.value =

Re: Modifying the value of a float-like object

2009-04-15 Thread Arnaud Delobelle
eric.le.bi...@spectro.jussieu.fr writes: > Arnaud, your code is very interesting! > > On Apr 15, 1:00 pm, Arnaud Delobelle wrote: >> I still don't understand why you need mutable floats. > > Here is why: the code that your proposed (or any code that does > straightforward error propagation, for t

Re: Modifying the value of a float-like object

2009-04-15 Thread Piet van Oostrum
I think the term 'mutable float' is causing a lot of confusion. My solution I wouldn't call a mutable float, but a float container that tries to act like a float in a context where this is required. Another solution would have been to use automatically dereferencing pointers but that is something

Re: Modifying the value of a float-like object

2009-04-15 Thread Steven D'Aprano
On Wed, 15 Apr 2009 05:59:39 -0400, Dave Angel wrote: > Steven D'Aprano wrote: >> On Tue, 14 Apr 2009 14:45:47 -0400, Dave Angel wrote: >> >> >>> The answer to your original question is no. If the value can be >>> changed, then it doesn't behave like a float. And that's not just a >>> pedantic a

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
Thanks, Piet! Before reading your post, I did not know that defining __float__() was enough for math.sin() to be able to calculate something! To summarize my current understanding for the original problem: - Mutable floats seem to be the only way of performing (correct) uncertainty calculations

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
Arnaud, your code is very interesting! On Apr 15, 1:00 pm, Arnaud Delobelle wrote: > I still don't understand why you need mutable floats. Here is why: the code that your proposed (or any code that does straightforward error propagation, for that matter) does not generally calculate uncertaintie

Re: Modifying the value of a float-like object

2009-04-15 Thread Piet van Oostrum
> eric.le.bi...@spectro.jussieu.fr (ELB) wrote: >ELB> To Dave A. and Piet: I appreciate your taking the time to make >ELB> suggestions. I understand that there is a hitch in the approach that >ELB> you describe, which I would like to insist on: how do you handle >ELB> functions that use math.

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
It looks like Dan found what is in effect a mutable float (numpy.array). Now, with respect to the initial problem of having mutable floats that also contain an uncertainty attribute, I'd like to note that numpy.ndarray can be subclassed: it now looks possible to create a mutable float class that a

Re: Modifying the value of a float-like object

2009-04-15 Thread Arnaud Delobelle
eric.le.bi...@spectro.jussieu.fr writes: > As for your idea of "straight-forward interval arithmetic", it's a > good one, but I'd have to redefine lots of functions from the math > module, to use them explicitly in my code, etc.: this is heavy; I was > looking for a light-weight alternative, where

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
To Dave A. and Piet: I appreciate your taking the time to make suggestions. I understand that there is a hitch in the approach that you describe, which I would like to insist on: how do you handle functions that use math.sin(), for instance? numpy does this kind of magic, but I'm not sure it's wi

Re: Re: Modifying the value of a float-like object

2009-04-15 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 14 Apr 2009 14:45:47 -0400, Dave Angel wrote: The answer to your original question is no. If the value can be changed, then it doesn't behave like a float. And that's not just a pedantic answer, it's a serious consideration. Oh nonsense. Many programmi

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
Steven, I'd appreciate if you could refrain from criticizing so bluntly so many points. I'd be great if you trusted me more for knowing what I'm talking about; I've been a programmer for 25 years, now, and I pretty well know what my own code looks like! I appreciate your input, but please soften

Re: Modifying the value of a float-like object

2009-04-15 Thread Piet van Oostrum
> eric.le.bi...@spectro.jussieu.fr (ELB) wrote: [snip] >ELB> A couple of ideas I had: >ELB> 1) Define a FloatWithUncert object, but get instance values as x(), as >ELB> in "x()+y()". The code is relatively legible. 'x' is mutable. But >ELB> formulas don't look so good, and you can't drop

Re: Re: Modifying the value of a float-like object

2009-04-15 Thread Dave Angel
eric.le.bi...@spectro.jussieu.fr wrote: Thanks Dave for your thoughtful remarks, which you sent right when I was writing a response to the previous posts. I was wondering about a kind "mutable float"; so you're right, it's not fully a float, because it's mutable. I'd like to have an object that

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
Dan, wow! This looks extremely promising! I initially tried to create a Float_ref class that inherits from numpy.array, so that objects of the new class behave like numpy.array in calculations, but also contain an "uncertainty" atribute, but this is apparently not allowed ("cannot create 'builti

Re: Modifying the value of a float-like object

2009-04-15 Thread Steven D'Aprano
On Wed, 15 Apr 2009 01:05:33 -0700, Eric.Le.Bigot wrote: > Ben F., you're right on the money! You expressed exactly what I'm > looking for. Why should I want this? because the place in the code > where (foo, baz) is calculated has _no idea_ of what foo and baz are, of > where they were defined,

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
To Peter: What I had in mind was to implement your calc() function; you could do something similar with your loop in the previous post by replacing "for f.shift..." by "f.shift = 1"; this would give you 2 values, which you can combine with your unused variable in order to obtain the same value as w

Re: Modifying the value of a float-like object

2009-04-15 Thread Dan Goodman
eric.le.bi...@spectro.jussieu.fr wrote: Hello, Is there a way to easily build an object that behaves exactly like a float, but whose value can be changed? The goal is to maintain a list [x, y,…] of these float-like objects, and to modify their value on the fly (with something like x.value = 3.1

Re: Modifying the value of a float-like object

2009-04-15 Thread Eric . Le . Bigot
Ben F., you're right on the money! You expressed exactly what I'm looking for. Why should I want this? because the place in the code where (foo, baz) is calculated has _no idea_ of what foo and baz are, of where they were defined, etc.; on the other hand, the floatref class can keep track of the

Re: Modifying the value of a float-like object

2009-04-15 Thread Peter Otten
eric.le.bi...@spectro.jussieu.fr wrote: > Now, I would like to get the uncertainty on the result, even though we > have no idea of what quantities are used in lattice_spacing() for the > calculation (it can be attribute that are floats, attributes that are > FloatWithUncert, module globals defined

Re: Modifying the value of a float-like object

2009-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2009 12:36:02 -0700, Eric.Le.Bigot wrote: > I'll give more details, as David S. and David R. were asking for. The > code could look like this: > > import crystals > my_crystal = crystals.Crystal("Quartz 111") > > which would set some attributes of my_crystal as "floats with >

Re: Modifying the value of a float-like object

2009-04-14 Thread Ben Finney
Steven D'Aprano writes: > On Tue, 14 Apr 2009 06:03:58 -0700, Eric.Le.Bigot wrote: > > The goal is to maintain a list [x, y,…] of these float-like > > objects, and to modify their value on the fly (with something like > > x.value = 3.14) so that any expression like "x > > +y" uses the new value.

Re: Modifying the value of a float-like object

2009-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2009 06:03:58 -0700, Eric.Le.Bigot wrote: > Hello, > > Is there a way to easily build an object that behaves exactly like a > float, but whose value can be changed? Yes, have a look at the source code for UserString.MutableString for some ideas. > The goal is to maintain a list

Re: Modifying the value of a float-like object

2009-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2009 14:45:47 -0400, Dave Angel wrote: > The answer to your original question is no. If the value can be > changed, then it doesn't behave like a float. And that's not just a > pedantic answer, it's a serious consideration. Oh nonsense. Many programming languages have mutable flo

Re: Modifying the value of a float-like object

2009-04-14 Thread Eric . Le . Bigot
Thanks Dave for your thoughtful remarks, which you sent right when I was writing a response to the previous posts. I was wondering about a kind "mutable float"; so you're right, it's not fully a float, because it's mutable. I'd like to have an object that behaves like a float in numerical calcula

Re: Modifying the value of a float-like object

2009-04-14 Thread Eric . Le . Bigot
Thank you all for your input. It is not yet obvious how to achieve the goal/need that I had in mind in the original post. Basically, I would need to be able to calculate the derive() function of Peter, but without knowing what arguments are passed to the function f under study. Here is why: I'

Re: Re: Modifying the value of a float-like object

2009-04-14 Thread Dave Angel
eric.le.bi...@spectro.jussieu.fr wrote: It looks like what is needed here are a kind of "mutable float". Is there a simple way of creating such a type? I don't mind changing the value through x.value =.23 instead of x = 1.23... :) On Apr 14, 3:03 pm, eric.le.bi...@spectro.jussieu.fr wrote:

Re: Modifying the value of a float-like object

2009-04-14 Thread Peter Otten
eric.le.bi...@spectro.jussieu.fr wrote: > Alternatively, I'd be happy with a way of handling numerical > uncertainties in Python calculations (such as in "calculate the value > and uncertainty of a*sin(b) knowing that a=3.0 +/- 0.1 and b=1.00 +/- > 0.01"). Naive no warranties implementation: fr

Re: Modifying the value of a float-like object

2009-04-14 Thread MRAB
Christian Heimes wrote: eric.le.bi...@spectro.jussieu.fr wrote: Hello, Is there a way to easily build an object that behaves exactly like a float, but whose value can be changed? The goal is to maintain a list [x, y,…] of these float-like objects, and to modify their value on the fly (with som

Re: Modifying the value of a float-like object

2009-04-14 Thread Christian Heimes
eric.le.bi...@spectro.jussieu.fr wrote: > Hello, > > Is there a way to easily build an object that behaves exactly like a > float, but whose value can be changed? The goal is to maintain a list > [x, y,…] of these float-like objects, and to modify their value on the > fly (with something like x.v

Re: Modifying the value of a float-like object

2009-04-14 Thread David Smith
eric.le.bi...@spectro.jussieu.fr wrote: > It looks like what is needed here are a kind of "mutable float". Is > there a simple way of creating such a type? I don't mind changing the > value through x.value = 1.23 instead of x = 1.23... :) > > On Apr 14, 3:03 pm, eric.le.bi...@spectro.jussieu.fr

Re: Modifying the value of a float-like object

2009-04-14 Thread David Robinow
On Tue, Apr 14, 2009 at 9:03 AM, wrote: > Hello, > > Is there a way to easily build an object that behaves exactly like a > float, but whose value can be changed?  The goal is to maintain a list > [x, y,…] of these float-like objects, and to modify their value on the > fly (with something like x.

Re: Modifying the value of a float-like object

2009-04-14 Thread Eric . Le . Bigot
It looks like what is needed here are a kind of "mutable float". Is there a simple way of creating such a type? I don't mind changing the value through x.value = 1.23 instead of x = 1.23... :) On Apr 14, 3:03 pm, eric.le.bi...@spectro.jussieu.fr wrote: > Hello, > > Is there a way to easily build

Modifying the value of a float-like object

2009-04-14 Thread Eric . Le . Bigot
Hello, Is there a way to easily build an object that behaves exactly like a float, but whose value can be changed? The goal is to maintain a list [x, y,…] of these float-like objects, and to modify their value on the fly (with something like x.value = 3.14) so that any expression like "x +y" uses