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

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.

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.

**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

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

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**).

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*

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

**$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`.

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**:

and next we impose type **sig** on signal terms

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.

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 .

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

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**.

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:

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

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.**

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*.

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.

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

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.

A resistor instance:

A capacitor instance:

An inductor instance:

A source instance:

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]]

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

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.

We define the behavior of a serial connection by means of two conditional rewrite rules**serial[S,•,L,R]→True⇐L~~Rserial[S, ,L,R]→True⇐C1[S,L,L1]~~True&&serial[S,CS,L1,R]~~True**

The first rule specifies that the input signal

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[****,****]** where **V** equals all , and returns the sum of currents **∑ **.

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

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

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

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**

C[S,InS1,OutS1]~~True&&

parallel[S,Cs,InS2,OutS2]~~True&&

junction[,

junction[

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.

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

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