-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Solve simple simultaneous equations
--
-- Solve a number of equations simultaneously. This is not Computer
-- Algebra, better think of a kind of type inference algorithm or logic
-- programming with only one allowed solution.
--
-- Only one solution is computed. Simultaneous equations with multiple
-- solutions are not allowed. However, variables may remain undefined. We
-- do not even check for consistency, since with floating point numbers
-- even simple rules may not be consistent.
--
-- The modules ordered with respect to abstraction level:
--
--
-- - UniqueLogic.ST.System: Construct and solve sets of
-- functional dependencies. Example: assignment3 (+) a b c
-- meaning dependency a+b -> c.
-- - UniqueLogic.ST.Rule: Combine functional dependencies to
-- rules that can apply in multiple directions. Example: add a b
-- c means relation a+b = c which resolves to dependencies
-- a+b -> c, c-a -> b, c-b -> a.
-- - UniqueLogic.ST.Expression: Allow to write rules using
-- arithmetic operators. It creates temporary variables automatically.
-- Example: (a+b)*c =:= d resolves to a+b = x, x*c =
-- d.
--
@package unique-logic
@version 0.2
module UniqueLogic.ST.System
data Variable s a
globalVariable :: ST s (Variable s a)
data M s a
localVariable :: M s (Variable s a)
constant :: a -> M s (Variable s a)
assignment2 :: String -> (a -> b) -> Variable s a -> Variable s b -> M s ()
assignment3 :: String -> (a -> b -> c) -> Variable s a -> Variable s b -> Variable s c -> M s ()
data Apply s a
-- | This function allows to generalize assignment2 and
-- assignment3 to more arguments. You could achieve the same with
-- nested applications of assignment3 (,).
arg :: Variable s a -> Apply s a
runApply :: String -> Apply s a -> Variable s a -> M s ()
solve :: M s a -> ST s a
query :: Variable s a -> ST s (Maybe a)
instance Applicative (Apply s)
instance Functor (Apply s)
instance Monad (M s)
instance Applicative (M s)
instance Functor (M s)
module UniqueLogic.ST.Rule
generic2 :: String -> (b -> a) -> (a -> b) -> Variable s a -> Variable s b -> M s ()
generic3 :: String -> (b -> c -> a) -> (c -> a -> b) -> (a -> b -> c) -> Variable s a -> Variable s b -> Variable s c -> M s ()
equ :: Eq a => Variable s a -> Variable s a -> M s ()
pair :: Variable s a -> Variable s b -> Variable s (a, b) -> M s ()
max :: Ord a => Variable s a -> Variable s a -> Variable s a -> M s ()
add :: Num a => Variable s a -> Variable s a -> Variable s a -> M s ()
mul :: Fractional a => Variable s a -> Variable s a -> Variable s a -> M s ()
square :: Floating a => Variable s a -> Variable s a -> M s ()
pow :: Floating a => Variable s a -> Variable s a -> Variable s a -> M s ()
module UniqueLogic.ST.Expression
-- | An expression is defined by a set of equations and the variable at the
-- top-level. The value of the expression equals the value of the top
-- variable.
data T s a
-- | Make a constant expression of a simple numeric value.
constant :: a -> T s a
fromVariable :: Variable s a -> T s a
fromRule1 :: (Variable s a -> M s ()) -> (T s a)
fromRule2 :: (Variable s a -> Variable s b -> M s ()) -> (T s a -> T s b)
fromRule3 :: (Variable s a -> Variable s b -> Variable s c -> M s ()) -> (T s a -> T s b -> T s c)
data Apply s f
-- | This function allows to generalize fromRule2 and
-- fromRule3 to more arguments using Applicative
-- combinators.
--
-- Example:
--
--
-- fromRule3 rule x y
-- = runApply $ liftA2 rule (arg x) (arg y)
-- = runApply $ pure rule <*> arg x <*> arg y
--
--
-- Building rules with arg provides more granularity than using
-- auxiliary pair rules!
arg :: T s a -> Apply s (Variable s a)
runApply :: Apply s (Variable s a -> M s ()) -> T s a
(=:=) :: Eq a => T s a -> T s a -> M s ()
(=!=) :: Eq a => T s a -> T s a -> T s a
sqr :: Floating a => T s a -> T s a
sqrt :: Floating a => T s a -> T s a
-- | We are not able to implement a full Ord instance including Eq
-- superclass and comparisons, but we need to compute maxima.
max :: Ord a => T s a -> T s a -> T s a
maximum :: Ord a => [T s a] -> T s a
-- | Construct or decompose a pair.
pair :: T s a -> T s b -> T s (a, b)
instance Fractional a => Fractional (T s a)
instance Fractional a => Num (T s a)
instance Applicative (Apply s)
instance Functor (Apply s)