#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 13 20:17:53 2021

@author: Cristian Magalhães
João Marcos
Matheus Lopes
William Francisco Machado
"""

# AND

import numpy as np

def degrau(v):
    if v >=0:
        return 1
    else:
        return 0

def perceptron(x, w, b):
    v = np.dot(w, x) + b
    y = degrau(v)
    return y

def AND(x): 
    w = np.array([1,1]) 
    bAND = -1.5 
    return perceptron(x, w, bAND) 

x0 = np.array([0,1]) 
x1 = np.array([1,1]) 
x2 = np.array([0,0]) 
x3 = np.array([1,0]) 

print("AND ({} + {}) = {}".format(0,1, AND(x0))) 
print("AND ({} + {}) = {}".format(1,1, AND(x1))) 
print("AND ({} + {}) = {}".format(0,0, AND(x2))) 
print("AND ({} + {}) = {}".format(1,0, AND(x3)))

print("----------------------------------------------------------------------")

# OR
# -*- coding: utf-8 -*- 

import numpy as np 

def degrau(v): 
    if v >=0: 
        return 1 
    else: 
        return 0 

def perceptron(x, w, b): 
    v = np.dot(w, x) + b  
    y = degrau(v)
    return y 

def OR(x): 
    w = np.array([1,1]) 
    b = -0.5
    return perceptron(x, w, b) 
  
x0 = np.array([0,1]) 
x1 = np.array([1,1]) 
x2 = np.array([0,0]) 
x3 = np.array([1,0]) 

print("OR ({} + {}) = {}".format(0,1, OR(x0))) 
print("OR ({} + {}) = {}".format(1,1, OR(x1))) 
print("OR ({} + {}) = {}".format(0,0, OR(x2))) 
print("OR ({} + {}) = {}".format(1,0, OR(x3)))

print("----------------------------------------------------------------------")


# NOR

import numpy as np 
  
def degrau(v): 
    if v >=0: 
        return 1 
    else:
        return 0 

def perceptron(x, w, b): 
    v = np.dot(w, x) + b  
    y = degrau(v) 
    return y 

def NOT(x): 
    wNOT = -1.0 
    bNOT = 0.5 
    return perceptron(x, wNOT, bNOT) 

def OR(x): 
    w = np.array([1,1]) 
    b = -0.5 
    return perceptron(x, w, b) 

def NOR(x): 
    output_OR = OR(x) 
    output_NOT = NOT(output_OR) 
    return output_NOT 

x0 = np.array([0,1]) 
x1 = np.array([1,1]) 
x2 = np.array([0,0]) 
x3 = np.array([1,0]) 

print("NOR ({} + {}) = {}".format(0,1, NOR(x0))) 
print("NOR ({} + {}) = {}".format(1,1, NOR(x1))) 
print("NOR ({} + {}) = {}".format(0,0, NOR(x2))) 
print("NOR ({} + {}) = {}".format(1,0, NOR(x3))) 

print("----------------------------------------------------------------------")
# NAND

# -*- coding: utf-8 -*- 

import numpy as np 

def degrau(v): 
    if v >=0: 
        return 1 
    else: 
        return 0 

def perceptron(x, w, b): 
    v = np.dot(w, x) + b  
    y = degrau(v) 
    return y 

def NOT(x): 
    wNOT = -1.0 
    bNOT = 0.5 
    return perceptron(x, wNOT, bNOT) 

def AND(x): 
    w = np.array([1,1]) 
    bAND = -1.5 
    return perceptron(x, w, bAND) 

def NAND(x): 
    output_AND = AND(x) 
    output_NOT = NOT(output_AND) 
    return output_NOT 
  
x0 = np.array([0,1]) 
x1 = np.array([1,1]) 
x2 = np.array([0,0]) 
x3 = np.array([1,0]) 
  
print("NAND ({} + {}) = {}".format(0,1, NAND(x0)))
print("NAND ({} + {}) = {}".format(1,1, NAND(x1)))
print("NAND ({} + {}) = {}".format(0,0, NAND(x2)))
print("NAND ({} + {}) = {}".format(1,0, NAND(x3)))
