Modelling Electric Circuits

©1998 Research Institute for Symbolic Computation (RISC-Linz)

NO WARRANTY

Package Description

This package contains definitions for electrical components and for elementary operations, like serial and parallel connections, used in building electrical circuits.
We start by modelling the electrical signals as pairs of current/voltage ranging over the domain of reals. Next, we model electrical components such as resistors, capacitors and inductors by predicates expressing equational constraints between the input and output signals. We found useful to introduce the notion of component instance which describes the behavior of an electric component with a given characteristic value. Component instances are modelled as lambda-terms and are used later in specifying the operations involved in describing electrical circuits.
We end by defining the operations of serial connection, parallel connection, and junction of signals, which suffice for describing any electrical circuit.
A sample session of how to use this package is provided in the notebook ElDemo.nb.

Initialization

There is a standard sequence of Mathematica commands that is typically used to set up the contexts in a package. These commands set the values of $Context and $ContextPath so that the new symbols which are introduced are created in the appropriate contexts.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr1.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr3.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr4.gif]

BeginPackage sets Electrical` to be the current context and specifies that the context of package TSolve` (which contains the actual implementation of the CFLP system) is needed in addition to the package System`. As a consequence, all the definitions provided in the package TSolve` are made visible in the package Electrical`. The two messages

[Graphics:Electricalgr2.gif][Graphics:Electricalgr5.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr6.gif]

are displayed by the command CSConnect which is called when reading package TSolve` and establishes the MathLink connections interpreter/scheduler and scheduler/constraint solvers.

Usage

The command Off is useful for switching off the warning messages printed by Mathematica. We use it here to switch off the warnings for defining symbols with similar names (e.g. CInst and RInst).

[Graphics:Electricalgr2.gif][Graphics:Electricalgr7.gif]

This sequence of commands introduces the objects intended for export (and no others). It also attaches usage messages to symbols; these messages can be visualized by the user by typing in

?symb

[Graphics:Electricalgr2.gif][Graphics:Electricalgr8.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr9.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr10.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr11.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr12.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr13.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr14.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr15.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr16.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr17.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr18.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr19.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr20.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr21.gif]

Begin

[Graphics:Electricalgr2.gif][Graphics:Electricalgr22.gif]

This command sets the current context to Electrical`Private`.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr23.gif]

$ContextPath is a global variable that gives a list of contexts, after $Context, to search in trying to find a symbol that has been entered. From now on, we can make use of the commands defined in the packages TypeSyntax`, TermSyntax`, Variables`, RewriteRules`, RewriteRuleDefs`, Types`, Terms`, Calculus`, TypeChecker` and TSolve`.

Electric signals

By convention, electric signals are defined as pairs V/I of voltage/current. We model them in our system as terms s[V,I] where s is a binary constructor over reals. We also find useful for the type checker to define a particular type, say sig, for the terms denoting electric signals.
First, we define the type constructor sig:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr24.gif]

and next we impose type sig on signal terms

[Graphics:Electricalgr2.gif][Graphics:Electricalgr25.gif]

Electrical components

We model electrical components by predicates that express the relationship between the input and output signal of a system as a conjunction of equations in the components of input/output signals, and two extra variables:

• a variable S called system frequency, which characterizes the electrical sytem as a whole,
• a variable X that is a characteristic parameter to a particular system.

Both S and X range over Real.
We distinguish two kinds of electrical components:
õ! unary components: these components get an input signal s[V0, I0] and produce an output signal s[V1, I1];
To this type belong the resistors, capacitors, inductors, and sources.
õ! constant components: these components emit an output signal s[V1, I1] without receiving any input.

Unary components

Are modelled by predicates of the form

C[ Z,S, s[V0, I0], s[V1, I1]]

where

s[V0, I0] is the input signal
s[V1, I1] is the output signal of the system
S is a Real variable (the frequency variable) that plays role in expressing the relationship between V0, I0, V1, I1
Z is a Real constant that characterizes the system C.

In this setting we can model resistors, inductors, capacitors and sources . All of them have the same type signature .

Type Signatures

We impose the type Realô Realô sigô sigõ%Bool to the predicates resistor, inductor, capacitor and source.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr26.gif]
Definitions

We proceed by defining the characterizing predicates for resistors, capacitors, inductors, and sources. The CFLP language constructs for this purpose are the conditional rewrite rules.
A resistor with characteristic R, input signal s[V0,I0] and output signal s[V1,I1] is an electric system that satisfies the following equations

-V0+V1 = R * I0
I0 = I1

We model such a system by CFLP conditional rewrite rules. The conditional rewrite rule for this system is

resistor[R,S,s[V0,I0],s[V1,I1]]→True⇐-V0+V1~~I0 R&&I0~~I1

And is declared with the command Def.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr27.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr28.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr29.gif]

An inductor with characteristic L, input signal s[V0,I0] and output signal s[V1,I1] is an electric system that satisfies the following equations

V0-V1=L*S*I0
I0=I1

The corresponding Def command is:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr30.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr31.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr32.gif]

A capacitor with characteristic C, input signal s[V0,I0] and output signal s[V1,I1] satisfies

V0-V1=I0/C
I0=I1

and is modeled with the conditional rewrite rule

[Graphics:Electricalgr33.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr34.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr35.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr36.gif]

A source with characteristic E, input signal s[V0,I0] and output signal s[V1,I1] satisfies

V0-V1=E
I0=I1

and is modelled with the conditional rewrite rule

source[E,S,s[V0,I0],s[V1,I1]]→True⇐V0-V1~~E&&I0~~I1.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr37.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr38.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr39.gif]

All electric systems considered so far are unary in the sense that they receive just one input signal and send one output signal. We may also assume the degenerate case when no input signal exists. These types of electric systems we call unidirectional.

Constant components

are modelled by predicates of the form C[ Z, S, s[V1, I1]] where s[V1, I1] is the output signal of the system. S and Z have the same meaning as before.
We consider earth as a unidirectional system.

Type Signature

We impose the type Realô Realô sigõ%Bool to earth.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr40.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr41.gif]
Definition

[Graphics:Electricalgr2.gif][Graphics:Electricalgr42.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr43.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr44.gif]

Component Instances

A component instance of an electric system is the electric component for which the characterizing value is specified. We model this concept with lambda terms.

Definitions

A resistor instance:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr45.gif]

A capacitor instance:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr46.gif]

An inductor instance:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr47.gif]

A source instance:

[Graphics:Electricalgr2.gif][Graphics:Electricalgr48.gif]

Note that we wrapped all CFLP lambda-terms in some Mathematica Module constructs. The reason for this is to quantify the quantities S, L, and R. For example, EInst[E] invoked twice generates two different instances of the lambda-term intended for a source instance:

&lgr;[{S$496,L$496,R$496},source[E,S$496,L$496,R$496]]
&lgr;[{S$497,L$497,R$497},source[E,S$497,L$497,R$497]]

Electrical connections

We describe now the main operations used for building up electrical sytems starting from electrical components.

Serial connections

The serial connection of n electric components is of the form

serial[S,Clist,InputSignal,OutputSignal]

where
õ! S is the frequency variable of the system,
õ! CList is a CFLP list containing the instances of electric components that are connected in serial,
õ! InputSignal is the input signal
õ! OutputSignal is the output signal

We give below the type signature and the definition of this predicate.

Signature(s)

[Graphics:Electricalgr2.gif][Graphics:Electricalgr49.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr50.gif]
Definition(s)

We define the behavior of a serial connection by means of two conditional rewrite rules

serial[S,•,L,R]→True⇐L~~R
serial[S,,L,R]→True⇐C1[S,L,L1]~~True&&serial[S,CS,L1,R]~~True

The first rule specifies that the input signal L coincides with the output signal R when no components are connected. The second rule stands for the recursive definition of a serial connection.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr51.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr52.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr53.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr54.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr55.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr56.gif]

Parallel connections

For modelling parallel connections we first introduce the concept of electrical joint of electrical signals. The predicate

elJoin[Signals,V]

joins a list Signals of signals s[[Graphics:Electricalgr57.gif],[Graphics:Electricalgr58.gif]] where V equals all [Graphics:Electricalgr59.gif], and returns the sum of currents [Graphics:Electricalgr60.gif].

elJoin

Signature

[Graphics:Electricalgr2.gif][Graphics:Electricalgr61.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr62.gif]
Definitions

[Graphics:Electricalgr2.gif][Graphics:Electricalgr63.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr64.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr65.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr66.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr67.gif]

junction

Next we define the junction of a list L of input signals with a list R of output signals.

Signature

[Graphics:Electricalgr2.gif][Graphics:Electricalgr68.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr69.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr70.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr71.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr72.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr73.gif]
Definition

Like serial connections, parallel connections of n components C1, ..., Cn can also be expressed recursively. The predicate

parallel

The parallel connection of n electric components is of the form

parallel[S,Clist,InputSignal,OutputSignal]

where
õ! S is the frequency variable of the system,
õ! CList is a CFLP list containing the instances of electric components that are connected in parallel,
õ! InputSignal is the input signal
õ! OutputSignal is the output signal

Signature

[Graphics:Electricalgr2.gif][Graphics:Electricalgr74.gif]
[Graphics:Electricalgr2.gif][Graphics:Electricalgr75.gif]
Definitions

We define the behavior of a parallel connection by means of two conditional rewrite rules

parallel[S,,InS,OutS]→True⇐C[S,InS,OutS]~~True
parallel[S,,InS,OutS]→True⇐
C[S,InS1,OutS1]~~True&&
parallel[S,Cs,InS2,OutS2]~~True&&
junction[,>]~~True&&
junction[>,]~~True

A difference to the definition of serial connections is the fact that for parallel connection we have the base case when only one component is connected.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr76.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr77.gif]

End

[Graphics:Electricalgr2.gif][Graphics:Electricalgr78.gif]

[Graphics:Electricalgr2.gif][Graphics:Electricalgr79.gif]

This command reverts to the previous context, in this case Electrical`.

[Graphics:Electricalgr2.gif][Graphics:Electricalgr80.gif]

This ends the package Electrical`, prepending it to the context search path.