创建序言词汇 [英] Create Prolog Vocabulary

查看:113
本文介绍了创建序言词汇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对序言很陌生,我有一些基本问题...

i am quite new to prolog, and i have some basic questions...

我不知道英语中的词汇"是否正确,但是我需要创建一个描述电子电路的东西.

I dont know if "vocabulary" is the right world in english, but i need to create one to describe an eletronic circuit.

我的问题是,如何创建这些函数以及如何使用"="语句,因为序言似乎并没有接受它.

My problem is, how do i create these functions and how i use the "=" statement since prolog doesnt seems do acept it.

我正在使用SWI Prolog.

Im using SWI Prolog.

(尽我最大的努力翻译成英文)这就是我必须在序言中写的内容:

(tried my best to translate to english)Thats what i have to put in prolog:

确定词汇表(谓词,函数,常量):

Decide the vocabulary (Predicates, functions, constants):

端口由常量(X1,X2,...)–

Ports are represented by constants (X1, X2, ...) –

Gate(X1)

Type(X1)= Xor –类型:AND,OR,XOR或NOT

Type(X1) = Xor – types: AND, OR, XOR or NOT

电路(C1)

Terminals(x)–返回x的输入和输出

Terminals(x) – returns inputs and outputs of x

In(1,X1)–返回X1的第一个输入的函数

In(1, X1) – function that returns first input of X1

Out –返回输出的函数

Out – function that returns output

Arity(c,i,j)–函数,电路c有i个输入和j个输出

Arity(c, i, j) – function, circuit c has i inputs and j outputs

Connected(Out(1,X1),In(1,X2))-连接了两个端口

Connected(Out(1, X1), In(1, X2)) - wich ports are conected

Signal(t)–端子t的信号值.

Signal(t) – signal value for terminal t.

这就是我到目前为止所尝试的.我认为我对"="的处理方式不正确...

Thtas what i tried until now. I dont think my approach to the "=" is right...

gate(x1).
gate(x2).
gate(a1).
gate(a2).
gate(o1).
type(x1, xor).
type(x2, xor).
type(a1, and).
type(a2, and).
type(o1, or).
circuit(c1).

我是否应该使用名为Equal(X,Y)的谓词,例如等于(type(x1),xor).

Should i use an predicate named Equal(X, Y) ?, like "equal (type(x1), xor).

我应该如何实现这些?

Gate(X1) , Type(X1) = XOR
Gate(X2) , Type(X2) = XOR
Gate(A1) , Type(A1) = AND
Gate(A2) , Type(A2) = AND
Gate(O1) , Type(O1) = OR 

我不知道如何从这里继续.我尝试实现这些功能的所有方法似乎都是错误的(请教).

I dont know how to continue from here. All my approachs trying to implement the functions seems to be wrong (cant consult).

推荐答案

您应该阅读

You should read this document to get some inspiration :)

例如,基本的功能(即门)可以描述为

For instance, basic functions (i.e. gates) can be described like

and(0, 0, 0).
and(0, 1, 0).
and(1, 0, 0).
and(1, 1, 1).

xor(0, 0, 0).
...

然后结合起来获得更复杂的构建基块

and then combined to get more complex building blocks

fulladder(A, B, Carryin, Sum, Carryout):-
 xor(A, B, X),
 and(A, B, Y),
 and(X, Carryin, Z),
 xor(Carryin, X, Sum),
 or(Y, Z, Carryout).

计算逻辑功能:

?- fulladder(X, Y, Z, 0, 1).
X = 0, Y = 1, Z = 1 ? ;
X = 1, Y = 0, Z = 1 ? ;
X = 1, Y = 1, Z = 0 ? ;
no

这篇关于创建序言词汇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆