import numpy as np

# Defining a function to compute the intersection of two BCN matrices
def intersection(A, B):
    row, column, memberships, _ = A.shape
    answer = np.zeros_like(A)

    for i in range(row):
        for j in range(column):
            for k in range(memberships):
                amplitude_A, angle_A = A[i,j,k]
                amplitude_B, angle_B = B[i,j,k]

                if k == 0:
                    # Positive truth membership function(alpha+): min amplitude, min angle
                    new_amplitude = min(amplitude_A, amplitude_B)
                    new_angle = min(angle_A, angle_B)
                elif k == 1:
                    # Positive indeterminacy membership function(beta+): max amplitude, max angle
                    new_amplitude = max(amplitude_A, amplitude_B)
                    new_angle = max(angle_A, angle_B)
                elif k == 2:
                    # Positive falsity membership function(gamma+): max amplitude, max angle
                    new_amplitude = max(amplitude_A, amplitude_B)
                    new_angle = max(angle_A, angle_B)
                elif k == 3:
                    # Negative truth membership function(alpha-): max amplitude, max angle
                    new_amplitude = max(amplitude_A, amplitude_B)
                    new_angle = max(angle_A, angle_B)
                elif k == 4:
                    # Negative indeterminacy membership function(beta-): min amplitude, min angle
                    new_amplitude = min(amplitude_A, amplitude_B)
                    new_angle = min(angle_A, angle_B)
                elif k == 5:
                    # Negative falsity membership function(gamma-): min amplitude, min angle
                    new_amplitude = min(amplitude_A, amplitude_B)
                    new_angle = min(angle_A, angle_B)

                answer[i,j,k] = (new_amplitude, new_angle)

    return answer

# Defining the function to display the intersection of the entered maatrices
def print_result(matrix):
    row, column, memberships, _ = matrix.shape
    for i in range(row):
        print("[")
        for j in range(column):
            element = matrix[i,j]
            format = ", ".join([f"{amplitude:.2f}e^{{i.{angle:.2f}}}" for amplitude, angle in element])
            print(f"<{format}>")
        print("]")

# Entering two example matrices
A = np.array([
    [[(0.7, 0.5), (0.6, 1.0), (0.5, 1.2), (-0.6, -1.5), (-0.7, -1.0), (-0.4, -0.5)],
     [(0.8, 0.4), (0.5, 1.1), (0.6, 1.5), (-0.5, -1.7), (-0.6, -1.2), (-0.2, -0.8)],
     [(0.6, 0.6), (0.7, 1.3), (0.5, 1.1), (-0.4, -1.4), (-0.5, -1.1), (-0.3, -0.6)]],
    
    [[(0.5, 0.8), (0.4, 0.9), (0.6, 1.2), (-0.7, -1.2), (-0.6, -1.3), (-0.2, -0.7)],
     [(0.7, 0.7), (0.5, 1.0), (0.8, 1.7), (-0.6, -1.6), (-0.5, -1.0), (-0.4, -0.9)],
     [(0.6, 0.9), (0.6, 1.2), (0.7, 1.3), (-0.5, -1.5), (-0.4, -1.1), (-0.2, -0.8)]],
])

B = np.array([
    [[(0.7, 0.2), (0.1, 1.4), (0.5, 2.0), (-0.3, -1.4), (-0.6, -1.8), (-0.7, -0.3)],
     [(0.1, 0.5), (0.7, 2.0), (0.6, 2.3), (-0.8, -2.5), (-0.2, -2.0), (-0.5, -1.9)],
     [(0.1, 0.9), (0.7, 1.1), (0.9, 1.4), (-0.5, -1.1), (-0.4, -1.3), (-0.3, -1.5)]],
    
    [[(0.2, 2.5), (0.6, 1.0), (0.8, 1.3), (-0.7, -1.3), (-0.5, -1.4), (-0.2, -0.8)],
     [(0.8, 0.7), (0.6, 1.3), (0.7, 2.6), (-0.6, -1.2), (-0.7, -1.2), (-0.3, -0.6)],
     [(0.9, 0.8), (0.7, 1.7), (0.7, 1.3), (-0.8, -1.1), (-0.5, -2.1), (-0.3, -1.7)]]
])

# Assigning the intersection of two matrices to answer
answer = intersection(A, B)

# Calling the function to print the final answer
print("Intersection of the entered bipolar complex neutrosophic matrices is")
print_result(answer)

