Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

對不起 又來麻煩你嚕 再問一下

浏览上一个主题 浏览下一个主题 向下  留言 [第1页/共1页]

1 對不起 又來麻煩你嚕 再問一下 于 周二 十一月 27, 2012 4:20 am

主程式:

family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)].

husband(X) :- family(X, _, _).
wife(X) :- family(_, X, _).
child(X) :- family(_,_,Childred), member(X, Children).
exists(Person) :- husband(Person); wife(Person); child(Person).

若我想弄個查詢 雙胞胎的程式 和計算 家庭的年收入的話 該如何寫呢???謝謝您
因為還蠻急的 麻煩你了

查阅用户资料

2 回复: 對不起 又來麻煩你嚕 再問一下 于 周二 十一月 27, 2012 9:03 am

nestea520 写道::主程式:

family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)].

husband(X) :- family(X, _, _).
wife(X) :- family(_, X, _).
child(X) :- family(_,_,Childred), member(X, Children).
exists(Person) :- husband(Person); wife(Person); child(Person).

若我想弄個查詢 雙胞胎的程式 和計算 家庭的年收入的話 該如何寫呢???謝謝您
因為還蠻急的 麻煩你了

代码:
family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)]).


income :- family(person(A,B,_,S1), person(_,_,_,S2), [person(_,_,_,S3), person(_,_,_,S4)]),
          (S1 = works(_, M1) -> L1 = [M1]; L1 = []), (S2 = works(_, M2) -> L2 = [M2|L1]; L2 = L1),
          (S3 = works(_, M3) -> L3 = [M3|L2]; L3 = L2), (S4 = works(_, M4) -> L4 = [M4|L3]; L4 = L3),
          sumlist(L4, I), write('family '), write(A), write(' '), write(B), write(' : income = '), write(I), nl, false.


14 ?- income.
family tom fox : income = 15200
false.


双胞胎的话,你要先想个方法让记录能体现出双胞胎的信息,
定好表示方法的话查询是很容易的。

查阅用户资料 http://prolog.longluntan.net

3 回复: 對不起 又來麻煩你嚕 再問一下 于 周二 十一月 27, 2012 10:33 am

Mercury Liao 写道::
nestea520 写道::主程式:

family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)].

husband(X) :- family(X, _, _).
wife(X) :- family(_, X, _).
child(X) :- family(_,_,Childred), member(X, Children).
exists(Person) :- husband(Person); wife(Person); child(Person).

若我想弄個查詢 雙胞胎的程式 和計算 家庭的年收入的話 該如何寫呢???謝謝您
因為還蠻急的 麻煩你了

代码:
family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)]).


income :- family(person(A,B,_,S1), person(_,_,_,S2), [person(_,_,_,S3), person(_,_,_,S4)]),
          (S1 = works(_, M1) -> L1 = [M1]; L1 = []), (S2 = works(_, M2) -> L2 = [M2|L1]; L2 = L1),
          (S3 = works(_, M3) -> L3 = [M3|L2]; L3 = L2), (S4 = works(_, M4) -> L4 = [M4|L3]; L4 = L3),
          sumlist(L4, I), write('family '), write(A), write(' '), write(B), write(' : income = '), write(I), nl, false.


14 ?- income.
family tom fox : income = 15200
false.


双胞胎的话,你要先想个方法让记录能体现出双胞胎的信息,
定好表示方法的话查询是很容易的。

了解 謝謝 那不能夠把兒子的出生年月日一樣 父母親也一樣就證明是雙胞胎麻??

查阅用户资料

4 回复: 對不起 又來麻煩你嚕 再問一下 于 周二 十一月 27, 2012 11:07 am

nestea520 写道::
Mercury Liao 写道::
nestea520 写道::主程式:

family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)].

husband(X) :- family(X, _, _).
wife(X) :- family(_, X, _).
child(X) :- family(_,_,Childred), member(X, Children).
exists(Person) :- husband(Person); wife(Person); child(Person).

若我想弄個查詢 雙胞胎的程式 和計算 家庭的年收入的話 該如何寫呢???謝謝您
因為還蠻急的 麻煩你了

代码:
family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)]).


income :- family(person(A,B,_,S1), person(_,_,_,S2), [person(_,_,_,S3), person(_,_,_,S4)]),
          (S1 = works(_, M1) -> L1 = [M1]; L1 = []), (S2 = works(_, M2) -> L2 = [M2|L1]; L2 = L1),
          (S3 = works(_, M3) -> L3 = [M3|L2]; L3 = L2), (S4 = works(_, M4) -> L4 = [M4|L3]; L4 = L3),
          sumlist(L4, I), write('family '), write(A), write(' '), write(B), write(' : income = '), write(I), nl, false.


14 ?- income.
family tom fox : income = 15200
false.


双胞胎的话,你要先想个方法让记录能体现出双胞胎的信息,
定好表示方法的话查询是很容易的。

了解 謝謝 那不能夠把兒子的出生年月日一樣 父母親也一樣就證明是雙胞胎麻??

是哈,我怎么没想到。
那你可以练习写写看,这个应该比计算家庭年收入还容易。

查阅用户资料 http://prolog.longluntan.net
family(
person( brian, fox, date(17,apr,1958), works(bbc, 42000)),
person( donna, fox, date(12,sep,1962), unemployed),
[person( jason, fox, date(01,jan,1988), unemployed)]).

family(
person( andy, do, date(19,sep,1976), works(director, 400000)),
person( min, do, date(5,mar,1975), works(boss, 150000)).

family(
person( andrew, re, date(15,dec,1970), works(professor, 82000)),
person( sue, re, date(28,feb,1975), works(teacher, 36000)).
[person( Tommy, re, date(22,jul,1992), unemployed)]).

family(
person( william, mi, date(20,mar,1968), works(actor, 200000)),
person( vicky, mi, date(23,jul,1973), unemployed),
[person( simon, mi, date(24,dec,1987), works(office workers,28000)),
person( daniel, mi, date(15,oct,1989), unemployed),
person( alice, mi, date(14,apr,1992), unemployed)]).

family(
person( ian, fa, date(12,dec,1961), works(engineer, 200000)),
person( eileen , fa, date(10,feb,1963), unemployed),
[person( alex, fa, date(17,dec,1981), works(engineer, 54000)),
person( abbie, fa, date(03,aug,1990), unemployed)]).

family(
person( zoe, so, date(19,dec,1980), works(doctor, 120000)),
[person( rita, so, date(6,jun,2007), unemployed)]).

family(
person( steven, la, date(16,oct,1943), unemployed),
person( olivia, la, date(11,nov,1947), unemployed),
[person( jessie, la, date(16,jul,1977), works(teacher, 38000)),
person( wayne , la, date(2,nov,1982), works(teacher, 40000)]).

family(
person( paul, si, date(23,apr,1970), works(Stylist, 42000)),
person( eva, si, date(19,mar,1975), unemployed),
[person( owen, si, date(12,aug,1983), works(sale, 15000)]).

family(
person( peggy, da, date(30,dec,1963), works(assistant, 32000)),
[person( roger, da, date(5,may,1973), works(worker, 28000))]).

family(
person( jeff, gi, date(27,may,1980), works(accountants, 62000)),
person( vivian, gi, date(29,may,1981), works(secretary, 32000)),
[person( monica, gi, date(5,may,1993), unemployed)),
person( edward , gi, date(5,may,1993), unemployed)),
person( ada, gi, date(5,may,1994), unemployed)]).

husband(X):-family(X,_,_).

wife(X):-family(_,X,_).

child(X):-family(_,_,Children),
member(X,Children).

exists(Person):-husband(Person);
wife(Person);
child(Person).


dateofbirth(person(_,_,Date,_),Date).

salary(person(_,_,_,works(_,S)),S).

salary(person(_,_,_,unemployed),0).

income :- family(person(A,B,_,S1), person(_,_,_,S2), [person(_,_,_,S3), person(_,_,_,S4)]),
(S1 = works(_, M1) -> L1 = [M1]; L1 = []), (S2 = works(_, M2) -> L2 = [M2|L1]; L2 = L1),
(S3 = works(_, M3) -> L3 = [M3|L2]; L3 = L2), (S4 = works(_, M4) -> L4 = [M4|L3]; L4 = L3),
sumlist(L4, I), write('family '), write(A), write(' '), write(B), write(' : income = '), write(I), nl, false.


結果:
1 ?- income.
family ian fa : income = 254000
false.

還有雙胞胎 我只知道規則 但程式部分還是不太懂~~ Crying or Very sad

查阅用户资料

浏览上一个主题 浏览下一个主题 返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题