`[<<][compsci][>>][..]`
Thu Dec 2 11:42:46 EST 2010

```-- Instead of having to perform numerical inverse all the time, why
-- not represent numbers as (x, 1/x), where possibly one of the two is
-- not given?

-- EDIT: This turned out to be quite interesting: dual.hs

-----------------------------------------------------------------------

import Data.Complex

---- Dual representation of 2-terminals.

-- "Half" two-terminal: 2 primitive elements, one composition.
data HTT a = Resistive a             -- V = R I        ;  I = G V
| Reactive a              -- V = L dI/dt    ;  I = C dV/dt
| Composite (TT a) (TT a) -- V1 + V2 (ser)  ;  I1 + I2 (par)
deriving (Show, Eq)

-- A two-terminal is a dualized HTT.
data TT a = Primal (HTT a)      -- keep duals
| Dual (HTT a)        -- flip duals (invert)
deriving (Show, Eq)

dual (Primal htt) = Dual htt
dual (Dual htt)   = Primal htt

-- The main idea of the dual representation is generality.  One
-- consequence is that building a s-parameterized

trans :: (RealFloat a) => (TT a) -> (Complex a) -> (Complex a)

trans = flip a'' where
a'' s = a' where
a' (Dual htt)   = 1 / (a htt)
a' (Primal htt) = a htt

a (Resistive r)   = r :+ 0
a (Reactive  r)   = (r :+ 0) * s
a (Composite x y) = (a' x) + (a' y)

---- Absolute representation of 2-terminals in terms of dual rep.

-- To represent networks we need to tag the TT to indicate which one
-- of Impedance or Admittance it represents.

data ATT a = Impedance (TT a)
deriving (Show, Eq)

-- Primitive absolute elements are constructed as I/A tagged Primal TTs.

-- Resistive: Impedance / Admittance independent of frequency.
res r = Impedance  (Primal (Resistive r))   -- resistor (Ohms)
cnd g = Admittance (Primal (Resistive g))   -- conductor (Siemens,Mhos)

-- Reactive: Impedance / Admittance proportional to frequency.
ind l = Impedance  (Primal (Reactive l))    -- inductor (Henry)

-- Project ATT to TT, interpreting it as impedance or admittance.
imp (Impedance tt)  = tt
imp (Admittance tt) = dual tt

-- Primitive absolute 2-terminal operations are constructed in terms
-- of a Primal Composite operation.
ser a b = Impedance  (Primal (Composite (imp a) (imp b)))

j x = (0 :+ x)

-- Voltage divider
divider a b s = a' / (a' + b') where
a' = trans (imp a) s
b' = trans (imp b) s

```
`[Reply][About]`
`[<<][compsci][>>][..]`