Logic 可以用合金来模拟逻辑门吗

Logic 可以用合金来模拟逻辑门吗,logic,frames,alloy,Logic,Frames,Alloy,我是一个新的合金学习者。我有几件事想知道 是否可以创建一个元素 您将如何为AND逻辑门建模 我的想法是useles是这样的 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

我是一个新的合金学习者。我有几件事想知道

是否可以创建一个元素

您将如何为AND逻辑门建模

我的想法是useles是这样的

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个输入。。。然后在另一个帧中,它生成的输出不是任何输入

提前谢谢


如果有什么我应该读或现在就做这个任务,请说出来。

不清楚你到底想用你的大门实现什么。希望我下面的例子能澄清关于合金的某些事情,并帮助你设计你想要的任何浇口

在这个简单的例子中,有一个抽象的sig表示信号,以及两种不同的具体信号:
One
Zero
。接下来,对抽象门进行建模,使其输入端(ins字段)上有一组信号,输出端(out字段)上只有一个信号。最后,我定义了3个具体的SIG来模拟标准AND、OR和NOT门;对于这些SIG中的每一个,我添加了一个附加事实,以建立在输入和输出上找到的信号之间必须保持的关系(例如,
门的输出是
One
当且仅当其所有输入都是
One
s)

然后我认为展示如何对由几个简单的门组成的更复杂的门进行建模会很有用。我定义了
xorgate
谓词,它断言给定的输入信号(
a
b
)和门(
和1
和2
和not1
not2
或1
)一起构成一个异或门(“连接”如下图所示)

现在,Alloy最好的部分是,您可以使用
run
命令,通过查找满足此谓词的实例来模拟此XOR门。您还可以使用
check
命令来检查此异或门上的所有可能输入,其输出是否为
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

现在还不清楚你到底想用你的大门实现什么。希望我下面的例子能澄清关于合金的某些事情,并帮助你设计你想要的任何浇口

在这个简单的例子中,有一个抽象的sig表示信号,以及两种不同的具体信号:
One
Zero
。接下来,对抽象门进行建模,使其输入端(ins字段)上有一组信号,输出端(out字段)上只有一个信号。最后,我定义了3个具体的SIG来模拟标准AND、OR和NOT门;对于这些SIG中的每一个,我添加了一个附加事实,以建立在输入和输出上找到的信号之间必须保持的关系(例如,
门的输出是
One
当且仅当其所有输入都是
One
s)

然后我认为展示如何对由几个简单的门组成的更复杂的门进行建模会很有用。我定义了
xorgate
谓词,它断言给定的输入信号(
a
b
)和门(
和1
和2
和not1
not2
或1
)一起构成一个异或门(“连接”如下图所示)

现在,Alloy最好的部分是,您可以使用
run
命令,通过查找满足此谓词的实例来模拟此XOR门。您还可以使用
check
命令来检查此异或门上的所有可能输入,其输出是否为
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

现在还不清楚你到底想用你的大门实现什么。希望我下面的例子能澄清关于合金的某些事情,并帮助你设计你想要的任何浇口

在这个简单的例子中,有一个抽象的sig表示信号,以及两种不同的具体信号:
One
Zero
。接下来,对抽象门进行建模,使其输入端(ins字段)上有一组信号,输出端(out字段)上只有一个信号。最后,我定义了3个具体的SIG来模拟标准AND、OR和NOT门;对于这些SIG中的每一个,我添加了一个附加事实,以建立在输入和输出上找到的信号之间必须保持的关系(例如,
门的输出是
One
当且仅当其所有输入都是
One
s)

然后我认为展示如何对由几个简单的门组成的更复杂的门进行建模会很有用。我定义了
xorgate
谓词,它断言给定的输入信号(
a
b
)和门(
和1
和2
和not1
not2
或1
)一起构成一个异或门(“连接”如下图所示)

现在,Alloy最好的部分是,您可以使用
run
命令,通过查找满足此谓词的实例来模拟此XOR门。您还可以使用
check
命令来检查此异或门上的所有可能输入,其输出是否为
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

现在还不清楚你到底想用你的大门实现什么。希望我下面的例子能澄清一些关于合金的事情,并帮助你设计