Defining functions over symbolic domains
Is there a way to define a function that takes a value (say $x$) on the interval $[-L, L]$ and is zero everywhere else? I tried the following code but it doesn't work. It gives me an error. This is because piecewise only accepts real intervals. Is there an alternative way of defining this? I want to be able to integrate/differentiate such types of functions so my understanding is that I also cannot use def here.
L = var('L', domain = 'positive')
f = piecewise([((-oo, -L), 0), ([-L, L], x), ((L, oo), 0)])