import numpy as np

# Function to find the complement of entered BCNM:
def complement(A):
    row, column, membership, _ = A.shape
    answer = np.zeros_like(A)

    for i in range(row):
        for j in range(column):
            element = A[i, j]

            # Complement of positive truth membership(alpha+) is (gamma+)
            answer[i,j,0,0] = element[2,0]  # gamma+ amplitude
            answer[i,j,0,1] = (2*np.pi - element[0,1])  # Angle complement

            # Complement of positive indeterminacy membership(beta+)  is (1 - beta+)
            answer[i,j,1,0] = 1 - element[1,0]
            answer[i,j,1,1] = (2*np.pi - element[1,1])  # Angle complement 

            # Complement of positive falsity membership(gamma+) is (alpha+)
            answer[i,j,2,0] = element[0,0]  # alpha+ amplitude
            answer[i,j,2,1] = (2*np.pi - element[2,1])  # Angle complement

            # Complement of negative truth membership(alpha-) is (gamma-)
            answer[i,j,3,0] = element[5,0]  # gamma- amplitude
            answer[i,j,3,1] = (-2*np.pi - element[3,1])  # Angle complement

            # Complement of negative indeterminacy membership(beta-) is (1 - beta-)
            answer[i,j,4,0] = 1 - element[4,0]
            answer[i,j,4,1] = (-2*np.pi - element[4,1])  # Angle complement

            # Complement of negative falsity membership(gamma-) is (alpha-)
            answer[i,j,5,0] = element[3,0]  # alpha- amplitude
            answer[i,j,5,1] = (-2*np.pi - element[5,1])  # Angle complement

    return answer

# Defining the function to print the complement of the entered matrix 
def print_answer(matrix):
    row, column, component, _ = 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("]")

# Inputting an example BCNM

A = np.array([
    [
        [(0.5, 2.2), (0.7, 1.8), (0.3, 2.1), (-0.4, -1.2), (-0.8, -2.5), (-0.4, -1.9)],
        [(0.8, 1.0), (0.2, 1.6), (0.6, 3.0), (-0.8, -1.0), (-0.5, -1.8), (-0.4, -2.0)],
        [(0.4, 1.2), (0.9, 1.7), (0.4, 2.6), (-0.4, -1.3), (-0.3, -1.4), (-0.3, -1.6)]
    ],
    [
        [(0.6, 1.6), (0.9, 1.5), (0.2, 2.4), (-0.4, -1.2), (-0.9, -1.7), (-0.3, -1.7)],
        [(0.4, 1.0), (0.6, 1.4), (0.9, 2.1), (-0.4, -1.1), (-0.8, -1.4), (-0.3, -1.9)],
        [(0.9, 1.2), (0.4, 1.8), (0.7, 2.1), (-0.1, -1.4), (-0.6, -1.4), (-0.4, -1.4)]
    ],
    [
        [(0.4, 2.0), (0.7, 1.6), (0.4, 2.2), (-0.2, -1.3), (-0.4, -1.7), (-0.9, -1.5)],
        [(0.8, 1.1), (0.6, 1.2), (0.5, 1.0), (-0.6, -1.5), (-0.6, -1.4), (-0.4, -1.6)],
        [(0.4, 1.2), (0.5, 1.9), (0.6, 2.3), (-0.2, -1.5), (-0.4, -1.6), (-0.4, -1.7)]
    ]
])

# Calling the function to print the complement of the entered matrix
print("The complement of the entered Bipolar Complex Neutrosophic Matrix is")
print_answer(complement(A))
