On Apr 2, 2008, at 12:05 PM, Jason Grout wrote: > Robert Bradshaw wrote: >> >> 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?)
Actually, given more thought, I think the opcodes you have chosen make sense, but there should be an "IF" opcode that operates on [true_val false_val test_val] as well which would allow for a full range of piecewise functions. (One could look at making conditional jumps so as to not calculate both sides of the expression, though this would be a fundamental change to the code. Hmm...) > 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? In Sage 3*(x<1) becomes 3x < 3. One can argue whether or not this is a good thing (I think it is) but it shows how symbolic equations are distinct objects from symbolic expressions. I'm not thinking of piecewise functions as being limited by what the Piecewise class can do. (I'm sure there's a better name for it, but it's evading me for the moment. Basically, I'm thinking the condition is an arbitrary equation, and there is an expression for each truth value.) Basically the ternary operation. > 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. I like this idea a lot, though I'm not sure "SymbolicFormula" is the best name for it. Perhaps "SymbolicCondition?" One could construct such things using && and ||, and it could short-circuit on evaluation. The output would be a boolean, which of course turns into a 1 or 0 when float(...) is called. - Robert --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---