jueves, 12 de septiembre de 2013

PowerLoom 1

Código PL de relaciones familiares:
(in-package "STELLA")

(defmodule "PL-KERNEL/PL-USER/FAMILIA")

(in-module "FAMILIA")

(clear-module "FAMILIA")

(in-dialect :KIF)

(defconcept Person)

(defconcept Male (?m Person)
:<=>(not (Female ?m)))

(defconcept Female (?f Person)
:<=>(not (Male ?f)))

(defrelation Spouse-of ((?spouse1 Person) (?spouse2 Person)))

(assert (forall (?x ?y) (<=> (Spouse-of ?y ?x) (Spouse-of ?x ?y))))
(assert (forall (?x ?y) (<=>(exists ?c (and (Parent-of ?x ?c) (Parent-of ?y ?c))) (Spouse-of ?x ?y))))

(defrelation Parent-of ((?p1 Person) (?p2 Person))
:<=> (not (= ?p1 ?p2)))

(defrelation Child-of ((?p1 Person) (?p2 Person))
:<=> (Parent-of ?p2 ?p1))

(defrelation Son-of ((?p1 Person) (?p2 Person))
:<=> (and (Child-of ?p1 ?p2) (Male ?p1)))

(defrelation Daughter-of ((?p1 Person) (?p2 Person))
:<=> (and (Child-of ?p1 ?p2) (Female ?p1)))

(defrelation Mother-of ((?m Person) (?c Person))
:<=> (and (Female ?m) (Parent-of ?m ?c)))

(defrelation Father-of ((?h Person) (?c Person))
:<=> (and (Male ?h) (Parent-of ?h ?c)))

(defrelation Husband-of ((?h Person) (?w Person))
:<=> (and (Male ?h) (Spouse-of ?h ?w)))

(defrelation Wife-of ((?w Person) (?h Person))
:<=> (and (Female ?w) (Spouse-of ?w ?h)))

(defrelation Grandparent-of ((?g Person) (?c Person))
:<=> (exists ?p (and (Parent-of ?g ?p) (Parent-of ?p ?c))))

(defrelation Granny-of ((?m Person) (?c Person))
:<=> (and (Female ?m) (Grandparent-of ?m ?c)))

(defrelation Grandpa-of ((?h Person) (?c Person))
:<=> (and (Male ?h) (Grandparent-of ?h ?c)))

(defrelation Sibling-of ((?x Person) (?y Person))
:<=> (and (exists ?p (and (Parent-of ?p ?x) (Parent-of ?p ?y) (not (= ?x ?y))))))

(defrelation Brother-of ((?h Person) (?c Person))
:<=> (and (Male ?h) (Sibling-of ?h ?c)))

(defrelation Sister-of ((?m Person) (?c Person))
:<=> (and (Female ?m) (Sibling-of ?m ?c)))

(defrelation Uncle-of ((?t Person) (?c Person))
:<=> (exist ?p (and (Parent-of ?p ?c) (Brother-of ?t ?p))))

(defrelation Aunt-of ((?t Person) (?c Person))
:<=> (exist ?p (and (Parent-of ?p ?c) (Sister-of ?t ?p))))

(defrelation Primo-of ((?o Person) (?c Person))
:<=> (and (exist ?t (and (or (Uncle-of ?t ?c) (Aunt-of ?t ?c)) (Parent-of ?t ?o))) (Male ?o)))

(defrelation Prima-of ((?a Person) (?c Person))
:<=> (and (exist ?t (and (or (Uncle-of ?t ?c) (Aunt-of ?t ?c)) (Parent-of ?t ?a))) (Female ?a)))

(defrelation Cuñado-of ((?h Person) (?c Person))
:<=> (exists ?m (or (and (Spouse-of ?m ?c) (Brother-of ?h ?m)) (and (Sister-of ?m ?c) (Husband-of ?h ?m)))))

(defrelation Cuñada-of ((?m Person) (?c Person))
:<=> (exists ?h (or (and (Spouse-of ?h ?c) (Brother-of ?m ?h)) (and (Sister-of ?h ?c) (Husband-of ?m ?h)))))

(defrelation Suegro-of ((?s Person) (?c Person))
:<=> (exists ?p (and (Spouse-of ?p ?c) (Father-of ?s ?p))))

(defrelation Suegra-of ((?s Person) (?c Person))
:<=> (exists ?p (and (Spouse-of ?p ?c) (Mother-of ?s ?p))))

(defrelation Concuño-of ((?o Person) (?c Person))
:<=> (exists (?p ?q) (and (Spouse-of ?c ?p) (Sibling-of ?p ?q) (Husband-of ?o ?q))))

(defrelation Concuña-of ((?a Person) (?c Person))
:<=> (exists (?p ?q) (and (Spouse-of ?c ?p) (Sibling-of ?p ?q) (Wife-of ?a ?q))))

(defrelation Consuegro-of ((?o Person) (?c Person))
:<=> (exists (?p ?q) (and (Parent-of ?c ?p) (Spouse-of ?p ?q) (Father-of ?o ?q))))

(defrelation Consuegra-of ((?a Person) (?c Person))
:<=> (exists (?p ?q) (and (Parent-of ?c ?p) (Spouse-of ?p ?q) (Mother-of ?a ?q))))

(defrelation Nietx-of ((?x Person) (?c Person))
:<=> (exists ?p (and (Parent-of ?c ?p) (Parent-of ?p ?x))))

(defrelation Nieto-of ((?o Person) (?c Person))
:<=> (and (Male ?o) (Nietx-of ?o ?c)))

(defrelation Nieta-of ((?a Person) (?c Person))
:<=> (and (Female ?a) (Nietx-of ?a ?c)))

(defrelation Bisnieto-of ((?o Person) (?c Person))
:<=> (exists ?p (and (Parent-of ?c ?p) (Nieto-of ?o ?p))))

(defrelation Bisnieta-of ((?a Person) (?c Person))
:<=> (exists ?p (and (Parent-of ?c ?p) (Nieta-of ?a ?p))))

(defrelation Sobrinx-of ((?s Person) (?p Person))
:<=> (exists ?x (and (Sibling-of ?x ?p) (Parent-of ?x ?s))))

(defrelation Sobrina-of ((?s Person) (?p Person))
:<=> (and (Female ?s) (Sobrinx-of ?s ?p)))

(defrelation Sobrino-of ((?s Person) (?p Person))
:<=> (and (Male ?s) (Sobrinx-of ?s ?p)))





;;;(assert (forall (?x ?y) (exists ?z (<= (and (Sibling-of ?x ?y) (Sibling-of ?x ?z)) (Sibling-of ?y ?z)))));;;
;;;(assert (forall (?x ?y) (exists ?p (=> (and (Sibling-of ?x ?y) (Parent-of ?p ?x)) (Parent-of ?p ?y)))));;;
;;;(assert (forall (?x ?y ?z) (<=> (and (Mother-of ?x ?z) (Mother-of ?y ?z)) (= ?x ?y))));;;
;;;(assert (forall (?x ?y ?z) (<=> (and (Father-of ?x ?z) (Father-of ?y ?z)) (= ?x ?y))));;;






(assert (Male Miguel))

(assert (Male Alejandro))

(assert (Male Fernando))

(assert (Female Carmen))

(assert (Male Alberto))

(assert (Male Marcos))

(assert (Female María))

(assert (Male Tomás))

(assert (Female Lucía))

(assert (Female Berta))

(assert (Female Patricia))


(assert (or (Parent-of Miguel Alejandro) (Parent-of Alejandro Miguel)))
(assert (exists (?hermano Person) (Brother-of Fernando ?hermano)))
(assert (forall (?x ?y) (=> (and (Brother-of Fernando ?x) (Brother-of Fernando ?y)) (= ?x ?y))))
(assert (Sibling-of Alejandro Carmen))
(assert (exists (?madre) (and (Mother-of ?madre Marcos) (Father-of Alberto ?madre))))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 María) (Child-of ?h2 María))))
(assert (range-cardinality Parent-of María 2))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 Carmen) (Child-of ?h2 Carmen))))
(assert (range-cardinality Parent-of Carmen 2))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 Alberto) (Child-of ?h2 Alberto))))
(assert (range-cardinality Parent-of Alberto 2))
(assert (Cuñado-of Tomás Lucía))
(assert (exists (?hermana ?hermano) (and (Sister-of ?hermana Berta) (and (Brother-of ?hermano ?hermana) (Brother-of ?hermano Berta)))))
(assert (Sobrinx-of Patricia Carmen))



(retrieve all ?p (and (Person ?p) (Parent-of Alberto ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Alejandro ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Miguel ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Fernando ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Marcos ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of María ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Carmen ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Tomás ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Lucía ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Patricia ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Berta ?p)))
(retrieve all ?p (and (Person ?p) (Grandpa-of Alberto ?p)))

Actividades 2 y 3
Asserts
(assert (Male Miguel))
(assert (Male Alejandro))
(assert (Male Fernando))
(assert (Female Carmen))
(assert (Male Alberto))
(assert (Male Marcos))
(assert (Female María))
(assert (Male Tomás))
(assert (Female Lucía))
(assert (Female Berta))
(assert (Female Patricia))

(assert (or (Parent-of Miguel Alejandro) (Parent-of Alejandro Miguel)))
(assert (exists (?hermano Person) (Brother-of Fernando ?hermano)))
(assert (forall (?x ?y) (=> (and (Brother-of Fernando ?x) (Brother-of Fernando ?y)) (= ?x ?y))))
(assert (Sibling-of Alejandro Carmen))
(assert (exists (?madre) (and (Mother-of ?madre Marcos) (Father-of Alberto ?madre))))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 María) (Child-of ?h2 María))))
(assert (range-cardinality Parent-of María 2))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 Carmen) (Child-of ?h2 Carmen))))
(assert (range-cardinality Parent-of Carmen 2))
(assert (exists (?h1 ?h2) (and (Child-of ?h1 Alberto) (Child-of ?h2 Alberto))))
(assert (range-cardinality Parent-of Alberto 2))
(assert (Cuñado-of Tomás Lucía))
(assert (exists (?hermana ?hermano) (and (Sister-of ?hermana Berta) (and (Brother-of ?hermano ?hermana) (Brother-of ?hermano Berta)))))
(assert (Sobrinx-of Patricia Carmen))

Queries
(retrieve all ?p (and (Person ?p) (Parent-of Alberto ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Alejandro ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Miguel ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Fernando ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Marcos ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of María ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Carmen ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Tomás ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Lucía ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Patricia ?p)))
(retrieve all ?p (and (Person ?p) (Parent-of Berta ?p)))
(retrieve all ?p (and (Person ?p) (Grandpa-of Alberto ?p)))


Actividad 4


(in-package "STELLA")

(defmodule "PL-KERNEL/PL-USER/EINSTEIN")

(in-module "EINSTEIN")

(clear-module "EINSTEIN")

(in-dialect :KIF)

(defconcept Color)

(assert (Color blanca))

(assert (Color amarilla))

(assert (Color roja))

(assert (Color verde))

(assert (Color azul))


(defconcept Casa)

(assert (Casa uno))

(assert (Casa dos))

(assert (Casa tres))

(assert (Casa cuatro))

(assert (Casa cinco))


(defconcept Cigarro)

(assert (Cigarro PallMall))

(assert (Cigarro Bluemaster))

(assert (Cigarro Dunhill))

(assert (Cigarro Blend))

(assert (Cigarro Prince))


(defconcept Bebida)

(assert (Bebida cerveza))

(assert (Bebida agua))

(assert (Bebida leche))

(assert (Bebida cafe))

(assert (Bebida te))


(defconcept Mascota)

(assert (Mascota perro))

(assert (Mascota pajaros))

(assert (Mascota gatos))

(assert (Mascota caballos))

(assert (Mascota pez))


(defconcept Nacionalidad)

(assert (Nacionalidad noruego))

(assert (Nacionalidad ingles))

(assert (Nacionalidad danes))

(assert (Nacionalidad sueco))

(assert (Nacionalidad aleman))


(defrelation Casa-para-Nacionalidad ((?c Casa) (?n Nacionalidad)))

(defrelation Nacionalidad-para-Casa ((?n Nacionalidad) (?c Casa)))

(assert (inverse Casa-para-Nacionalidad Nacionalidad-para-Casa))

(assert (forall (?i) (= (range-cardinality Nacionalidad-para-Casa ?i) (1))))

(assert (forall (?i) (= (range-cardinality Casa-para-Nacionalidad ?i) (1))))


(defrelation Mascota-de-Casa ((?m Mascota) (?c Casa)))

(defrelation Casa-de-Mascota ((?c Casa) (?m Mascota)))

(assert (inverse Mascota-de-Casa Casa-de-Mascota))

(assert (forall (?i) (= (range-cardinality Mascota-de-Casa ?i) (1))))

(assert (forall (?i) (= (range-cardinality Casa-de-Mascota ?i) (1))))


(defrelation Bebida-de-Casa ((?b Bebida) (?c Casa)))

(defrelation Casa-de-Bebida ((?c Casa) (?b Bebida)))

(assert (inverse Bebida-de-Casa Casa-de-Bebida))

(assert (range-cardinality Bebida-de-Casa Casa 1))

(assert (range-cardinality Casa-de-Bebida Bebida 1))

(assert (forall (?i) (= (range-cardinality Bebida-de-Casa ?i) (1))))

(assert (forall (?i) (= (range-cardinality Casa-de-Bebida ?i) (1))))


(defrelation Cigarro-de-Casa ((?g Cigarro) (?c Casa)))

(defrelation Casa-de-Cigarro ((?c Casa) (?g Cigarro)))

(assert (inverse Cigarro-de-Casa Casa-de-Cigarro))

(assert (forall (?i) (= (range-cardinality Cigarro-de-Casa ?i) (1))))

(assert (forall (?i) (= (range-cardinality Casa-de-Cigarro ?i) (1))))


(defrelation Color-de-Casa ((?l Color) (?c Casa)))

(defrelation Casa-de-Color ((?c Casa) (?l Color)))

(assert (inverse Color-de-Casa Casa-de-Color))

(assert (forall (?i) (= (range-cardinality Color-de-Casa ?i) (1))))

(assert (forall (?i) (= (range-cardinality Casa-de-Color ?i) (1))))



(defrelation next ((?c2 Casa) (?c1 Casa)))

(defrelation junto-a ((?c1 Casa) (?c2 Casa))
:<=> (or (next ?c1 ?c2) (next ?c2 ?c1)))

(assert (next dos uno))

(assert (next tres dos))

(assert (next cuatro tres))

(assert (next cinco cuatro))

;;;(assert (range-cardinality Casa-de-Color Color 1));;;

Actividad 5
1. ¿Qué relación tiene conmigo Lola si su madre fue la única hija de mi madre?

(assert (Female Lola))
(assert (Female MamáDeLola))
(assert (Female MiMamá))
(assert (Male Yo))

(assert (Mother-of MamáDeLola Lola))
(assert (Mother-of MiMamá Yo))
(assert (Daughter-of MamáDeLola MiMamá))
(assert (forall (?x) (=> (Daughter-of ?x ?MiMamá) (= ?x MamáDeLola))))

(ask (Uncle-of Yo Lola))

2. ¿Qué es de mí el abuelo paterno de la hija de mi único hermano?
(assert (Male Hermano))
(assert (Female Hija))
(assert (Male Abuelo))
(assert (Male Yo))

(assert (Brother-of Hermano Yo))
(assert (Daughter-of Hija Hermano))
(assert (Grandpa-of Abuelo Hija))

(ask (Father-of Abuelo Yo))

3. Tito es tío de Tota, Tota es hermana de Toña, Toña es madre de Pepe. ¿Qué es Tito de Pepe?
(defrelation TíoAbuelo-de ((?g Person) (?c Person))
:<=> (exists ?p (and (Uncle-of ?g ?p) (Parent-of ?p ?c))))

(assert (Male Tito))
(assert (Female Tota))
(assert (Female Toña))
(assert (Male Pepe))

(assert (Uncle-of Tito Tota))
(assert (Sister-of Tota Toña))
(assert (Mother-of Toña Pepe))

(ask (TíoAbuelo-de Tito Pepe))

4. ¿Quién es el único nieto del padre del padre de Jorge?
(assert (Male Jorge))
(assert (Male Padre))
(assert (Male PadreDelPadre))

(assert (Father-of Padre Jorge))
(assert (Father-of PadreDelPadre Padre))

(retrieve all ?p (Grandpa-of Jorge ?p))

5. ¿Qué parentesco tiene conmigo un joven que es el hijo de la esposa del único hijo de mi abuela?
(assert (Female Abuela))
(assert (Male ÚnicoHijo))
(assert (Female Esposa))
(assert (Male Hijo))
(assert (Female Yo))

(assert (Mother-of Abuela ÚnicoHijo))
(assert (forall (?x) (=> (Mother-of Abuela ?x) (= ?x ÚnicoHijo))))
(assert (Granny-of Abuela Yo))
(assert (Wife-of Esposa ÚnicoHijo))
(assert (Mother-of Esposa Hijo))

(ask (Brother-of Hijo Yo))   

No hay comentarios:

Publicar un comentario en la entrada