c語言怎麼實現求謂詞公式的前束範式

有木有疼人的男生,~913

Ⅱ 用C語言編程:輸入命題公式的合式公式,求出公式的真值表,並輸出該公式的主合取範式和主析取範式

A-Z + is OR * is AND _ is → # is⊕(圓圈裡加個+) @ is ⊙

$ is ↑ 命題的"與非" 運算( "與非門" )

% is ↓ 命題的"或非"運算( "或非門" )

Input the source formula:

A*!S+R

NORMALc: (!A*!B*!R)+(A*!B*!R)+(!A*B*!R)+(A*B*!R)+(!A*!B*R)+(!A*B*R)+(A*B*R)

NORMALd (!A+B+!R)

Error!

Input the source formula:

A#B

Here!

4countTerms

NORMALc: (A*!B)+(!A*B)

NORMALd (A+B)*(!A+!B)

Error!

Input the source formula:

stack<char> stk;

bool isVar(char ch)const;

void addMin(int minterm);

void addMax(int maxterm);

bool compute(int minterm);

void getInversePoland();

int countTerms(int n);

void assign(int minterm);

stack<bool> boolStk;

public:

formulaBase();

formulaBase(const formulaBase& rhs);

~formulaBase();

void getSource();

cout<<"Invalid input !"

"Operate again:"<<endl;

cin>>sourceFormula;*/

}

void formulaBase::getInversePoland()

{

char temp,temp1;

for(int i=0;sourceFormula[i]!='';i++)

stk.pop();

}

else break;

}

stk.push(temp);

break;

case '*':

while (!stk.empty())

//從鍵盤上任意輸入一個主析取範式,輸出與之等值的主合取範式。┐∧∨

# include <iostream>

# include <cmath>

# include <windows.h>

using namespace std ;

(2)範式c語言擴展閱讀:

(1)命題變項是命題公式。

(2)如果A是命題公式,則¬A是命題公式。

(3)如果A和B是命題公式,那麼(A∧B)、(A∨B)、(A→B)和(A↔B)都是命題公式。

(4)當且僅當有限次地應用(1),(2),(3)所得到的包含命題變項,聯結詞和圓括弧的符號串是命題公式。

命題公式的定義是一個遞歸定義形式。命題公式本身不是命題,沒有真值,只有對其命題變項進行賦值後,它才有真值。

5個聯結詞運算兒有不同的優先順序。當它們同時出現在一個命題公式里時,聯結間運算的優先次序為、∧、∨、→、,如果有括弧,則括弧內的運算優先進行。

Ⅲ 命題邏輯推理實踐:求主析取範式,如果有給出成真賦值(C++,C語言都行)急急急!

正好是我這周的作業,順便完成了,經VC++6.0測試,可以運行

Ⅳ 請教:R(A,B,C,D)F={A->B,C->D}屬於幾範式為什麼

我覺得這個是第一範式,應為主鍵是(A,C)組成的組合,當他有一個A或C可以單獨推出另一個非主屬性就是部分依賴,BCNF要(A,C)->B,(A,C)->D這樣才能達到BC範式

Ⅳ 用C或C++編寫程序,要求: 輸入命題公式,給出它的主合取範式和主析取範式。

A-Z + is OR * is AND _ is → # is⊕(圓圈裡加個+) @ is ⊙
$ is ↑ 命題的"與非" 運算( "與非門" )
% is ↓ 命題的"或非"運算( "或非門" )
Input the source formula:
A*!S+R
Here!
8countTerms
NORMALc: (A*!S*!R)+(!A*!S*R)+(A*!S*R)+(!A*S*R)+(A*S*R)
NORMALd (A+S+R)*(A+!S+R)*(!A+!S+R)
!A+S*!R

Input the source formula:
(!A+B)_R
Here!
8countTerms
NORMALc: (!A*!B*!R)+(A*!B*!R)+(!A*B*!R)+(A*B*!R)+(!A*!B*R)+(!A*B*R)+(A*B*R)
NORMALd (!A+B+!R)
Error!

Input the source formula:
A#B
Here!
4countTerms
NORMALc: (A*!B)+(!A*B)
NORMALd (A+B)*(!A+!B)
Error!

Input the source formula:
A@B
Here!
4countTerms
NORMALc: (!A*!B)+(A*B)
NORMALd (!A+B)*(A+!B)
Error!

#include <string>
#include <stack>
#include <vector>
#include<iostream>
using namespace std;
class formulaBase
{
private:
int numVar;//The number of the variables in the formula
bool variables[100];//To store the value of the variables
string sourceFormula;
string normalCFormula;
string normalDFormula;
string alFormula;
vector<char> vctofVar;
vector<char> vctofPoland;
stack<char> stk;
bool isVar(char ch)const;
void addMin(int minterm);
void addMax(int maxterm);
bool compute(int minterm);
void getInversePoland();
int countTerms(int n);
void assign(int minterm);
stack<bool> boolStk;
public:
formulaBase();
formulaBase(const formulaBase& rhs);
~formulaBase();
void getSource();
string generateNormalC();
string generateNormalD();
string getDual();
void printSource()const{cout<<sourceFormula<<endl;}
void printDNormal()const{cout<<normalDFormula<<endl;}
void printCNormal()const{cout<<normalCFormula<<endl;}
void printDual()const{cout<<alFormula<<endl;}
//void printTruthTable();

};
formulaBase::formulaBase()
{
for(int i=0;i<100;i++)variables[i]=false;
numVar=0;
}
formulaBase::formulaBase(const formulaBase& rhs)
{
sourceFormula=rhs.sourceFormula;
for(int i=0;i<100;i++)variables[i]=false;
numVar=0;
}
formulaBase::~formulaBase()
{

while(!stk.empty())stk.pop();
vctofVar.clear();
vctofPoland.clear();
}
int formulaBase::countTerms(int n)
{
if(n==0)
{
cout<<"invalid input!"<<endl;
exit(0);
}
switch(n)
{
case 1:return 2;
case 2:return 4;
default:
{
int tempA=2,tempB=2;
for(int i=2;i<=n;i*=2)tempA*=tempA;
i/=2;
if(i==n)return tempA;
i=n-i;
for(int j=2;j<=i;j*=2)tempB*=tempB;

for(j/=2;j<i;j++)tempB*=2;
tempB*=tempA;
return tempB;
}
}

}
bool formulaBase::isVar(char ch)const
{
if (ch>='A'&&ch<='Z')
return true;
return false;
}
void formulaBase::getSource()
{
cout<<"Input the source formula:"<<endl;
cin>>sourceFormula;
/*if(!isValid(sourceFormula))
cout<<"Invalid input !"
"Operate again:"<<endl;
cin>>sourceFormula;*/

}
void formulaBase::getInversePoland()
{

char temp,temp1;
for(int i=0;sourceFormula[i]!='\0';i++)
{
temp=sourceFormula[i];
if(isVar(temp))
{
if(!variables[temp])
{
numVar++;
vctofVar.push_back(temp);
variables[temp]=true;
}
vctofPoland.push_back(temp);

}
else
switch(temp)
{
case'_':case'$': //
case'%':case'#':
case'@':
while(!stk.empty())
{
if(stk.top()==temp)
{
vctofPoland.push_back(temp);
stk.pop();
}
else break;
}
stk.push(temp);
break;
case '(':case '!':
stk.push(temp);
break;
case '+':
while (!stk.empty())
{
if(stk.top()!='(')
{
temp1=stk.top();
vctofPoland.push_back(temp1);
stk.pop();
}
else break;
}
stk.push(temp);
break;
case '*':
while (!stk.empty())
{
temp1=stk.top();
if(stk.top()=='*'||stk.top()=='!')
{
vctofPoland.push_back(temp1);
stk.pop();
}
else
break;
}
stk.push(temp);
break;

case ')':
while (!stk.empty())
{
if(stk.top()!='(')
{
temp1=stk.top();
vctofPoland.push_back(temp1);
stk.pop();
}
else break;
}
if(stk.empty())exit(0);
stk.pop();//pop the operator '('

break;

}
}
while(!stk.empty())
{
temp1=stk.top();
vctofPoland.push_back(temp1);
stk.pop();
}
}
void formulaBase::assign(int minterm)
{
int temp=minterm;
vector<char>::const_iterator itr=vctofVar.begin();
for(;itr!=vctofVar.end();itr++)
{

variables[*itr]=bool(temp&1);
temp=temp>>1;
}

}

bool formulaBase::compute(int minterm)
{
assign(minterm);
char temp;
bool valueA,valueB;
vector<char>::const_iterator itr=vctofPoland.begin();
while (itr!=vctofPoland.end())
{
temp=*itr;
if(isVar(temp))boolStk.push(variables[temp]);
else
switch(temp)
{
case '+':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=valueA||valueB;
boolStk.push(valueA);

}
break;
case '*':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=valueA&&valueB;
boolStk.push(valueA);

}
break;
case '!':
{
if(boolStk.empty())exit(0);
valueA=!(boolStk.top());
boolStk.pop();
boolStk.push(valueA);

}
break;
case'_':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=(!valueA)||valueB;
boolStk.push(valueA);

}
break;
case'$':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=!(valueA&&valueB);
boolStk.push(valueA);

}
break;
case'%':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=!(valueA||valueB);
boolStk.push(valueA);

}
break;
case'#':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=(!valueA&&valueB)||(valueA&&!valueB);
boolStk.push(valueA);

}
break;
case'@':
{
if(boolStk.size()<2)exit(0);
valueA=boolStk.top();
boolStk.pop();
valueB=boolStk.top();
boolStk.pop();
valueA=(valueA&&valueB)||(!valueA&&!valueB);
boolStk.push(valueA);

}
break;

}
itr++;
}
if(boolStk.size()!=1)
{
cout<<"Error in computing the value of minterm"<<endl;
exit(0);
}
valueA=boolStk.top();
boolStk.pop();
return valueA;

}
void formulaBase::addMin(int minterm)
{
int temp=minterm;
vector<char>::const_iterator itr=vctofVar.begin();
normalCFormula+='(';
while (itr!=vctofVar.end())
{
if(!variables[*itr])
normalCFormula+='!';
normalCFormula+=*itr;
normalCFormula+='*';
itr++;

}
normalCFormula+="\b)+";
}
void formulaBase::addMax(int maxterm)
{
int temp=maxterm;
vector<char>::const_iterator itr=vctofVar.begin();
normalDFormula+='(';
while (itr!=vctofVar.end())
{
if( variables[*itr])
normalDFormula+='!';
normalDFormula+=*itr;
normalDFormula+='+';
itr++;

}
normalDFormula+="\b)*";
}

string formulaBase::generateNormalC()
{
if(vctofPoland.size()==0)//This oeration has not been done yet!
getInversePoland();
cout<<"Here!"<<endl;
int n=countTerms(numVar);
cout<<n<<"countTerms"<<endl;
normalCFormula=' ';
for(int i=0;i<n;i++)
{
if(compute(i))addMin(i);

}
normalCFormula+="\b ";
return normalCFormula;

}
string formulaBase::generateNormalD()
{
if(vctofPoland.size()==0)//This operation has not been done yet!!
getInversePoland();
int n=countTerms(numVar);
normalDFormula=' ';
for(int i=0;i<n;i++)
{
if(!compute(i))addMax(i);
}
normalDFormula+="\b ";
return normalDFormula;

}

string formulaBase::getDual()
{
int i=0;
char temp;
alFormula=' ';
while ((temp=sourceFormula[i])!='\0')
{
switch(temp)
{
case '!':
{
i++;
alFormula+=sourceFormula[i];
break;
}
case '+':alFormula+='*';break;
case '*':alFormula+='+';break;

case'(':case ')':alFormula+=sourceFormula[i];
break;
default:
if (isVar(temp))
{
alFormula+='!';
alFormula+=temp;
}
else
{
cout<<"Error!"<<endl;
exit(0);
}
}
i++;
}
return alFormula;
}
/*void formulaBase::printTruthTable()//A const function is unable to call a nonconst function!!!
{
int i=0;
int count=countTerms(numVar);
cout<<" TRUTH TABLE \n";
for( i=0;i<=numVar;i++)cout<<"___";
cout<<endl;
//for( i=0;i<numVar;i++)cout<<'|'<<vctofVar[i];
//cout<<"|F|" <<endl;
for( i=0;i<=numVar;i++)cout<<"___";
cout<<endl;
for(i=0;i<count;i++ )
{
int temp=i;
for(int j=0;j<numVar;j++)
{
if(bool(temp&1))cout<<"|1";
else cout<<"|0";
temp=temp>>1;
}
if(this->compute(i))cout<<"|1";
else cout<<"|0";
cout<<'|'<<endl;
for( int k=0;k<=numVar;k++)cout<<"___";
cout<<endl;
}

}
*/

int main()
{
string str;
formulaBase f;
f.getSource();
str=f.generateNormalC();
cout<<"NORMALc:"<<str<<endl;
str=f.generateNormalD();
cout<<"NORMALd"<<str<<endl;
// cout<<"Coming here"<<endl;
//f.printTruthTable();
str=f.getDual();
f.printDual();
return 0;
}

Ⅵ AB→C,AC→D,各位大佬這是第幾範式

你好


答案是第二範式

因為有部分依賴


祝你好運

望點贊

Ⅶ 資料庫中的三大範式是什麼

資料庫中三大範式的定義如下:

1、第一範式:

當關系模式R的所有屬性都不能在分解為更基本的數據單位時,稱R是滿足第一範式的,簡記為1NF。滿足第一範式是關系模式規范化的最低要求,否則,將有很多基本操作在這樣的關系模式中實現不了。

2、第二範式:

如果關系模式R滿足第一範式,並且R得所有非主屬性都完全依賴於R的每一個候選關鍵屬性,稱R滿足第二範式,簡記為2NF。

3、第三範式:

設R是一個滿足第一範式條件的關系模式,X是R的任意屬性集,如果X非傳遞依賴於R的任意一個候選關鍵字,稱R滿足第三範式,簡記為3NF。

(7)範式c語言擴展閱讀:

資料庫中引入範式概念的目的:

規范化目的是使結構更合理,消除存儲異常,使數據冗餘盡量小。便於插入、刪除和更新。遵從概念單一化「一事一地」原則,即一個關系模式描述一個實體或實體間的一種聯系。規范的實質就是概念的單一化。

一個關系模式接著分解可以得到不同關系模式集合,也就是說分解方法不是惟一的。最小冗餘的要求必須以分解後的資料庫能夠表達原來資料庫所有信息為前提來實現。

其根本目標是節省存儲空問,避免數據不一致性,提高對關系的操作效率,同時滿足應用需求。實際上,並不一定要求全部模式都達到BCNF不可。有時故意保留部分冗餘可能更方便數據查詢。尤其對於那些更新頻度不高,查詢頻度極高的資料庫系統更是如此。

參考資料來源:網路-資料庫範式

Ⅷ 資料庫中,關系R(A,B,C),函數依賴為F=(AB->C),關系R是第幾範式,為什麼

滿足第三範式
因為:第一範式指每一列都是不可分割的原子數據項,A、B、C都不可再分了。所以滿足第一範式了。
第二範式指要求實體的屬性完全依賴於主關鍵字, C完全依賴AB(沒有A->C、B->C),所以滿足第二範式
第三範式在第二範式的基礎上消除依賴傳遞,上述只有一個依賴關系,所以也滿足第三範式。