module Formas where import Asignaciones import Formula import Evaluar -- fnc de O(n) fnc :: Formula -> String fnc f = if (forma == "") then head(atomicas):[] ++ " | ~ " ++ head(atomicas):[] else forma where forma = (fnc' Vacio (atomicas) f) atomicas = reverse (obtenerAtomicas f) fnc' :: LVar_prop -> [Atomica] -> Formula -> String fnc' lista [] f | ((evaluar lista f) == Falso) = "( " ++ printFnc (lista) ++ ")" | otherwise = "" fnc' lista (x:xs) f = if ((&&) (f1 == []) (f2 == [])) then "" else if (f1 == []) then f2 else if (f2 == []) then f1 else f1 ++ " & " ++ f2 where f1 = (fnc' (Nodo Verdadero x lista) xs f) f2 = (fnc' (Nodo Falso x lista) xs f) printFnc :: LVar_prop -> String printFnc (Vacio) = "" printFnc lista = (printFnc' lista) printFnc' :: LVar_prop -> [Char] printFnc' (Vacio) = "" printFnc' (Nodo v a sig) | v == Falso = if (sig /= Vacio) then a : " | " ++ (printFnc' sig) else a : (printFnc' sig) | otherwise = if (sig /= Vacio) then "~ " ++ a : " | " ++ (printFnc' sig) else "~ " ++ a : (printFnc' sig) ---------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------- -- fnd de O(n) fnd :: Formula -> String fnd f = if (forma == "") then head(atomicas):[] ++ " | ~ " ++ head(atomicas):[] else forma where forma = (fnd' Vacio (atomicas) f) atomicas = reverse (obtenerAtomicas f) fnd' :: LVar_prop -> [Atomica] -> Formula -> String fnd' lista [] f | ((evaluar lista f) == Verdadero) = "( " ++ printFnd (lista) ++ ")" | otherwise = "" fnd' lista (x:xs) f = if ((&&) (f1 == []) (f2 == [])) then "" else if (f1 == []) then f2 else if (f2 == []) then f1 else f1 ++ " | " ++ f2 where f1 = (fnd' (Nodo Verdadero x lista) xs f) f2 = (fnd' (Nodo Falso x lista) xs f) printFnd :: LVar_prop -> String printFnd (Vacio) = "" printFnd lista = (printFnd' lista) printFnd' :: LVar_prop -> [Char] printFnd' (Vacio) = "" printFnd' (Nodo v a sig) | v == Verdadero = if (sig /= Vacio) then a : " & " ++ (printFnd' sig) else a : (printFnd' sig) | otherwise = if (sig /= Vacio) then "~ " ++ a : " & " ++ (printFnd' sig) else "~ " ++ a : (printFnd' sig)