Template for the subsort solution to non-totality of partial maps
The non-totality of map-apply on partial map M can be handled by
introducing a subsort, called Defined-Dom, for pairs <M x>
where (defined-at M x). map-apply is then restricted to
Defined-Dom subsort.
Note: This not the full spec for partial maps; it is
just enough to illustrate the Subsort solution to non-totality of
map-apply for partial maps.
spec MAP is
sorts Dom, Cod, Map, Defined-Dom
sort-axiom Defined-Dom = (Map, Dom) | defined-at?
%---------------------------------------------
% basic operations
op empty-map : Map
op map-shadow : Map, Dom, Cod -> Map
constructors {empty-map, map-shadow} construct Map
%---------------------------------------------
% derived concepts
op defined-at? : Map, Dom -> Boolean
definition map-defined-at?-def of defined-at? is
axiom (not (defined-at? empty-map x))
axiom (iff (defined-at? (map-shadow M x1 y) x2)
(or (equal x1 x2)
(defined-at? M x2)))
end-definition
op map-apply : Defined-Dom -> Cod
definition map-apply-def of map-apply is
axiom (implies (equal ((relax defined-at?) M-at-x)
<(map-shadow M x y) x>)
(equal (map-apply M-at-x) y))
end-definition
end-spec