scheme myfamily = class type TMaleFemale=Text>< Marriage-set>< FatherDaughter-set>Male-set getMales((m,f,ma,fs,fd,ms,md)) is m, getFemales: Family->Female-set getFemales((m,f,ma,fs,fd,ms,md)) is f, getMarriages: Family->Marriage-set getMarriages((m,f,ma,fs,fd,ms,md)) is ma, getFatherSon:Family->FatherSon-set getFatherSon((m,f,ma,fs,fd,ms,md)) is fs, getFatherDaughter:Family->FatherDaughter-set getFatherDaughter((m,f,ma,fs,fd,ms,md)) is fd, getMotherDaughter:Family->MotherDaughter-set getMotherDaughter((m,f,ma,fs,fd,ms,md)) is md, getMotherSon:Family->MotherSon-set getMotherSon((m,f,ma,fs,fd,ms,md)) is ms, getMarMan: Marriage->Male getMarMan((male,female)) is male, getMarWoman: Marriage->Male getMarWoman((male,female)) is female, /*task's fumction*/ existMale:Family>Bool existMale(fam,male) as res post true =(res = (male isin getMales(fam))) , existFemale:Family>Bool existFemale(fam,female) as res post true =(res = (female isin getFemales(fam))), existMarriage:Family>Bool existMarriage(fam,mar) as res post true =(res = (mar isin getMarriages(fam))), existMarriagePair:Family>Bool existMarriagePair(fam,female,male) as res post true =( res = (exists (m,f): Marriage :- ((m,f) isin getMarriages(fam))/\ (m = male)/\(f=female))) , hasWife: Family>Bool hasWife(fam,male) as res post res = (exists (m,f): Marriage :- ((m,f) isin getMarriages(fam)) /\ (m = male)), hasHusband: Family>Bool hasHusband(fam,female) as res post true =( res = (exists (m,f): Marriage :- ((m,f) isin getMarriages(fam)) /\ (f = female))), existSon:Family>Bool existSon(fam,son) as res post true =( res = ( exists (f,s):FatherSon :- (f,s) isin getFatherSon(fam) /\ s=son)), existDaughter:Family>Bool existDaughter(fam,dau) as res post true =(res = (exists (f,d):FatherDaughter :- (f,d) isin getFatherDaughter(fam) /\d=dau)), addMale:Family>Family addMale(fam,male) as res post true=(existMale(res,male)/\ ( getMales(fam)=getMales(res) \{male} /\ getFemales(fam)=getFemales(res) /\ getMarriages(fam)=getMarriages(res)/\ getFatherSon(fam)=getFatherSon(res)/\ getFatherDaughter(fam)=getFatherDaughter(res)/\ getMotherDaughter(fam)=getMotherDaughter(res) /\ getMotherSon(fam)=getMotherSon(res) )) pre (~existMale(fam,male)), addFemale:Family>Family addFemale(fam,female) as res post true =(existFemale(res,female)/\ ( getFemales(fam)=getFemales(res) \{female} /\ getMales(fam)=getMales(res) /\ getMarriages(fam)=getMarriages(res)/\ getFatherSon(fam)=getFatherSon(res)/\ getFatherDaughter(fam)=getFatherDaughter(res)/\ getMotherDaughter(fam)=getMotherDaughter(res) /\ getMotherSon(fam)=getMotherSon(res) )) pre (~existFemale(fam,female)), addWife:Family>Family addWife(family,female,male) as res post true =( ( (female isin getFemales(res)) /\ (existMarriagePair(res,female,male)) /\ (~existMarriagePair(family,female,male)) )/\ ( getFemales(family)=getFemales(res) \{female} /\ getMales(family)=getMales(res) /\ getMarriages(family)=getMarriages(res) \ {(male,female)}/\ getFatherSon(family)=getFatherSon(res)/\ getFatherDaughter(family)=getFatherDaughter(res)/\ getMotherDaughter(family)=getMotherDaughter(res) /\ getMotherSon(family)=getMotherSon(res) )) pre ( (~existFemale(family,female)) /\ (existMale(family,male))/\ (~hasWife(family,male)) ), addHusband:Family>Family addHusband(family,female,male) as res post true =( ( (male isin getMales(res)) /\ (existMarriagePair(res,female,male)) /\ (~existMarriagePair(family,female,male)) )/\ ( getFemales(family)=getFemales(res) /\ getMales(family)=getMales(res) \{male}/\ getMarriages(family)=getMarriages(res) \ {(male,female)}/\ getFatherSon(family)=getFatherSon(res)/\ getFatherDaughter(family)=getFatherDaughter(res)/\ getMotherDaughter(family)=getMotherDaughter(res) /\ getMotherSon(family)=getMotherSon(res) )) pre ( (existFemale(family,female)) /\ (~existMale(family,male))/\ (~hasHusband(family,female)) ), addSon:Family>Family addSon(family,mar,male) as res post true= ( existSon(res,male) /\ existMale(res,male)/\ (exists (f,s) : FatherSon :- ((f,s) isin getFatherSon(res)) /\ (s = male) /\ (f = getMarMan(mar))) /\ (~(exists (f1,s1) : FatherSon :- ((f1,s1) isin getFatherSon(res)) /\ (s1 = male) /\ (f1 = getMarMan(mar)))) /\ (exists (m,s) : MotherSon :- ((m,s) isin getMotherSon(res)) /\ (s = male) /\ (m = getMarWoman(mar))) /\ (~(exists (m2,s2) : MotherSon :- ((m2,s2) isin getMotherSon(res)) /\ (s2 = male) /\ (m2 = getMarWoman(mar)))) ) pre (existMarriage(family,mar) /\ (~existMale(family,male))), addDaughter:Family>Family addDaughter(family,mar,female) as res post true =( ( existDaughter(res,female) /\ existFemale(res,female) /\ (exists (f,d) : FatherDaughter :- ((f,d) isin getFatherDaughter(res)) /\ (d = female) /\ (f = getMarMan(mar))) /\ (~(exists (f1,d1) : FatherDaughter :- ((f1,d1) isin getFatherDaughter(res)) /\ (f1 = female) /\ (f1 = getMarMan(mar)))) /\ (exists (m,d) : MotherDaughter :- ((m,d) isin getMotherDaughter(res)) /\ (d = female) /\ (m = getMarWoman(mar))) /\ (~(exists (m2,d2) : MotherDaughter :- ((m2,d2) isin getMotherDaughter(res)) /\ (d2 = female) /\ (m2 = getMarWoman(mar)))) )) pre (existMarriage(family,mar) /\ (~existFemale(family,female))), getChildren:Family>Children getChildren(family,(m,f)) as res post true =(res= ( {boy | boy:Male :- existSon(family,boy) /\ existMale(family,boy) /\ (exists(father,son): FatherSon :- (father,son) isin getFatherSon(family) /\ father=f /\son=boy) }, {girl|girl:Female:- existDaughter(family,girl) /\ existFemale(family,girl) /\ (exists(father,daughter): FatherDaughter :- (father,daughter) isin getFatherDaughter(family) /\ father=f /\girl=daughter) } )) pre existMarriage(family,(m,f)) end