Robert Bradshaw wrote:
> 
> On Apr 1, 2008, at 11:59 PM, Jason Grout wrote:
>> Robert Bradshaw wrote:
>>> On Apr 1, 2008, at 9:15 PM, Jason Grout wrote:
>>>
>>>> I'm trying to add _fast_float_ functionality to SymbolicEquation
>>>> objects.  However, a perusal of the sage.ext.fast_eval.pyx file
>>>> seems to
>>>> indicate that the operations <, <=, ==, >=, >, and != are not
>>>> supported
>>>> by the fast_float machinery.  Is that correct?
>>> That is correct.
>>>
>>>> If so, how do I add
>>>> these operations?  If not, then how do I construct a FastDoubleFunc
>>>> object appropriately?
>>>>
>>>> Or, should I just use the python operators and call fast_float on
>>>> each side?
>>> The latter is what I would do--the result of evaluating a symbolic
>>> equation object is a boolean not a float so it would be kind of hard
>>> to hook into this mechanism anyways (well, one could represent True
>>> by one float and False by another, but I don't think that's a very
>>> clean solution).
>>
>> Sorry, Robert, I didn't see your message until just now (after all the
>> work was done).  If you want to veto the patch, I understand and  
>> I'll do
>> it the way you suggest.
>>
>> The use-case I had in mind called for getting 0 for false and 1 for
>> true, so that is how I implemented it (e.g., contour_plot(x<y,  
>> (x,-1,1),
>> (y,-1,1))).
>>
>> Still, it was fun to muck around in the fast_float file.  You're  
>> amazing!
> 
> Thanks.
> 
> I put a comment up on trac, but it boils down to
> 
> sage: f = (x == 1)
> sage: g = (1 == x)
> sage: bool(f+g)
> True
> sage: ff = f._fast_float_('x') + g._fast_float_('x')
> sage: ff(0)
> 0.0
> 
> but I think piecewise functions would be a good way to implement the  
> desired functionality.

What sort of interface do you see with piecewise functions and the 
_fast_float_ interface (i.e., what sort of opcodes?)

You bring up a good point about the clash between the current semantics 
of operations of symbolic equalities and my proposed fast_float 
extension.  Currently, operations operate on both sides of the equation 
if it makes sense (many times it doesn't make sense and an error is 
thrown!).

In the patch above, I think of a symbolic equation as a characteristic 
function (i.e., 1 where it is true, 0 where it is false).  This provides 
a very natural, short, and easy notation for such things:

x*(x<1) + (-x)*(x>3) means piecewise([[(-Infinity,1), x], [(1, 
Infinity), 0]]) + Piecewise([[(-Infinity, 3), 0], [(3, Infinity), -x]])

and

x*(x<1) + (-x)*(x^2>4) means -- well, I don't know how to express the 
constraint that x^2 > 4 using piecewise.

while:

x*(x<1) + (-x*y)*(x^2+y^2<1) -- I'm not sure even how to write this down 
using the two variables using piecewise.

Personally, it seems that the characteristic-function approach is more 
generally useful (and much nicer notationally) when calling 
_fast_float_.  Thoughts?


As a middle-ground, how about I implement a SymbolicFormula class that 
allows us to express logical combinations of SymbolicEquations.  The 
SymbolicFormula class, when multiplied under _fast_float_, will act as a 
characteristic function.

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to