版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Asaset:
speed
2.66
2.10
1.42
2.80
3.20
2.20
2.00
1.86
3.06
Average=2.37
Asabag:
speed
2.66
2.10
1.42
2.80
3.20
3.20
2.20
2.20
2.00
2.80
1.86
2.80
3.06
Average=2.48
Asaset:
hd
250
80
320
200
300
160
Average=218
Asabag:
hd
250
250
80
250
250
320
200
250
250
300
160
160
80
Average=215
Asaset:
bore
15
16
14
18
Asabag:
bore
15
16
14
16
15
15
14
18
πbore(ShipsClasses)
Forbags:
Ontheleft-handside:
GivenbagsRandSwhereatupletappearsnandmtimesrespectively,theunionofbagsRandSwillhavetupletappearn+mtimes.ThefurtherunionofbagTwiththetupletappearingotimeswillhavetupletappearn+m+otimesinthefinalresult.
Ontheright-handside:
GivenbagsSandTwhereatupletappearsmandotimesrespectively,theunionofbagsRandSwillhavetupletappearm+otimes.ThefurtherunionofbagRwiththetupletappearingntimeswillhavetupletappearm+o+ntimesinthefinalresult.
Forsets:
Thisisasimilarcasewhendealingwithbagsexceptthetupletcanonlyappearatmostonceineachset.Thetupletonlyappearsintheresultifallthesetshavethetuplet.Otherwise,thetupletwillnotappearintheresult.Sincewecannothaveduplicates,theresultonlyhasatmostonecopyofthetuplet.
Forbags:
Ontheleft-handside:
GivenbagsRandSwhereatupletappearsnandmtimesrespectively,theintersectionofbagsRandSwillhavetupletappearmin(n,m)times.ThefurtherintersectionofbagTwiththetupletappearingotimeswillproducetupletmin(o,min(n,m))timesinthefinalresult.
Ontheright-handside:
GivenbagsSandTwhereatupletappearsmandotimesrespectively,theintersectionofbagsRandSwillhavetupletappearmin(m,o)times.ThefurtherintersectionofbagRwiththetupletappearingntimeswillproducetupletmin(n,min(m,o))timesinthefinalresult.
TheintersectionofbagsR,SandTwillyieldaresultwheretupletappearsmin(n,m,o)times.
Forsets:
Thisisasimilarcasewhendealingwithbagsexceptthetupletcanonlyappearatmostonceineachset.Thetupletonlyappearsintheresultifallthesetshavethetuplet.Otherwise,thetupletwillnotappearintheresult.
Forbags:
Ontheleft-handside:
GiventhattuplerinR,whichappearsmtimes,cansuccessfullyjoinwithtuplesinS,whichappearsntimes,weexpecttheresulttocontainmncopies.AlsogiventhattupletinT,whichappearsotimes,cansuccessfullyjoinwiththejoinedtuplesofrands,weexpectthefinalresulttohavemnocopies.
Ontheright-handside:
GiventhattuplesinS,whichappearsntimes,cansuccessfullyjoinwithtupletinT,whichappearsotimes,weexpecttheresulttocontainnocopies.AlsogiventhattuplerinR,whichappearsmtimes,cansuccessfullyjoinwiththejoinedtuplesofsandt,weexpectthefinalresulttohavenomcopies.
Theorderinwhichweperformthenaturaljoindoesnotmatterforbags.
Forsets:
Thisisasimilarcasewhendealingwithbagsexceptthejoinedtuplescanonlyappearatmostonceineachresult.Iftherearetuplesr,s,tinrelationsR,S,Tthatcansuccessfullyjoin,thentheresultwillcontainatuplewiththeschemaoftheirjoinedattributes.
Forbags:
SupposeatupletoccursnandmtimesinbagsRandSrespectively.IntheunionofthesetwobagsRS,tupletwouldappearn+mtimes.Likewise,intheunionofthesetwobagsSR,tupletwouldappearm+ntimes.Bothsidesoftherelationyieldthesameresult.
Forsets:
Atupletcanonlyappearatmostonetime.TupletmightappeareachinsetsRandSoneorzerotimes.ThecombinationsofnumberofoccurrencesfortupletinRandSrespectivelyare(0,0),(0,1),(1,0),and(1,1).OnlywhentupletappearsinbothsetsRandSwilltheunionRShavethetuplet.ThesamereasoningholdswhenwetaketheunionSR.
Thereforethecommutativelawforunionholds.
Forbags:
SupposeatupletoccursnandmtimesinbagsRandSrespectively.IntheintersectionofthesetwobagsR∩S,tupletwouldappearmin(n,m)times.LikewiseintheintersectionofthesetwobagsS∩R,tupletwouldappearmin(m,n)times.Bothsidesoftherelationyieldthesameresult.
Forsets:
Atupletcanonlyappearatmostonetime.TupletmightappeareachinsetsRandSoneorzerotimes.ThecombinationsofnumberofoccurrencesfortupletinRandSrespectivelyare(0,0),(0,1),(1,0),and(1,1).OnlywhentupletappearsinatleastoneofthesetsRandSwilltheintersectionR∩Shavethetuplet.ThesamereasoningholdswhenwetaketheintersectionS∩R.
Thereforethecommutativelawforintersectionholds.
Forbags:
SupposeatupletoccursntimesinbagRandtupleuoccursmtimesinbagS.Supposealsothatthetwotuplest,ucansuccessfullyjoin.TheninthenaturaljoinofthesetwobagsRS,thejoinedtuplewouldappearnmtimes.LikewiseinthenaturaljoinofthesetwobagsSR,thejoinedtuplewouldappearmntimes.Bothsidesoftherelationyieldthesameresult.
Forsets:
Anarbitrarytupletcanonlyappearatmostonetimeinanyset.Tuplesu,vmightappearrespectivelyinsetsRandSoneorzerotimes.Thecombinationsofnumberofoccurrencesfortuplesu,vinRandSrespectivelyare(0,0),(0,1),(1,0),and(1,1).OnlywhentupleuexistsinRandtuplevexistsinSwillthenaturaljoinRShavethejoinedtuple.ThesamereasoningholdswhenwetakethenaturaljoinSR.
Thereforethecommutativelawfornaturaljoinholds.
Forbags:
SupposetupletappearsmtimesinRandntimesinS.IfwetaketheunionofRandSfirst,wewillgetarelationwheretupletappearsm+ntimes.TakingtheprojectionofalistofattributesLwillyieldaresultingrelationwheretheprojectedattributesfromtupletappearm+ntimes.IfwetaketheprojectionoftheattributesinlistLfirst,thentheprojectedattributesfromtupletwouldappearmtimesfromRandntimesfromS.Theunionoftheseresultingrelationswouldhavetheprojectedattributesoftupletappearm+ntimes.
Forsets:
Anarbitrarytupletcanonlyappearatmostonetimeinanyset.TupletmightappearinsetsRandSoneorzerotimes.ThecombinationsofnumberofoccurrencesfortupletinRandSrespectivelyare(0,0),(0,1),(1,0),and(1,1).OnlywhentupletexistsinRorS(orbothRandS)willtheprojectedattributesoftupletappearintheresult.
Thereforethelawholds.
Forbags:
SupposetupletappearsutimesinR,vtimesinSandwtimesinT.Onthelefthandside,theintersectionofSandTwouldproducearesultwheretupletwouldappearmin(v,w)times.WiththeadditionoftheunionofR,theoverallresultwouldhaveu+min(v,w)copiesoftuplet.Ontherighthandside,wewouldgetaresultofmin(u+v,u+w)copiesoftuplet.Theexpressionsonboththeleftandrightsidesareequivalent.
Forsets:
Anarbitrarytupletcanonlyappearatmostonetimeinanyset.TupletmightappearinsetsR,SandToneorzerotimes.ThecombinationsofnumberofoccurrencesfortupletinR,SandTrespectivelyare(0,0,0),(0,0,1),(0,1,0),(0,1,1),(1,0,0),(1,0,1),(1,1,0)and(1,1,1).OnlywhentupletappearsinRorinbothSandTwilltheresulthavetuplet.
Thereforethedistributivelawofunionoverintersectionholds.
SupposethatinrelationR,utuplessatisfyconditionCandvtuplessatisfyconditionD.SupposealsothatwtuplessatisfybothconditionsCandDwherew≤min(v,w).Thenthelefthandsidewillreturnthosewtuples.Ontherighthandside,σC(R)producesutuplesandσD(R)producesvtuples.However,weknowtheintersectionwillproducethesamewtuplesintheresult.
Whenconsideringbagsandsets,theonlydifferenceisbagsallowduplicatetupleswhilesetsonlyallowonecopyofthetuple.Theexampleaboveappliestobothcases.
Thereforethelawholds.
Forsets,anarbitrarytupletappearsonthelefthandsideifitappearsinbothR,SandnotinT.Thesameistruefortherighthandside.
Asanexampleforbags,supposethattupletappearsonetimeeachinbothR,TandtwotimesinS.Theresultofthelefthandsidewouldhavezerocopiesoftupletwhiletherighthandsidewouldhaveonecopyoftuplet.
Thereforethelawholdsforsetsbutnotforbags.
Forsets,anarbitrarytupletappearsonthelefthandsideifitappearsinRandeitherSorT.ThisisequivalenttosayingtupletonlyappearswhenitisinatleastRandSorinRandT.Theequivalenceisexactlytherightside’sexpression.
Asanexampleforbags,supposethattupletappearsonetimeinRandtwotimeseachinSandT.Thenthelefthandsidewouldhaveonecopyoftupletintheresultwhiletherighthandsidewouldhavetwocopiesoftuplet.
Thereforethelawholdsforsetsbutnotforbags.
Forsets,anarbitrarytupletappearsonthelefthandsideifitsatisfiesconditionC,conditionDorbothconditionCandD.Ontherighthandside,σC(R)selectsthosetuplesthatsatisfyconditionCwhileσD(R)selectsthosetuplesthatsatisfyconditionD.However,theunionoperatorwilleliminateduplicatetuples,namelythosetuplesthatsatisfybothconditionCandD.Thusweareensuredthatbothsidesareequivalent.
Asanexampleforbags,weonlyneedtolookattheunionoperator.IfthereareindeedtuplesthatsatisfybothconditionsCandD,thentherighthandsidewillcontainduplicatecopiesofthosetuples.Thelefthandside,however,willonlyhaveonecopyforeachtupleoftheoriginalsetoftuples.
A+B
A2
B2
1
0
1
5
4
9
1
0
1
6
4
16
7
9
16
B+1
C-1
1
0
3
3
3
4
4
3
1
1
4
3
A
B
0
1
0
1
2
3
2
4
3
4
B
C
0
1
0
2
2
4
2
5
3
4
3
4
A
B
0
1
2
3
2
4
3
4
B
C
0
1
2
4
2
5
3
4
0
2
A
SUM(B)
0
2
2
7
3
4
B
AVG(C)
0
1.5
2
4.5
3
4
A
0
2
3
A
MAX(C)
2
4
A
B
C
2
3
4
2
3
4
0
1
┴
0
1
┴
2
4
┴
3
4
┴
A
B
C
2
3
4
2
3
4
┴
0
1
┴
2
4
┴
2
5
┴
0
2
A
B
C
2
3
4
2
3
4
0
1
┴
0
1
┴
2
4
┴
3
4
┴
┴
0
1
┴
2
4
┴
2
5
┴
0
2
A
R.B
S.B
C
0
1
2
4
0
1
2
5
0
1
3
4
0
1
3
4
0
1
2
4
0
1
2
5
0
1
3
4
0
1
3
4
2
3
┴
┴
2
4
┴
┴
3
4
┴
┴
┴
┴
0
1
┴
┴
0
2
Applyingtheδoperatoronarelationwithnoduplicateswillyieldthesamerelation.Thusδisidempotent.
TheresultofπLisarelationoverthelistofattributesL.PerformingtheprojectionagainwillreturnthesamerelationbecausetherelationonlycontainsthelistofattributesL.ThusπLisidempotent.
TheresultofσCisarelationwhereconditionCissatisfiedbyeverytuple.PerformingtheselectionagainwillreturnthesamerelationbecausetherelationonlycontainstuplesthatsatisfytheconditionC.ThusσCisidempotent.
TheresultofγLisarelationwhoseschemaconsistsofthegroupingattributesandtheaggregatedattributes.Ifweperformthesamegroupingoperation,thereisnoguaranteethattheexpressionwouldmakesense.Thegroupingattributeswillstillappearinthenewresult.However,theaggregatedattributesmayormaynotappearcorrectly.Iftheaggregatedattributeisgivenadifferentnamethantheoriginalattribute,thenperformingγLwouldnotmakesensebecauseitcontainsanaggregationforanattributenamethatdoesnotexist.Inthiscase,theresultingrelationwould,accordingtothedefinition,onlycontainthegroupingattributes.Thus,γLisnotidempotent.
TheresultofτisasortedlistoftuplesbasedonsomeattributesL.IfLisnottheentireschemaofrelationR,thenthereareattributesthatarenotsortedon.IfinrelationRtherearetwotuplesthatagreeinallattributesLanddisagreeinsomeoftheremainingattributesnotinL,thenitisarbitraryastowhichorderthesetwotuplesappearintheresult.Thus,performingtheoperationτmultipletimescanyieldadifferentrelationwherethesetwotuplesareswapped.Thus,τisnotidempotent.
Ifweonlyconsidersets,thenitispossible.WecantakeπA(R)anddoaproductwithitself.Fromthisproduct,wetakethetupleswherethetwocolumnsareequaltoeachother.
Ifweconsiderbagsaswell,thenitisnotpossible.Takethecasewherewehavethetwotuples(1,0)and(1,0).Wewishtoproducearelationthatcontainstuples(1,1)and(1,1).Ifweusetheclassicaloperationsofrelationalalgebra,wecaneithergetaresultwheretherearenotuplesorfourcopiesofthetuple(1,1).Itisnotpossibletogetthedesiredrelationbecausenooperationcandistinguishbetweentheoriginaltuplesandtheduplicatedtuples.Thusitisnotpossibletogettherelationwiththetwotuples(1,1)and(1,1).
Answer(model)←PC(model,speed,_,_,_)ANDspeed≥3.00
Answer(maker)←Laptop(model,_,_,hd,_,_)ANDProduct(maker,model,_)ANDhd≥100
Answer(model,price)←PC(model,_,_,_,price)ANDProduct(maker,model,_)ANDmaker=’B’
Answer(model,price)←Laptop(model,_,_,_,_,price)ANDProduct(maker,model,_)ANDmaker=’B’
Answer(model,price)←Printer(model,_,_,price)ANDProduct(maker,model,_)ANDmaker=’B’
Answer(model)←Printer(model,color,type,_)ANDcolor=’true’ANDtype=’laser’
PCMaker(maker)←Product(maker,_,type)ANDtype=’pc’
LaptopMaker(maker)←Product(maker,_,type)ANDtype=’laptop’
Answer(maker)←LaptopMaker(maker)ANDNOTPCMaker(maker)
Answer(hd)←PC(model1,_,_,hd,_)ANDPC(model2,_,_,hd,_)ANDmodel1<>model2
Answer(model1,model2)←PC(model1,speed,ram,_,_)ANDPC(model2,_speed,ram,_,_)ANDmodel1<model2
FastComputer(model)←PC(model,speed,_,_,_)ANDspeed≥2.80
FastComputer(model)←Laptop(model,speed,_,_,_,_)ANDspeed≥2.80
Answer(maker)←Product(maker,model1,_)ANDProduct(maker,model2,_)ANDFastComputer(model1)ANDFastComputer(model2)ANDmodel1<>model2
Computers(model,speed)←PC(model,speed,_,_,_)
Computers(model,speed)←Laptop(model,speed,_,_,_,_)
SlowComputers(model)←Computers(model,speed)ANDComputers(model1,speed1)ANDspeed<speed1
FastestComputers(model)←Computers(model,_)ANDNOTSlowComputers(model)
Answer(maker)←FastestComputers(model)ANDProduct(maker,model,_)
PCs(maker,speed)←PC(model,speed,_,_,_)ANDProduct(maker,model,_)
Answer(maker)←PCs(maker,speed)ANDPCs(maker,speed1)ANDPCs(maker,speed2)ANDspeed<>speed1ANDspeed<>speed2ANDspeed1<>speed2
PCs(maker,model)←Product(maker,model,type)ANDtype=’pc’
Answer(maker)←PCs(maker,model)ANDPCs(maker,model1)ANDPCs(maker,model2)ANDPCs(maker,model3)ANDmodel<>model1ANDmodel<>model2ANDmodel1<>model2AND(model3=modelORmodel3=model1ORmodel3=model2)
Answer(class,country)←Classes(class,_,country,_,bore,_)ANDbore≥16
Answer(name)←Ships(name,_,launched)ANDlaunched<1921
Answer(ship)←Outcomes(ship,battle,result)ANDbattle=’DenmarkStrait’ANDresult=‘sunk’
Answer(name)←Classes(class,_,_,_,_,displacement)ANDShips(name,class,launched)ANDdisplacement>35000ANDlaunched>1921
Answer(name,displacement,numGuns)←Classes(class,_,_,numGuns,_,displacement)ANDShips(name,class,_)ANDOutcomes(ship,battle,_)ANDbattle=’Guadalcanal’ANDship=name
Answer(name)←Ships(name,_,_)
Answer(name)←Outcomes(name,_,_)ANDNOTAnswer(name)
MoreThanOne(class)←Ships(name,class,_)ANDShips(name1,class,_)ANDname<>name1
Answer(class)←Classes(class,_,_,_,_,_)ANDNOTMoreThanOne(class)
Battleship(country)←Classes(_,type,country,_,_,_)ANDtype=’bb’
Battlecruiser(country)←Classes(_,type,country,_,_,_)ANDtype=’bc’
Answer(country)←Battleship(country)ANDBattlecruiser(country)
Results(ship,result,date)←Battles(name,date)ANDOutcomes(ship,battle,result)ANDbattle=name
Answer(ship)←Results(ship,result,date)ANDResults(ship,_,date1)ANDresult=’damaged’ANDdate<date1
Answer(x,y)←R(x,y)ANDz=z
Answer(a,b,c)←R(a,b,c)
Answer(a,b,c)←S(a,b,c)
Answer(a,b,c)←R(a,b,c)ANDS(a,b,c)
Exercise5.4.1c
Answer(a,b,c)←R(a,b,c)ANDNOTS(a,b,c)
Exercise5.4.1d
Union(a,b,c)←R(a,b,c)
Union(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生产线培训新员工
- 2024儿童用药安全
- 陕西省西安市新城区多校2023-2024学年三年级上学期月考英语试卷
- 电动车消防安全预防电动车火灾培训课件
- 天津市河东区2024-2025学年七年级上学期期中数学试卷(含答案)
- 山东省滨州市博兴县 2024-2025学年八年级上学期11月期中道德与法治试题(含答案)
- 2024-2025学年山东省日照市日照一中高二(上)第一次质检数学试卷(含答案)
- 江苏省苏州市2024-2025学年第一学期初三化学期中模拟测试卷(七)(含解析)
- 福建省南平市延平区多校2024-2025学年四年级上学期期中语文试题
- 信息技术(第2版)(拓展模块) 教案 项目五 Web和FTP服务器的配置与管理
- 植物检疫证书
- 《现代社会调查方法》课件_7
- 微型消防站人员配备
- 甘肃省建筑工程施工图审查要点(共155页)
- 一、身体姿态评估与纠正PPT课件(PPT 24页)
- 样板引路工程施工方案(正弘瓴筑)
- 海澜之家特许经营协议合同
- 大众汽车入侵北美市场
- 网络安全教育培训课件(共30页).ppt
- 建设银行员工劳动合同
- 《艺术创意与创新管理》课程教学大纲
评论
0/150
提交评论