AccDiff_p2 - Parts Problem Assume we have a database of...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Parts Problem Assume we have a database of assemblies required for a bike, for example: assembly(bike, [wheel, wheel, frame]). assembly(frame, [rearframe, frontframe]). assembly(frontframe, [fork, handle]). .... basicpart(rearframe). basicpart(fork). .... York University- CSE 3401- V. Movahedi 12 bike wheel hub gears axle bolt nut spoke rim frame frontframe fork handle rearframe 06_AccDiff
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Parts Problem (cont.) To find the parts to assemble a bike, we can write: partsof(X, [X]):- basicpart(X). partsof(X, P):- assembly(X, Subparts), partsofList(Subparts,P). partsofList([], []). partsofList([Head|Tail], P) :- partsof(Head, Headparts), partsofList(Tail, Tailparts), append(Headparts, Tailparts, P). Expensive computation York University- CSE 3401- V. Movahedi 13 06_AccDiff
Background image of page 2
Parts Problem (cont.) We can use an accumulator to avoid extra work: partsof(X, P) :- partsacc(X, [], P). partsacc(X, A, [X|A]) :-
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/14/2012 for the course CSE 3401 taught by Professor Movahedi during the Fall '11 term at York University.

Page1 / 5

AccDiff_p2 - Parts Problem Assume we have a database of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online