I think the keys would have to be the conditions, not the expressions. One issue with this is that Piecewise((x, x < 1), (-x, x < 0)) is not the same as Piecewise((x, x < 0), (-x, x < 1)). The former evaluates to -1 at -1 and the latter evaluates to 1 at -1. In other words, a Piecewise in SymPy is really an ITE chain. See the lengthy discussion at https://code.google.com/p/sympy/issues/detail?id=2626 and https://github.com/sympy/sympy/pull/1009. Probably the most natural data structure then would be an OrderedDict.
Aaron Meurer On Tue, Oct 29, 2013 at 2:24 PM, F. B. <[email protected]> wrote: > How do you handle identical keys in dictionaries? > > > On Tuesday, October 29, 2013 8:53:59 PM UTC+1, Chris Smith wrote: >> >> Does anyone else think that the desmos graphing method of defining >> piecewise functions is worth emulating: they use a dictionary >> representation. This is very clean and more transparent than the current >> format: >> >> instead of >> >> >>> Piecewise( >> ... (3,x<0), >> ... (0,True)) >> >> we could allow >> >> >>> Piecewise({ >> ... 3:x<0, >> ... 0:True}) >> >> For compatibility we can still store it as tuples (or modify attribute >> functions so they give tuples) but allowing that alternate input might be >> nice. >> >> Note: desmos switches the expression/condition order so the key is the >> condition and the value the expression. >> /c > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
