Cs7120 (Prasad)L23-1-Applications1 Applications [email protected]
-
Upload
lambert-richard -
Category
Documents
-
view
217 -
download
0
Transcript of Cs7120 (Prasad)L23-1-Applications1 Applications [email protected]
![Page 1: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/1.jpg)
cs7120 (Prasad) L23-1-Applications 1
Applications
http://www.knoesis.org/tkprasad/
![Page 2: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/2.jpg)
cs7120 (Prasad) L23-1-Applications 2
VHDL-Parser Pretty-Printer System
http://www.knoesis.org/tkprasad/
![Page 3: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/3.jpg)
URLs
• Online Parser Documentation– http://www.cs.wright.edu/~tkprasad/VHDL/VH
DL-AMS/START.html
• Public Distribution– http://www.cs.wright.edu/~tkprasad/VHDL/VH
DL-AMS.zip
cs7120 (Prasad) L23-1-Applications 3
![Page 4: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/4.jpg)
cs7120 (Prasad) L23-1-Applications 4
A Meta-Interpreter for circuit Extraction
http://www.knoesis.org/tkprasad/
![Page 5: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/5.jpg)
Outline
• Formal Description of Digital Circuits
• Design Verification
• Motivation for Applying Meta-programming Techniques
• Implementation and Correctness Considerations
• Conclusions
cs7120 (Prasad) L23-1-Applications 5
![Page 6: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/6.jpg)
Hierarchical Description of Circuit Design
cs7120 (Prasad) L23-1-Applications 6
Component
Sub-Components
Gate-level Description
Transistor Netlist
Abstraction
Full-Adder
Half-Adder
AND-OR-NANDGates
CMOS Transistors
![Page 7: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/7.jpg)
Declarative Specification of the Structure: Inverter and Netlist
Single Inverter:
inv(In,Out,X,Y) :-
pt(In,vdd,Out,X,Y),
nt(In,gnd,Out,_,_).
Netlist:
pt(in1,vdd,out1,50,50).
nt(in1,gnd,out1,50,40).
pt(out1,vdd,out2,100,50).
nt(out1,gnd,out2,100,40).
cs7120 (Prasad) L23-1-Applications 7
GND
![Page 8: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/8.jpg)
Problem and Solution Strategy
• Verify structural correctness of a component layout by reverse engineering the top-level design.
• Use automatically generated Prolog extraction rules – Prolog specifications are executable and can be
used to simulate the circuit or check for faults by designing suitable queries
cs7120 (Prasad) L23-1-Applications 8
![Page 9: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/9.jpg)
Circuit Extraction
cs7120 (Prasad) L23-1-Applications 9
MAGIC (CAD Tool) LayoutMAGIC (CAD Tool) Layout
Netlist : Prolog FactsNetlist : Prolog Facts
Higher-level ComponentsHigher-level Components
TRANSLATE
EXTRACT
![Page 10: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/10.jpg)
Extraction Rules in Prolog
extract_inverter :-
pt(In,vdd,Out,X,Y),
nt(In,gnd,Out,_,_),
remove_pt(In,vdd,Out),
remove_nt(In,gnd,Out),
asserta(inverter(In,Out,X,Y)).
cs7120 (Prasad) L23-1-Applications 10
![Page 11: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/11.jpg)
Finer Points
• Retracts not undone on backtracking =>
Identify complete component before retracting
• Retract all occurrences of a component =>
Use “fail” appropriately.
cs7120 (Prasad) L23-1-Applications 11
![Page 12: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/12.jpg)
Spec vs Extraction Template
component :-
subcomponent_1
subcomponent_2.
extract_component :-
subcomponent_1
subcomponent_2,
retract(subcomponent_1),
retract(subcomponent_2),
assert(component),
fail.
cs7120 (Prasad) L23-1-Applications 12
![Page 13: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/13.jpg)
Problem and Our Solution
• Requires generation of customized extraction rules (for each component) explicitly (which causes duplication of information).
• Use meta-programming techniques to perform extraction “on-the-fly” using declarative specification of the structure of the component.
cs7120 (Prasad) L23-1-Applications 13
![Page 14: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/14.jpg)
• Advantage: Avoids explicit creation and storing of extraction rules
• Disadvantage: Meta-interpretation is slower than using customized extraction rules
• Pragmatically: Explicit rules are good for extracting low-level components, while meta-interpreter is good for extracting high-level component extraction
cs7120 (Prasad) L23-1-Applications 14
![Page 15: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/15.jpg)
Meta-Rule
extract(Comp) :-
clause(Comp, Sub_Comps),
Sub_Comps \== true,
call(Sub_Comps),
remove_primitive(Sub_Comps),
asserta(Comp), fail.
extract(_).
cs7120 (Prasad) L23-1-Applications 15
![Page 16: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/16.jpg)
remove_primitive((C1,C2)) :-
!, remove_primitive(C1),
remove_primitive(C2).
remove_primitive(C) :-
clause(C,true), !, retract(C).
remove_primitive(C) :-
clause(C,S_Cs),
remove_primitive(S_Cs).
cs7120 (Prasad) L23-1-Applications 16
![Page 17: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/17.jpg)
(cont’d)
• The interpreter does not work properly if the definition also contains ordinary predicates, written to capture connectivity constraints, position calculations, etc.
• Introduce special meta-predicate constraint as follows:
constraint(Test) : - call(Test).remove_primitive(constraint(_)):-!.
cs7120 (Prasad) L23-1-Applications 17
![Page 18: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/18.jpg)
ExampleinvZ(P,N,I,O,X,Y) :- pt(I,vdd,Q,X1,Y1), pt(P,Q,O,X2,Y2),
nt(N,O,R,X3,Y3), nt(I,R,gnd,X4,Y4),
constraint( \+
connected([Q,R,vdd,gnd])
),
constraint( X is (X1+X2+X3+X4)/4, Y is (Y1+Y2+Y3+Y4)/4
).cs7120 (Prasad) L23-1-Applications 18
![Page 19: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/19.jpg)
Correctness Issue
• Facts and rule-heads are disjoint. The lowest-level is represented as facts. Retraction of facts is sufficient.
• Each fact contributes to just one rule. Subcomponents are not shared.
Retraction of a fact does not interfere with the extraction of other components.
(Stratification of sorts)
cs7120 (Prasad) L23-1-Applications 19
![Page 20: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/20.jpg)
Conclusion
• Meta-interpreter approach uses the declarative specification of a design directly to perform extraction.
• This approach is flexible for higher-level components. The trade-off is that it is inefficient for lower-level components.
cs7120 (Prasad) L23-1-Applications 20
![Page 21: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/21.jpg)
cs7120 (Prasad) L23-1-Applications 21
Meta-Interpreters
Ref: Yoav Shoham’s AI Techniques in Prolog
![Page 22: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/22.jpg)
Types
• Backward Chaining (Top-down)– Depth-first
• Prolog
– Breadth-first
• Forward Chaining (Bottom-up)
• Production Systems
Extensions
• Expert systems • Mycin
• Abductive Reasoning• Diagnosis
• Annotated Logic Programming
cs7120 (Prasad) L23-1-Applications 22
![Page 23: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/23.jpg)
Representing forward chaining rules
op(1000, xfy, ‘,’).
op(1150, xfx, ‘-:’).
p -: q.
r,s -: p.
q -: t.• Forward chaining adds new conclusions
using rules in response to facts of the database and the newly asserted conclusions.
cs7120 (Prasad) L23-1-Applications 23
![Page 24: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/24.jpg)
Membership in and-list
amember(X, (A,B)) :-
!, ( X = A; amember(X,B)).
amember(A,A).
• Recall
op(_, xfy, ‘,’).
cs7120 (Prasad) L23-1-Applications 24
![Page 25: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/25.jpg)
Propagating the effect of facts• Forward chaining interpreter recursively
determines the conclusions forced by the facts and the rules, and asserts them explicitly. – Given the set of rules, each fact is asserted one
by one (using the code shown on the next slide) and the conclusions implied by them are determined.
• Specifically, the head of a rule is asserted after all the literals in the body of the rule have been asserted.
cs7120 (Prasad) L23-1-Applications 25
![Page 26: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/26.jpg)
Propagating the effects of factsupdate(X) :- clause(X, true),!.
update(X) :-
assert(X),
( If -: Then ),
amember(X, If),
\+ ((amember(Y, If),
\+(clause(Y, true)))),
update(Then), fail.
cs7120 (Prasad) L23-1-Applications 26
![Page 27: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/27.jpg)
Propagating the effect of facts• Complexity of update()
• O( number of rules * number of body literals)
• Can be optimized and extended to include negative literals, deletion, and maintaining justifications.
• Reference: Chapter 4 of Yoav Shoham’s AI Techniques in Prolog
cs7120 (Prasad) L23-1-Applications 27
![Page 28: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/28.jpg)
cs7120 (Prasad) L23-1-Applications 28
Pooling of Evidence : The Mycin approach
Ref: Yoav Shoham’s AI Techniques in Prolog
![Page 29: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/29.jpg)
Introducing Certainty Factor
• Facts => CF = 1
• Rules => CF in [0,1]
high_fever. (1)
malaria :- high_fever, recently_in_jungle. (0.8)
malaria :- …
cs7120 (Prasad) L23-1-Applications 29
![Page 30: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/30.jpg)
Mycin Interpretercert(true, 1).
cert( (A,B), C) :- !,
cert(A , C1), cert(B, C2),
comb_fn_serial(C1, C2, C).
cert( A, C) :- !,
findall(CR,
(clause(A,B,CF),
cert(B , CC),
comb_fn_rule(CF,CC,CR)),
CLst),
comb_fn_parallel(CLst, C).
cs7120 (Prasad) L23-1-Applications 30
![Page 31: Cs7120 (Prasad)L23-1-Applications1 Applications t.k.prasad@wright.edu](https://reader038.fdocuments.in/reader038/viewer/2022110206/56649cdf5503460f949a8f11/html5/thumbnails/31.jpg)
Other Static Analysis Tools
• Type Checking/Inferenceappend(list(X), list(X), list(X)).
fact(int, int).
• Mode Inference
append(+,+,_)
cs7120 (Prasad) L23-1-Applications 31