-- Component values are RealFloat while s values and impedances are
-- complex.
import Data.Complex
-- Represents 2-terminal elements that relate current and voltage.
data Twot a
= R a | G a -- primitive
| C a | L a
| Ser (Twot a) (Twot a) -- composite
| Par (Twot a) (Twot a)
deriving (Show,Eq)
-- (//) a b = 1 / ( 1 / a + 1 / b)
m = (* 0.001)
u = m . m
n = m . n
p = m . p
k = (* 1000)
j x = 0 :+ x
imp :: RealFloat a => (Twot a) -> (Complex a) -> (Complex a)
cond :: RealFloat a => (Twot a) -> (Complex a) -> (Complex a)
-- An impedance is a function of angular frequency to impedance. This
-- is a direct numerical interpretation of a Twot. Note that symmetry
-- is restored with R represented as (Either )
imp c s = z c where
z (R x) = x :+ 0
z (L x) = s * (x :+ 0)
z (Ser x y) = (z x) + (z y)
z x = 1 / cond x s
cond c s = a c where
a (G x) = x :+ 0
a (C x) = s * (x :+ 0)
a (Par x y) = (a x) + (a y)
a x = 1 / imp x s
-- Imp and cond should obey the following duality:
dual = d where
d (R x) = G x
d (G x) = R x
d (C x) = L x
d (L x) = C x
d (Ser x y) = Par x y
d (Par x y) = Ser x y