Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!newsfeed.internetmci.com!news.mel.aone.net.au!inferno.mpx.com.au!news.unimelb.EDU.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Help: subsumption test
Message-ID: <9523923.5700@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <199508200506.WAA03041@usc.edu> <9523617.26004@mulga.cs.mu.OZ.AU>
Date: Sun, 27 Aug 1995 13:05:56 GMT
Lines: 30

While we're on the topic of different methods of doing subsumption checking,
here's a Mercury version of subsumes/2.  This uses the type `term'
defined in one of the Mercury standard library modules, which is a
ground representation.  It doesn't suffer from any of the usual
problems of non-ground representations or number_vars as alluded to
in the code Lee Naish posted.  Unlike the Prolog solutions, it doesn't
use any non-logical features such as cut, unsound negation, var/1, etc.

:- module subsumption.
:- interface.
:- import_module term.

:- pred subsumes(term::in, term::in) is semidet.
	% subsumes(A, B) is true iff A subsumes B.

:- implementation.
:- import_module map.

	% unify A and B, and then check that the resulting
	% substitution does not bind any of the variables in A.
subsumes(A, B) :-
	map__init(EmptySubstitution),
	term__unify(A, B, EmptySubstitution, Substitution),
	not (term__contains_var(A, Var), map__contains(Substitution, Var)).

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh@cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F
