I have the following code:
ghost function U<T> (S : set<set>) : set
{
if S == {} then {}
else var s := pick (S) ;
U (S - {s}) + s
}
ghost function pick<T> (s : set) : T
requires s != {}
{var x :| x in s ; x}
But cannot manage to give a suitable body to
lemma singletonsU<T> (s : set)
ensures s == U (set x <- s :: {x})
In particular when trying induction I seem to need using the function pick again and this might give a result different from the one obtained when invoking U.
You are correct, that is something you should be concerned with. Check out the essay "Functions over Set Elements" here for an example of how to deal with that situation. https://leino.science/dafny-power-user/