 (defmulti make-context
   "Standard constructor for contexts. Takes a sequence of objects,
   a sequence of attributes and either a set of pairs or function of
-  two elements being true iff its arguments are incident. Note that the
-  object and attribute sequences are converted to sets and therefore have to
-  not contain any douplicate elements."
+  two elements being true iff its arguments are incident. Note that
+  the object and attribute sequences are converted to sets and
+  therefore have to not contain any douplicate elements. The incidence
+  relation is auzomatically restricted to the cartesian product of the
+  object an the attribute set."
   (fn [& args] (map type-of args)))
 
 (defmethod make-context [::set ::set ::set] [objects attributes incidence]
-  (conexp.fca.Context. (set objects) (set attributes) (set incidence)))
+  (let [objs (set objects)
+	atts (set attributes)
+	inz  (set-of [g m] [[g m] incidence
+			    :when (and (contains? objs g)
+				       (contains? atts m))])]
+    (conexp.fca.Context. objs atts inz)))
 
 (defmethod make-context [::set ::set ::fn] [objects attributes incidence]
   (make-context objects attributes (set-of [x y] [x objects

  "Clarifies objects in context ctx."
  [ctx]
  (let [prime (memoize (partial object-derivation ctx))
	new-objs (set (distinct-by-key (objects ctx) #(prime #{%})))
	new-inz (set-of [g m] [[g m] (incidence ctx)
			       :when (contains? new-objs g)])]
    (make-context new-objs (attributes ctx) new-inz)))

(defn clarify-attributes
  "Clarifies attributes in context ctx."
  [ctx]
  (let [prime (memoize (partial attribute-derivation ctx))
	new-atts (set (distinct-by-key (attributes ctx) #(prime #{%})))
	new-inz (set-of [g m] [[g m] (incidence ctx)
			       :when (contains? new-atts m)])]
    (make-context (objects ctx) new-atts new-inz)))

(defn clarify-context
  "Clarifies context ctx."

(defn reduce-clarified-context
  "Reduces context ctx assuming it is clarified."
  [ctx]
  (let [uda (up-down-arrows ctx)
	new-obj (set (map first uda))
	new-att (set (map second uda))]
    (make-context new-obj new-att (incidence ctx))))

(defn reduce-context
  "Reduces context ctx."
