-- 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 are:
--
--
-- - 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. For an executable
-- example see UniqueLogic.ST.Example.Rule.
-- - UniqueLogic.ST.Expression: Allows to write rules using
-- arithmetic operators. It creates temporary variables automatically.
-- Example: (a+b)*c =:= d resolves to a+b = x, x*c = d.
-- For an executable example see
-- UniqueLogic.ST.Example.Expression.
-- - UniqueLogic.ST.SystemLabel: Provides a new type for named
-- variables. When creating a variable you decide whether and how an
-- assignment to this variable shall be logged. There is an example that
-- shows how to solve a logic system using symbolic expressions. The
-- naming and logging allows us to observe shared intermediate results.
-- For an executable example see
-- UniqueLogic.ST.Example.Label.
-- - UniqueLogic.ST.SystemLog, UniqueLogic.ST.RuleLog:
-- These modules allow to log an assignment depending on the arguments to
-- an assignment. This is more general than
-- UniqueLogic.ST.SystemLabel which allows only dependencies on
-- the result of an assignment.
--
@package unique-logic
@version 0.3
module UniqueLogic.ST.SystemLog
data Variable w s a
globalVariable :: ST s (Variable w s a)
data T w s a
localVariable :: T w s (Variable w s a)
constant :: a -> T w s (Variable w s a)
assignment2 :: Monoid w => (a -> Writer w b) -> Variable w s a -> Variable w s b -> T w s ()
assignment3 :: Monoid w => (a -> b -> Writer w c) -> Variable w s a -> Variable w s b -> Variable w s c -> T w s ()
data Apply w s a
-- | This function allows to generalize assignment2 and
-- assignment3 to more arguments. You could achieve the same with
-- nested applications of assignment3 (,).
arg :: Monoid w => Variable w s a -> Apply w s a
runApply :: Monoid w => Apply w s (Writer w a) -> Variable w s a -> T w s ()
solve :: Monoid w => T w s a -> WriterT w (ST s) a
query :: Variable w s a -> ST s (Maybe a)
instance Monoid w => Applicative (Apply w s)
instance Monoid w => Functor (Apply w s)
instance Monad (T w s)
instance Applicative (T w s)
instance Functor (T w s)
module UniqueLogic.ST.RuleLog
generic2 :: Monoid w => (b -> Writer w a) -> (a -> Writer w b) -> Variable w s a -> Variable w s b -> T w s ()
generic3 :: Monoid w => (b -> c -> Writer w a) -> (c -> a -> Writer w b) -> (a -> b -> Writer w c) -> Variable w s a -> Variable w s b -> Variable w s c -> T w s ()
module UniqueLogic.ST.System
class Var var
plainVariable :: Var var => var w s a -> Variable w s a
runApply :: (Var var, Monoid w) => Apply w s a -> var w s a -> T w s ()
constant :: (Var var, Monoid w) => a -> T w s (var w s a)
localVariable :: (Var var, Monoid w) => T w s (var w s a)
data Variable w s a
globalVariable :: ST s (Variable w s a)
data T w s a
assignment2 :: (Var var, Monoid w) => (a -> b) -> var w s a -> var w s b -> T w s ()
assignment3 :: (Var var, Monoid w) => (a -> b -> c) -> var w s a -> var w s b -> var w s c -> T w s ()
data Apply w s a
arg :: (Var var, Monoid w) => var w s a -> Apply w s a
solve :: T () s a -> ST s a
query :: (Var var, Monoid w) => var w s a -> ST s (Maybe a)
instance Var Variable
module UniqueLogic.ST.SystemLabel
data Variable w s a
globalVariable :: (a -> Writer w a) -> ST s (Variable w s a)
data T w s a
localVariable :: (Var var, Monoid w) => T w s (var w s a)
constant :: (Var var, Monoid w) => a -> T w s (var w s a)
assignment2 :: (Var var, Monoid w) => (a -> b) -> var w s a -> var w s b -> T w s ()
assignment3 :: (Var var, Monoid w) => (a -> b -> c) -> var w s a -> var w s b -> var w s c -> T w s ()
data Apply w s a
arg :: (Var var, Monoid w) => var w s a -> Apply w s a
runApply :: (Var var, Monoid w) => Apply w s a -> var w s a -> T w s ()
solve :: Monoid w => T w s a -> WriterT w (ST s) a
query :: (Var var, Monoid w) => var w s a -> ST s (Maybe a)
instance Var Variable
module UniqueLogic.ST.Rule
generic2 :: (Var var, Monoid w) => (b -> a) -> (a -> b) -> var w s a -> var w s b -> T w s ()
generic3 :: (Var var, Monoid w) => (b -> c -> a) -> (c -> a -> b) -> (a -> b -> c) -> var w s a -> var w s b -> var w s c -> T w s ()
equ :: (Var var, Monoid w) => var w s a -> var w s a -> T w s ()
-- | You might be tempted to use the pair rule to collect parameters
-- for rules with more than three arguments. This is generally not a good
-- idea since this way you lose granularity. For building rules with more
-- than three arguments, please build according assignments with
-- arg and runApply and bundle these assignments to rules.
-- This is the way, generic2 and generic3 work.
pair :: (Var var, Monoid w) => var w s a -> var w s b -> var w s (a, b) -> T w s ()
max :: (Ord a, Var var, Monoid w) => var w s a -> var w s a -> var w s a -> T w s ()
add :: (Num a, Var var, Monoid w) => var w s a -> var w s a -> var w s a -> T w s ()
mul :: (Fractional a, Var var, Monoid w) => var w s a -> var w s a -> var w s a -> T w s ()
square :: (Floating a, Var var, Monoid w) => var w s a -> var w s a -> T w s ()
pow :: (Floating a, Var var, Monoid w) => var w s a -> var w s a -> var w s a -> T w 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 var w s a
-- | Make a constant expression of a simple numeric value.
constant :: (Var var, Monoid w) => a -> T var w s a
fromVariable :: var w s a -> T var w s a
fromRule1 :: (Var var, Monoid w) => (var w s a -> T w s ()) -> (T var w s a)
fromRule2 :: (Var var, Monoid w) => (var w s a -> var w s b -> T w s ()) -> (T var w s a -> T var w s b)
fromRule3 :: (Var var, Monoid w) => (var w s a -> var w s b -> var w s c -> T w s ()) -> (T var w s a -> T var w s b -> T var w s c)
data Apply w 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 var w s a -> Apply w s (var w s a)
runApply :: (Var var, Monoid w) => Apply w s (var w s a -> T w s ()) -> T var w s a
(=:=) :: (Var var, Monoid w) => T var w s a -> T var w s a -> T w s ()
(=!=) :: (Var var, Monoid w) => T var w s a -> T var w s a -> T var w s a
sqr :: (Floating a, Var var, Monoid w) => T var w s a -> T var w s a
sqrt :: (Floating a, Var var, Monoid w) => T var w s a -> T var w 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, Var var, Monoid w) => T var w s a -> T var w s a -> T var w s a
maximum :: (Ord a, Var var, Monoid w) => [T var w s a] -> T var w s a
-- | Construct or decompose a pair.
pair :: (Var var, Monoid w) => T var w s a -> T var w s b -> T var w s (a, b)
instance (Fractional a, Var var, Monoid w) => Fractional (T var w s a)
instance (Fractional a, Var var, Monoid w) => Num (T var w s a)
instance Applicative (Apply w s)
instance Functor (Apply w s)
-- | Deprecated: This module is intended for documentation purposes. Do
-- not import it!
module UniqueLogic.ST.Example.Label
data Assign
Assign :: Name -> Term -> Assign
type Assigns = [Assign]
data Term
Const :: Rational -> Term
Var :: Name -> Term
Max :: Term -> Term -> Term
Add :: Term -> Term -> Term
Sub :: Term -> Term -> Term
Mul :: Term -> Term -> Term
Div :: Term -> Term -> Term
Abs :: Term -> Term
Signum :: Term -> Term
type Name = String
globalVariable :: Name -> ST s (Variable Assigns s Term)
constant :: Rational -> T Assigns s (Variable Assigns s Term)
-- |
-- x=1
-- y=2
-- z=3
--
--
--
-- x+y=3
-- y*z=6
-- z=3
--
rule :: ((Maybe Term, Maybe Term, Maybe Term), Assigns)
expression :: ((Maybe Term, Maybe Term), Assigns)
instance Show Term
instance Show Assign
instance Fractional Term
instance Num Term
-- | Deprecated: This module is intended for documentation purposes. Do
-- not import it!
module UniqueLogic.ST.Example.Rule
-- |
-- x=1
-- y=2
-- z=3
-- w=3
--
--
--
-- x+y=3
-- y*z=6
-- z=3
-- y^w=8
--
example :: (Maybe Double, Maybe Double, Maybe Double, Maybe Double)
-- | Deprecated: This module is intended for documentation purposes. Do
-- not import it!
module UniqueLogic.ST.Example.Expression
example :: (Maybe Double, Maybe Double)