So I'd like to define a function (we'll call it applied
) that would get rid of all occurrences of a sub-multiset within another multiset and replace each occurrence with a single element. For example,
applied {#a,a,c,a,a,c#} ({#a,a,c#}, f) = {#f,f#}
So at first I tried a definition:
definition applied :: "['a multiset, ('a multiset × 'a)] ? 'a multiset" where
"applied ms t = (if (fst t) ?# ms then plus (ms - (fst t)) {#snd t#} else ms)"
However, I quickly realised that this would only remove one occurrence of the subset. So if we went by the previous example, we would have
applied {#a,a,c,a,a,c#} ({#a,a,c#}, f) = {#f,a,a,c#}
which is not ideal.
I then tried using a function (I initially tried primrec, and fun, but the former didn't like the structure of the inputs and fun couldn't prove that the function terminates.)
function applied :: "['a multiset, ('a multiset × 'a)] ? 'a multiset" where
"applied ms t = (if (fst t) ?# ms then applied (plus (ms - (fst t)) {#snd t#}) t else ms)"
by auto
termination by (*Not sure what to put here...*)
Unfortunately, I can't seem to prove the termination of this function. I've tried using "termination", auto, fastforce, force, etc and even sledgehammer but I can't seem to find a proof for this function to work.
Could I please have some help with this problem?
question from:
https://stackoverflow.com/questions/66057437/how-can-i-remove-all-occurrences-of-a-sub-multiset-in-isabelle