簡體   English   中英

是否可以對合金中的邏輯門建模

[英]is it possible to model a logic gate in alloy

我是一名新的Alloy學習者。 我想知道幾件事。

是否可以創建元素?

您將如何對AND邏輯門建模?

我的想法是用油菜是這樣的

open util/ordering[Time]
sig Time {frame: set gate}


abstract sig gate{}
sig ABinCout extends gate{ 
getA    : A,
getB    : B,
outputsC    : C,
} 


abstract sig Signals {}
sig A extends Signals{}
sig B extends Signals{}
sig C extends Signals{}


fact{first.frame = gate && no gate.getA && no gate.getB && no gate.outputsC } 

pred GateAB [t,t' : set Time,Gate : ABinCout]{
one a : A  | one b : B | {
Gate.getA = Gate.getA + a 
Gate.getB = Gate.getB + b
}}

pred GateABparaC [Gate : set ABinCout]{
one a : Gate.getA | one b : Gate.getB | one c : C{
    Gate.getA = Gate.getA - a
    Gate.getB = Gate.getB - b
    Gate.outputsC = Gate.outputsC + c

}}

pred GateC [Gate : set ABinCout]{
one c : Gate.outputsC | {
    Gate.outputsC =Gate.outputsC - c
}}

fact{
all t : Time, t' : t.next | one cel: ABinCout{
 GateAB[t,t',cel]
}}


run{ }for exactly 2 Time, 1 ABinCout, 3 A, 3 B, 1 C 

我可以從字面上說我對合金一無所知,但我想單獨代表門...然后生成2個輸入...然后在另一個幀中它生成的輸出不是任何輸入!

提前致謝

如果有什么我應該閱讀或現在要執行此任務的,請說出來。

目前尚不清楚您到底想達到什么目的。 希望我下面的示例將闡明有關Alloy的某些內容,並幫助您設計所需的任何澆口。

在這個簡單的示例中,有一個抽象信號代表信號,正好是兩種不同的具體信號: OneZero 接着,一個抽象的柵極被建模為具有一組在其輸入端的信號(在ins在其輸出(場)和正好一個信號out場)。 最后,我定義了3個對標准AND,OR和NOT門建模的具體信號。 為每個SIGS的我增加了一個附加的事實來建立那些必須在輸入和輸出中發現的信號之間保持的關系(例如,一個輸出AND門是One當且僅當所有的其輸入是One或多個) 。

然后,我認為展示如何建模由幾個簡單的門組成的更復雜的門將很有用。 我所定義的xorgate謂詞,它斷言給定的輸入信號( ab )和柵極( and1and2not1not2or1 )一起形成一個異或門(“連接”如在下面的圖片)

AND,NOT和OR門的XOR門

現在,有關Alloy的最好的部分是您可以擁有一個run命令,該命令將通過查找滿足該謂詞的實例來模擬此XOR門。 您還可以有一個check命令,該命令檢查並且僅當輸入不同時(對於XOR門而言應如此),對於此XOR門上的所有可能輸入,其輸出均為One 在Alloy中執行此檢查不會找到反例。

abstract sig Signal {}
one sig One extends Signal {}
one sig Zero extends Signal {}

abstract sig Gate {
  ins: set Signal,
  out: one Signal
} 

sig AND extends Gate {}{ out = One iff ins in One }
sig OR  extends Gate {}{ out = Zero iff ins in Zero }
sig NOT extends Gate {}{ #ins = 1 and out = Signal - ins }

pred xorgate[a, b: Signal, and1, and2: AND, not1, not2: NOT, o1: OR] {
  not1.ins = a
  and1.ins = b + not1.out
  not2.ins = b
  and2.ins = a + not2.out
  or1.ins = and1.out + and2.out
}

run xorgate for 5

check {
  all in1, in2: Signal |
    all a1, a2: AND, n1, n2: NOT, o1: OR {
      xorgate[in1, in2, a1, a2, n1, n2, o1] implies (o1.out = One iff in1 != in2)
    }
} for 5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM