module Transformations
( tr
, phi
, theta
, projection
, ideal) where
import Logic
import Haskell4Maths (Vect(..)
, var
, vars
, mindices
, eval
, linear
, (%%))
import F2 (PolF2)
import Test.QuickCheck (quickCheck
, maxSize
, quickCheckWith
, stdArgs)
tr :: FProp -> PolF2
tr T = 1
tr F = 0
tr (Atom ('p':xs)) = var ('x':xs)
tr (Atom xs) = var xs
tr (Neg a) = 1 + tr a
tr (Conj a b) = tr a * tr b
tr (Disj a b) = a' + b' + a' * b'
where a' = tr a
b' = tr b
tr (Impl a b) = 1 + a' + a' * tr b
where a' = tr a
tr (Equi a b) = 1 + tr a + tr b
theta :: PolF2 -> FProp
theta 0 = F
theta 1 = T
theta (V [m]) = (theta' . mindices . fst) m
theta (V (x:xs)) = no (((theta' . mindices . fst) x) ↔ (theta (V xs)))
theta' :: [(String, t)] -> FProp
theta' [] = T
theta' [(('x':v),i)] = Atom ('p':v)
theta' ((('x':v),i):vs) = Conj (Atom ('p':v)) (theta' vs)
theta' [(v,i)] = Atom v
theta' ((v,i):vs) = Conj (Atom v) (theta' vs)
phi :: PolF2 -> PolF2
phi = linear (\m -> product [ var x | (x,i) <- mindices m])
ideal :: PolF2 -> [PolF2]
ideal p = [v+v^2| v<-vars p]
projection :: FProp -> PolF2
projection = phi . tr