moving to FnT

This commit is contained in:
RustyRaptor committed 2019-09-09 16:28:10 -06:00
1 parent 08d0924b6a
commit 67db7b83e9
4 files changed
+189 -49

No files matched your search

Executable
BIN
View File
Binary file not shown.
+48 -49
View File
@@ -1,5 +1,5 @@
#include <stdio.h>
#include <stdbool.h>
// #include <stdchar.h>
/*
* Tell the compiler that we intend
@@ -10,76 +10,75 @@
*/
void show_message(void);
bool not(bool var);
bool or(bool l, bool r);
bool and(bool l, bool r);
bool implies(bool l, bool r);
bool prop1(bool p, bool q, bool r);
bool prop2(bool p, bool q, bool r);
bool prop3(bool p, bool q, bool r);
bool prop4(bool p, bool q, bool r);
char not(char var);
char or(char l, char r);
char and(char l, char r);
char implies(char l, char r);
char prop1(char p, char q, char r);
char prop2(char p, char q, char r);
char prop3(char p, char q, char r);
char prop4(char p, char q, char r);
/*
* Another function, but this includes the body of
* the function. This is a "definition".
*/
int main(){
not(false);
or(false, true);
and(true, true);
implies(true, false);
bool truth[8][3+4];
not('F');
or('F', 'T');
and('T', 'T');
implies('T', 'F');
char truth[8][3+4];
// generate p
for(int i = 0; i < 8; i++){
if(i < 4){
truth[i][0] = false;
truth[i][0] = 'F';
}else{
truth[i][0] = true;
truth[i][0] = 'T';
}
}
for(int i = 0; i < 8; i++){
printf(truth[i][0] ? "true\n" : "false\n");
printf(truth[i][0] ? "'T'\n" : "'F'\n");
}
printf("new\n");
bool tick = false;
char tick = 'F';
for(int i = 0; i < 8; i++) {
truth[i][1] = tick;
if (i % 2 != 0&&i != 0){
tick = !tick;
tick = not(tick);
}
}
tick = false;
tick = 'F';
for(int i = 0; i < 8; i++) {
truth[i][2] = tick;
tick = !tick;
truth[i][2] = not(tick);
}
for(int i = 0; i < 8; i++){
printf(truth[i][1] ? "true\n" : "false\n");
printf(truth[i][1] ? "'T'\n" : "'F'\n");
}
for(int i = 0; i < 8; i++){
truth[i][3] = prop1(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "a'T'\n" : "a'F'\n");
}
for(int i = 0; i < 8; i++){
truth[i][4] = prop2(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "a'T'\n" : "a'F'\n");
}
for(int i = 0; i < 8; i++){
truth[i][5] = prop2(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "a'T'\n" : "a'F'\n");
}
for(int i = 0; i < 8; i++){
truth[i][6] = prop3(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "a'T'\n" : "a'F'\n");
}
for(int i = 0; i < 8; i++){
truth[i][7] = prop4(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "a'T'\n" : "a'F'\n");
}
@@ -88,7 +87,7 @@ int main(){
for(int i = 0; i<8; i++){
printf("\n");
for(int j = 0; j<(3+4); j++){
printf(truth[i][j] ? "T\t" : "F\t");
printf("%c\t", truth[i][j]);
}
}
return(0);
@@ -99,43 +98,43 @@ int main(){
* This is now a "definition".
*/
bool not(bool var){
if(var){
return (false);
char not(char var){
if(var == 'T'){
return ('F');
}else{
return (true);
return ('T');
}
}
bool or(bool l, bool r){
if(l||r){
return (true);
char or(char l, char r){
if (l == 'T'|| r == 'T'){
return ('T');
}else{
return (false);
return ('F');
}
}
bool and(bool l, bool r){
if(l&&r){
return (true);
char and(char l, char r){
if (l == 'T' && r == 'T'){
return ('T');
}else{
return (false);
return ('F');
}
}
bool implies(bool l, bool r){
if( l<=r){
return (true);
char implies(char l, char r){
if ((l == 'T' && r == 'T') || (l == 'F' && r == 'T')){
return ('T');
}else{
return(false);
return('F');
}
}
bool prop1(bool p, bool q, bool r){
char prop1(char p, char q, char r){
return and(implies(not(p), q), implies(r, p));
}
bool prop2(bool p, bool q, bool r){
char prop2(char p, char q, char r){
return and(or(p, not(q)), or(r, not(implies(p,q))));
}
bool prop3(bool p, bool q, bool r) {
char prop3(char p, char q, char r) {
return implies(implies(p,not(and(p, not(q)))), and(p, q));
}
bool prop4(bool p, bool q, bool r) {
char prop4(char p, char q, char r) {
return and(and(p, implies(p,q)), not(q));
}
Executable
BIN
View File
Binary file not shown.
+141
View File
@@ -0,0 +1,141 @@
#include <stdio.h>
#include <stdbool.h>
/*
* Tell the compiler that we intend
* to use a function called show_message.
* It has no arguments and returns no value
* This is the "declaration".
*
*/
void show_message(void);
bool not(bool var);
bool or(bool l, bool r);
bool and(bool l, bool r);
bool implies(bool l, bool r);
bool prop1(bool p, bool q, bool r);
bool prop2(bool p, bool q, bool r);
bool prop3(bool p, bool q, bool r);
bool prop4(bool p, bool q, bool r);
/*
* Another function, but this includes the body of
* the function. This is a "definition".
*/
int main(){
not(false);
or(false, true);
and(true, true);
implies(true, false);
bool truth[8][3+4];
// generate p
for(int i = 0; i < 8; i++){
if(i < 4){
truth[i][0] = false;
}else{
truth[i][0] = true;
}
}
for(int i = 0; i < 8; i++){
printf(truth[i][0] ? "true\n" : "false\n");
}
printf("new\n");
bool tick = false;
for(int i = 0; i < 8; i++) {
truth[i][1] = tick;
if (i % 2 != 0&&i != 0){
tick = !tick;
}
}
tick = false;
for(int i = 0; i < 8; i++) {
truth[i][2] = tick;
tick = !tick;
}
for(int i = 0; i < 8; i++){
printf(truth[i][1] ? "true\n" : "false\n");
}
for(int i = 0; i < 8; i++){
truth[i][3] = prop1(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
}
for(int i = 0; i < 8; i++){
truth[i][4] = prop2(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
}
for(int i = 0; i < 8; i++){
truth[i][5] = prop2(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
}
for(int i = 0; i < 8; i++){
truth[i][6] = prop3(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
}
for(int i = 0; i < 8; i++){
truth[i][7] = prop4(truth[i][0], truth[i][1], truth[i][2]);
printf(prop1(truth[i][0], truth[i][1], truth[i][2]) ? "atrue\n" : "afalse\n");
}
for(int i = 0; i<8; i++){
printf("\n");
for(int j = 0; j<(3+4); j++){
printf(truth[i][j] ? "T\t" : "F\t");
}
}
return(0);
}
/*
* The body of the simple function.
* This is now a "definition".
*/
bool not(bool var){
if(var){
return (false);
}else{
return (true);
}
}
bool or(bool l, bool r){
if(l||r){
return (true);
}else{
return (false);
}
}
bool and(bool l, bool r){
if(l&&r){
return (true);
}else{
return (false);
}
}
bool implies(bool l, bool r){
if( l<=r){
return (true);
}else{
return(false);
}
}
bool prop1(bool p, bool q, bool r){
return and(implies(not(p), q), implies(r, p));
}
bool prop2(bool p, bool q, bool r){
return and(or(p, not(q)), or(r, not(implies(p,q))));
}
bool prop3(bool p, bool q, bool r) {
return implies(implies(p,not(and(p, not(q)))), and(p, q));
}
bool prop4(bool p, bool q, bool r) {
return and(and(p, implies(p,q)), not(q));
}