Documentation

CslibFrontier.Languages.Electrical.LinearCircuit

Linear circuits: Kirchhoff semantics, modified nodal equations and certified stability #

The component language #

A netlist (Cslib.Electrical.Netlist) has nodes numbered 1, …, nodes, with node 0 the ground (datum), inputs input ports, and a list of two-terminal branches (Cslib.Electrical.Branch), each with a positive terminal pos, a negative terminal neg and an element (Cslib.Electrical.Element). Values are exact rationals in SI units: potentials and voltages in volts, currents in amperes, time in seconds.

Branch b has voltage v_b = φ_pos - φ_neg, with φ_0 = 0, and current i_b flowing from pos through the element to neg (passive sign convention); a source supplying power has v_b i_b < 0. Netlist.check rejects a netlist that names a node above nodes, an input port at or above inputs, or a nonpositive R, C or L. No other element (diodes, transistors, switches, mutual inductance, current-controlled sources, nonlinear or time-varying values) is in the language.

Kirchhoff semantics #

Netlist.IsTrajectoryOn c u φ i s is the semantic definition, on a time set s: node potentials φ t and branch currents i t such that, at every t ∈ s,

Only capacitor voltages and inductor currents are required to be differentiable.

Modified nodal equations #

The unknowns are the node potentials followed by all branch currents, z = (φ, i) with N = nodes + #branches entries (Fin.append). The equations are KCL at each non-ground node followed by one equation per branch, its element law written with v_b = φ_pos - φ_neg: E ż = F z + G u + b (Netlist.mna). This is modified nodal analysis with every branch current kept as an unknown (Hachtel's sparse tableau with the branch voltages eliminated by KVL); the classical MNA, which eliminates resistor, capacitor, current-source and VCCS currents, is one of the eliminations that a decoupling certificate may perform. E is singular whenever the circuit has a branch that is not a capacitor or inductor, and nothing assumes otherwise.

Netlist.isTrajectoryOn_iff proves that the circuit trajectories are exactly the solutions of the descriptor system: (φ, i) is a trajectory if and only if Fin.append φ i solves E ż = F z + G u + b.

Certified stability and realizations #

Netlist.isExponentiallyStable_of_decoupling composes the semantics with any index-one decoupling of the equations, and Netlist.isExponentiallyStable_of_check with the exact checkers of CslibFrontier.Algorithms.LinearAlgebra.DescriptorCertificate: a well-formed netlist, an accepted index-one decoupling of its equations, an exactly checked equilibrium z₀ and exponential stability of the checked reduced matrix (for instance from an accepted dense or sparse Lyapunov certificate) together prove that

The supported class is the circuits whose equations have an index-one decoupling; nothing is claimed for any other circuit. By DAE index theory, loops of capacitors and voltage sources, cutsets of inductors and current sources, inconsistent sources and underdetermined subcircuits have none; this characterization is not proved here, but acceptance implies existence and uniqueness, so a circuit without trajectories, or with fewer than a decoupling would give, has no accepted certificate (the tests prove this for an inconsistent and an index-two circuit). Failure to find a certificate is not an instability proof.

Netlist.isTrajectoryOn_iff_realization gives, for selected output probes (Cslib.Electrical.Probe: a node-pair voltage or a branch current) and the input ports, the proper realization ẋ = A x + B u, y - y₀ = C x + D u after the equilibrium shift, on every time set with unique derivatives and for every input signal, including direct feedthrough D. No derivative of the input appears; an elimination that would need one has no index-one decoupling.

Main definitions #

Main results #

A circuit element. Values are exact rationals in SI units; see the module documentation for the element laws and sign conventions.

  • resistor (R : ℚ) : Element

    A linear resistor of resistance R ohms: v = R i.

  • capacitor (C : ℚ) : Element

    A linear capacitor of capacitance C farads: i = C v'.

  • inductor (L : ℚ) : Element

    A linear inductor of inductance L henries: v = L i'.

  • voltageSource (E : ℚ) (input : Option ℕ) : Element

    An independent voltage source v = E + u_k (volts), with u_k = 0 for input = none.

  • currentSource (J : ℚ) (input : Option ℕ) : Element

    An independent current source i = J + u_k (amperes).

  • vccs (g : ℚ) (cp cn : ℕ) : Element

    A voltage-controlled current source i = g (φ_cp - φ_cn), g in siemens.

  • vcvs (μ : ℚ) (cp cn : ℕ) : Element

    A voltage-controlled voltage source v = μ (φ_cp - φ_cn).

Instances For

    A two-terminal branch: its current flows from pos through the element to neg. Node 0 is ground.

    • pos : ℕ

      The positive terminal.

    • neg : ℕ

      The negative terminal.

    • elem : Element

      The element.

    Instances For

      A netlist with non-ground nodes 1, …, nodes, inputs input ports and its branches.

      • nodes : ℕ

        The number of non-ground nodes.

      • inputs : ℕ

        The number of input ports.

      • branches : List Branch

        The branches.

      An output probe: the voltage φ_p - φ_q, or the current of a branch.

      Nodes and branches are indexed differently. Nodes are 1-based: p, q ∈ {0, 1, …, nodes}, with 0 the ground. Branches are 0-based: b ∈ {0, …, branches.length - 1} is the position of the branch in Netlist.branches. An out-of-range probe evaluates to 0 (Probe.eval, Netlist.probeRows); Probe.check rejects it.

      • voltage (p q : ℕ) : Probe

        The voltage φ_p - φ_q between nodes p and q (1-based, 0 is ground).

      • current (b : ℕ) : Probe

        The current of branch b (0-based position in Netlist.branches).

      Well-formedness #

      Whether the element's parameters and references are supported for a netlist with n nodes and m inputs.

      Whether every branch refers to existing nodes and inputs and has supported parameters.

      @[reducible, inline]

      The number of unknowns of the modified nodal equations: potentials, then branch currents.

      Whether a probe refers to existing nodes (≤ nodes, 1-based with ground 0) or an existing branch (< branches.length, 0-based).

      Kirchhoff semantics #

      def Cslib.Electrical.potential {n : ℕ} (φ : Fin n → ℝ) (k : ℕ) :

      The potential of node k: 0 for the ground k = 0, and φ (k - 1) for 1 ≤ k ≤ n. (A well-formed netlist names no other node.)

      def Cslib.Electrical.inputValue {m : ℕ} (w : Fin m → ℝ) :

      The value of an input port, 0 for none.

      1 if branch br leaves node k, -1 if it enters it, 0 otherwise (or for a self loop).

      def Cslib.Electrical.Element.Law {n m : ℕ} (v i : ℝ → ℝ) (φ : ℝ → Fin n → ℝ) (w : ℝ → Fin m → ℝ) (s : Set ℝ) (t : ℝ) :

      The law of an element at time t, for its branch voltage v, its branch current i, the node potentials φ (for controlled sources) and the input w.

      structure Cslib.Electrical.Netlist.IsTrajectoryOn (c : Netlist) (u : ℝ → Fin c.inputs → ℝ) (φ : ℝ → Fin c.nodes → ℝ) (i : ℝ → Fin c.branches.length → ℝ) (s : Set ℝ) :

      Kirchhoff semantics. Node potentials φ and branch currents i form a trajectory of the circuit with input u on the time set s: KCL holds at every non-ground node and every branch obeys its element law, with branch voltage φ_pos - φ_neg.

      Stamps and the modified nodal equations #

      The coefficients of an element's equation `d/dt (eV v + eI i) = fV v + fI i + fC v_c + src

      • u_input, with v_c = φ_cp - φ_cn`.
      • eV : ℚ

        The coefficient of the branch voltage under the derivative.

      • eI : ℚ

        The coefficient of the branch current under the derivative.

      • fV : ℚ

        The coefficient of the branch voltage.

      • fI : ℚ

        The coefficient of the branch current.

      • fC : ℚ

        The coefficient of the control voltage.

      • cp : ℕ

        The positive control node.

      • cn : ℕ

        The negative control node.

      • src : ℚ

        The constant source value.

      • input : Option ℕ

        The input port added to the source value.

      The stamp of an element.

      def Cslib.Electrical.vrow (n p q j : ℕ) :

      Column j of the row vector of the voltage φ_p - φ_q, with n potential columns.

      Column j of the row vector of the current of branch b.

      def Cslib.Electrical.rowsOf (a b : ℕ) (f : ℕ → ℕ → ℚ) :

      The rows f i j for i < a, j < b.

      Entry j of the row of a probe.

      The branch with index b (default beyond the list).

      Entry (r, j) of E.

      Entry (r, j) of F: -incidence in the KCL rows, the stamp in the branch rows.

      Entry (r, q) of G.

      The modified nodal equations E ż = F z + G u + b over ℝ.

      The rows of the output map H of a list of probes.

      def Cslib.Electrical.Probe.eval {n nb : ℕ} (φ : Fin n → ℝ) (i : Fin nb → ℝ) :

      The value of a probe for potentials φ and branch currents i.

      Row computations #

      Element laws as stamped equations #

      theorem Cslib.Electrical.Netlist.isTrajectoryOn_iff {c : Netlist} (hc : c.check = true) {s : Set ℝ} (hs : UniqueDiffOn ℝ s) {u : ℝ → Fin c.inputs → ℝ} {φ : ℝ → Fin c.nodes → ℝ} {i : ℝ → Fin c.branches.length → ℝ} :
      c.IsTrajectoryOn u φ i s ↔ c.mna.IsSolutionOn u (fun (t : ℝ) => Fin.append (φ t) (i t)) s

      Circuit trajectories are the solutions of the modified nodal equations. For a well-formed netlist and a time set with unique derivatives (such as [0, ∞)), potentials φ and branch currents i form a Kirchhoff trajectory with input u exactly when z = (φ, i) solves E ż = F z + G u + b.

      theorem Cslib.Electrical.Netlist.probeRows_mulVec {c : Netlist} (probes : List Probe) (φ : Fin c.nodes → ℝ) (i : Fin c.branches.length → ℝ) :
      (LinearAlgebra.realOfRows probes.length c.size (c.probeRows probes)).mulVec (Fin.append φ i) = fun (o : Fin probes.length) => Probe.eval φ i (probes.get o)

      The probe rows compute the probed quantities.

      theorem Cslib.Electrical.Netlist.isExponentiallyStable_of_decoupling {c : Netlist} {κ : Type u_1} {ρ : Type u_2} [Fintype κ] [Fintype ρ] [DecidableEq κ] [DecidableEq ρ] (hc : c.check = true) (D : c.mna.IndexOneDecoupling κ ρ) {z₀ : Fin c.size → ℝ} (heq : c.mna.IsEquilibrium z₀) (hA : (Matrix.toEuclideanCLM D.A).IsExponentiallyStable) :
      c.IsTrajectoryOn 0 (fun (x : ℝ) (j : Fin c.nodes) => z₀ (Fin.castAdd c.branches.length j)) (fun (x : ℝ) (b : Fin c.branches.length) => z₀ (Fin.natAdd c.nodes b)) (Set.Ici 0) ∧ (∀ (x₀ : κ → ℝ), ∃ (φ : ℝ → Fin c.nodes → ℝ) (i : ℝ → Fin c.branches.length → ℝ), c.IsTrajectoryOn 0 φ i (Set.Ici 0) ∧ D.Q₁'.mulVec (Fin.append (φ 0) (i 0)) = x₀) ∧ ∃ (M : ℝ) (α : ℝ), 0 < α ∧ ∀ (φ : ℝ → Fin c.nodes → ℝ) (i : ℝ → Fin c.branches.length → ℝ), c.IsTrajectoryOn 0 φ i (Set.Ici 0) → ∀ t ≥ 0, ‖WithLp.toLp 2 (Fin.append (φ t) (i t) - z₀)‖ ≤ M * Real.exp (-(α * t)) * ‖WithLp.toLp 2 (Fin.append (φ 0) (i 0) - z₀)‖

      Exponential stability of a circuit from a decoupling. Let the netlist be well formed, D an index-one decoupling of its modified nodal equations, z₀ an equilibrium, and ẋ = A x exponentially stable for the state matrix of D. Then, with zero input, z₀ is a circuit trajectory, every differential state x₀ (read through D.Q₁') starts a circuit trajectory on [0, ∞), and every circuit trajectory on [0, ∞) converges to z₀ exponentially in the Euclidean norm of all potentials and branch currents.

      theorem Cslib.Electrical.Netlist.isExponentiallyStable_of_check {c : Netlist} {d : LinearAlgebra.DecouplingCert} {z₀ : List ℚ} (hc : c.check = true) (hd : d.check c.size c.eRows c.fRows = true) (hz : LinearAlgebra.isEquilibriumRows c.size c.fRows c.bList z₀ = true) (hA : (Matrix.toEuclideanCLM (LinearAlgebra.realOfRows d.k d.k d.A)).IsExponentiallyStable) :
      c.IsTrajectoryOn 0 (fun (x : ℝ) (j : Fin c.nodes) => LinearAlgebra.realOfList c.size z₀ (Fin.castAdd c.branches.length j)) (fun (x : ℝ) (b : Fin c.branches.length) => LinearAlgebra.realOfList c.size z₀ (Fin.natAdd c.nodes b)) (Set.Ici 0) ∧ (∀ (x₀ : Fin d.k → ℝ), ∃ (φ : ℝ → Fin c.nodes → ℝ) (i : ℝ → Fin c.branches.length → ℝ), c.IsTrajectoryOn 0 φ i (Set.Ici 0) ∧ (LinearAlgebra.realOfRows d.k c.size d.Q₁').mulVec (Fin.append (φ 0) (i 0)) = x₀) ∧ ∃ (M : ℝ) (α : ℝ), 0 < α ∧ ∀ (φ : ℝ → Fin c.nodes → ℝ) (i : ℝ → Fin c.branches.length → ℝ), c.IsTrajectoryOn 0 φ i (Set.Ici 0) → ∀ t ≥ 0, ‖WithLp.toLp 2 (Fin.append (φ t) (i t) - LinearAlgebra.realOfList c.size z₀)‖ ≤ M * Real.exp (-(α * t)) * ‖WithLp.toLp 2 (Fin.append (φ 0) (i 0) - LinearAlgebra.realOfList c.size z₀)‖

      Certified exponential stability of a circuit. Let the netlist be well formed, let d be an accepted index-one decoupling of its modified nodal equations, z₀ an exactly checked equilibrium (F z₀ + b = 0), and let ẋ = A x be exponentially stable for the checked reduced matrix d.A, for instance by an accepted Lyapunov certificate (Cslib.LinearAlgebra.LyapunovCert.isExponentiallyStable_of_check). Then, with zero input,

      1. the operating point z₀ = (φ₀, i₀) is a (constant) circuit trajectory;
      2. every differential state x₀, read through Q₁', starts a circuit trajectory on [0, ∞);
      3. every circuit trajectory on [0, ∞) converges to z₀ exponentially: for constants M and α > 0 independent of the trajectory, ‖(φ t, i t) - z₀‖ ≤ M exp (-α t) ‖(φ 0, i 0) - z₀‖ in the Euclidean norm of all potentials and branch currents.

      This is isExponentiallyStable_of_decoupling for DecouplingCert.toDecoupling.

      The checked realization of a circuit for the probes probes and its input ports, with the rational matrices computed from the decoupling d (DecouplingCert.A, reducedB, outputC and feedthroughD).

      Checked proper realization. Let the netlist be well formed, d an accepted decoupling and z₀ a checked equilibrium. On a time set with unique derivatives (such as [0, ∞)) and for every input signal u, (φ, i) is a circuit trajectory exactly when

      1. the vector z = (φ, i) is reconstructed from the state x = Q₁' (z - z₀) and the input: z = z₀ + Q₁ x - Q₂ P₂ G u, and
      2. x solves ẋ = A x + B u of c.realization d probes.

      The probed outputs then satisfy y - y₀ = C x + D u (IsTrajectoryOn.probe_sub_eq).

      theorem Cslib.Electrical.Netlist.IsTrajectoryOn.probe_sub_eq {c : Netlist} {d : LinearAlgebra.DecouplingCert} {z₀ : List ℚ} (hc : c.check = true) (hd : d.check c.size c.eRows c.fRows = true) (hz : LinearAlgebra.isEquilibriumRows c.size c.fRows c.bList z₀ = true) (probes : List Probe) {s : Set ℝ} (hs : UniqueDiffOn ℝ s) {u : ℝ → Fin c.inputs → ℝ} {φ : ℝ → Fin c.nodes → ℝ} {i : ℝ → Fin c.branches.length → ℝ} (h : c.IsTrajectoryOn u φ i s) {t : ℝ} (ht : t ∈ s) :
      ((fun (o : Fin probes.length) => Probe.eval (φ t) (i t) (probes.get o)) - fun (o : Fin probes.length) => Probe.eval (fun (j : Fin c.nodes) => LinearAlgebra.realOfList c.size z₀ (Fin.castAdd c.branches.length j)) (fun (b : Fin c.branches.length) => LinearAlgebra.realOfList c.size z₀ (Fin.natAdd c.nodes b)) (probes.get o)) = (realization d probes).C.mulVec ((LinearAlgebra.realOfRows d.k c.size d.Q₁').mulVec (Fin.append (φ t) (i t) - LinearAlgebra.realOfList c.size z₀)) + (realization d probes).D.mulVec (u t)

      Output equation. Along a circuit trajectory, the probed outputs differ from their values at the operating point by C x + D u, where x = Q₁' (z - z₀) is the realization's state.