Suppose I have two functions f and g defined on a mesh, such as in the following code fragment.
mesh = UnitSquareMesh(20, 20)
V = FunctionSpace(mesh, 'Lagrange', 1)
f = interpolate(Expression('x[0]+x[1]'), V)
g = interpolate(Expression('x[0]*x[1]'), V)
How can I define a function on the mesh that takes the values of f on the subdomain [0,0.5]x[0,1] and the values of g on the rest of the domain? I want to be able to do this without returning to the original expressions used to define f and g, but to only use f and g directly.