Note that there are some explanatory texts on larger screens.

plurals
  1. POPartial functions versus under-specified total functions
    primarykey
    data
    text
    <p>Suppose I have a set <code>A ⊆ nat</code>. I want to model in Isabelle a function <code>f : A ⇒ Y</code>. I could use either:</p> <ol> <li>a partial function, i.e. one of type <code>nat ⇒ Y option</code>, or </li> <li>a total function, i.e. one of type <code>nat ⇒ Y</code> that is unspecified for inputs not in <code>A</code>.</li> </ol> <p>I wonder which is the 'better' option. I see a couple of factors:</p> <ul> <li><p>The "partial function" approach is better because it is easier to compare partial functions for equality. That is, if I want to see if <code>f</code> is equal to another function, <code>g : A ⇒ Y</code>, then I just say <code>f = g</code>. To compare under-specified total functions <code>f</code> and <code>g</code>, I would have to say <code>∀x ∈ A. f x = g x</code>. </p></li> <li><p>The "under-specified total function" approach is better because I don't have to faff with the constructing/deconstructing <code>option</code> types all the time. For instance, if <code>f</code> is an under-specified total function, and <code>x ∈ A</code>, then I can just say <code>f x</code>, but if <code>f</code> is a partial function I would have to say <code>(the ∘ f) x</code>. For another instance, it's trickier to do function composition on partial functions than on total functions.</p></li> </ul> <p>For a concrete instance relevant to this question, consider the following attempt at formalising simple graphs.</p> <pre><code>type_synonym node = nat record 'a graph = V :: "node set" E :: "(node × node) set" label :: "node ⇒ 'a" </code></pre> <p>A graph comprises a set of nodes, an edge relation between them, and a <code>label</code> for each node. We only care about the label of nodes that are in <code>V</code>. So, should <code>label</code> be a partial function <code>node ⇒ 'a option</code> with <code>dom label = V</code>, or should it just be a total function that is unspecified outside of <code>V</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload