Here is an example from the `lts` branch computing the product of two 
functions
that have different ranges in each:

>>> p = Piecewise((a,abs(x-1)<1),(b,abs(x-2)<2),(c,True))*Piecewise((d,x>1
),(e,True))
>>> piecewise_fold(p)
Piecewise(
    (a*d, (x > 1) & (x < 2)), 
    (b*d, (x > 1) & (x < 4)), 
    (c*d, x > 1), 
    (a*e, Abs(x - 1) < 1), 
    (b*e, Abs(x - 2) < 2), 
    (c*e, True))
>>> _.integrate(x).diff(x)
Piecewise(
    (c*e, x <= 0), 
    (a*e, x <= 1), 
    (a*d, x <= 2), 
    (b*d, x <= 4), 
    (c*d, True))


[Note that value `b*e` does not appear in the final result because it has 
been determined to not appear because higher priority expression are 
defined on the range in which `b*e` is defined.]

I like the idea of range_function. Here are two ways it might be done:

>>> def range_function(x, *args):
...  return Piecewise(*[
...   (a[0], And(x>=a[1],x<=a[2])) for a in args])
...
>>> range_function(x, (a,1,2),(b,3,4),(c,0,6))
Piecewise((a, (x >= 1) & (x <= 2)), (b, (x >= 3) & (x <= 4)), (c, (x >= 0) & 
(x <= 6)))


>>> def interval_function(x, *args):
...  return Piecewise(*[
...   (a[0], a[1].contains(x)) for a in args])
...
>>> interval_function(x, (a,Interval(1,2)),(b,Interval.Lopen(0,4)))
Piecewise((a, (x >= 1) & (x <= 2)), (b, (x <= 4) & (x > 0)))


On Sunday, June 11, 2017 at 4:33:28 PM UTC-5, [email protected] wrote:
>
>
>
> On Wednesday, June 7, 2017 at 5:49:34 PM UTC-4, Aaron Meurer wrote:
>>
>>
>>
>> > 
>> > My thoughts on Piecewise is that it's trying to do too many things. 
>>  There's 
>> > a difference between representing a function whose form changes 
>> depending on 
>> > the value of its argument (in my case, t) and an answer that depends on 
>> > parameter values (a and b).  The latter distinction is best described 
>> with a 
>> > cases statement.  I.e., t is different from a and b. 
>>
>> I'm not sure I follow here. Are you suggesting to use a separate 
>> object. What would it look like? 
>>
>> I'm thinking of a "range" object (I wish the name "Piecewise" was still 
> available). Something like this:
>
> f = range_function([(f1,t1,t2),(f2,t3,t4),...],t)
>
> The first argument is a list of functions with the range of the arguments 
> for that function. The final argument is the variable.  The notation mimics 
> the integrate function. 
>
> I've written a partially completed convolution function for these range 
> functions.  Convolution requires knowing the range of each function.  But I 
> got stuck when I ran the example before whose answer depends on parameter 
> values.  That the answer depends on parameter values is the job for a 
> "cases" function (like the Latex cases function).
>
> The last step (which I haven't finished, but it's straightforward) is to 
> combine the outputs of the various convolutions into a range function.
>
> I haven't given much thought how to extend the range function to multiple 
> variables.  It's probably straightforward when the ranges are rectangles, 
> but maybe less for other shapes (e.g., circles).
>
>  
>

-- 
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/4a050b71-9821-4062-b107-1165192287d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to