Reduction ========= A reduction replaces the coordinates by combinations that the output determines :cite:p:`Chappell1998,Evans2000,Massonis2023`, the invariants :math:`I_l(\theta)` with :math:`X(I_l) = 0` :cite:p:`Olver1986`. The directions are reduced in *blocks*, sets of directions with overlapping supports, each block with the group :math:`G` generated by the flows of the generators of the block. symident searches, within degree bounds, monomial, polynomial and rational invariants (with a denominator in one coordinate), Darboux polynomials and exponential factors :cite:p:`Prelle1983,Goriely2001`, i.e., polynomials :math:`P` and exponentials :math:`e^{P/Q}` that :math:`X` multiplies by a polynomial, and invariants by separable quadrature, i.e., by integrating :math:`\mathrm{d}\theta_i / \xi_i = \mathrm{d}\theta_j / \xi_j` where it separates, and by an integrating factor. The invariants become new parameters, :math:`I_l(\theta) = q_l`, and the remaining coordinates are expressed through them. The invariants are coordinates on the orbit space :math:`\Theta / G`, a *chart*, and the trafo is the section in these coordinates. A chart is returned only where it is valid on the declared domain, the positive orthant by default; ``Reduction.partial`` names the directions whose chart covers the domain only in part, and ``alternatives=True`` also returns the charts of the other valid choices of the fixed coordinates. Among the charts, one with total coverage comes before a rational one. .. _red-scalings: Scalings -------- A scaling is removed by fixing one of the coordinates it moves at one, such as an initial value or a scale, a *pin*. Every orbit of a scaling meets the hypersurface :math:`\theta_i = 1` of a moved coordinate once, so the result is a *global section*: a one-to-one map of the new parameters onto a *global cross-section*, a set meeting every orbit exactly once, with the invariants as global coordinates on the orbit space :math:`\Theta / G`. In the example of Equation :eq:`eq-example`, :math:`A_0 = 1` meets every orbit of the scaling once. A direction along one coordinate is pinned like a scaling; every orbit meets the pin where a *sign certificate*, a proof that an expression has one sign on :math:`\Theta`, shows that the generator component on the pinned coordinate has one sign, else the orbits can be the intervals between the zeros of that component, and the pin is listed under ``unproven``. The pinned coordinates of a block of scalings, the *transversal* of the block, are chosen among the coordinates of the support that are not fixed: subsets :math:`T` of the size of the block, taken in the order of the coordinates, for which the columns :math:`W_T` of the weight matrix :math:`W` are invertible and :math:`W_T^{-1} W` has integer entries, so that every other coordinate becomes a monomial of the new parameters; for many candidates a greedy choice by the number of scalings moving each coordinate. Without a certified transversal the block keeps the invariants only (``invariant_only``). A scaling keeps the sign of every coordinate, so a pin on a coordinate that is not declared positive misses the orbits where that coordinate is negative or zero; transversals of positive coordinates come first. Where the only transversal outside the support of the general directions is such a signed one, the pins :math:`\theta_T = 1` are taken on positive coordinates inside that support, and each general generator :math:`X` becomes :math:`X - \sum_i \lambda_i S_i`, with the scalings :math:`S_i = \sum_c W_{ic} \theta_c \partial_{\theta_c}` and :math:`\lambda` solved from :math:`\sum_i \lambda_i W_{it} \theta_t = \xi_t` for :math:`t \in T`, divided by the greatest common divisor of the numerators of the components. The matrix :math:`(W_{it} \theta_t)` is invertible where the pins are positive, so the new generators span the same distribution as before together with the scalings, and they leave :math:`\theta_T = 1` in place. Every orbit meets :math:`\theta_T = 1`; there, the orbits of the new generators are the intersections with the orbits of all directions, so the certificates of the general block hold for the whole group. Of up to four positive transversals, the one with the shortest new generators is kept. Before the search for invariants, a block of several general generators is split by *module reduction*: an elimination order with few new nonzero entries, found at random points modulo a prime and repeated exactly, gives combinations of the generators with smaller supports, and independent ones form separate blocks. .. _red-linear: Linear flows ------------ A block of :math:`r` general generators is a *linear flow* when, in the coordinates :math:`\tilde\theta_i = \theta_i` for a moved coordinate that is not declared positive and :math:`\tilde\theta_i = \log \theta_i` for a positive one, every component :math:`\tilde\xi_i` depends only on the coordinates :math:`u` that the block does not move, and no declared bound involves a moved coordinate. The generators then commute, and the orbit of a point is the affine set :math:`\{(u, \tilde\theta + \Xi(u) s) : s \in \mathbb{R}^r\}`, with :math:`\Xi(u)` the matrix of the components, on which every moved coordinate takes every real value. Pins :math:`\tilde\theta_P = 0` on :math:`r` moved coordinates :math:`P` whose minor :math:`\det \Xi_P(u)` has one sign on :math:`\Theta` give a global section: :math:`\tilde\theta_P + \Xi_P(u) s = 0` has exactly one solution on every orbit, so the section is ``injective`` and ``reach``-es every orbit. The invariants are :math:`\tilde\theta_N - \Xi_N(u) \Xi_P(u)^{-1} \tilde\theta_P` for the other moved coordinates :math:`N`, and a linear coordinate is pinned to 0, a positive one to 1. This stage runs before the search for invariants. Among the pin sets, a coordinate that enters only the observables (an offset of the observation function) is preferred, an initial value is taken last. .. _red-general: General blocks -------------- For a block of :math:`r` general generators the invariants :math:`I(\theta) = q` are solved for coordinates :math:`\theta_s = R(q, \vartheta)`, with :math:`r` *gauge coordinates* :math:`\vartheta` left. Every level set :math:`\Lambda_q = \{\theta \in \Theta : I(\theta) = q\}` is one orbit when 1. :math:`R(q, \vartheta)` is the unique solution for every gauge value, so :math:`\Lambda_q` is the graph of :math:`R(q, \cdot)` over :math:`\mathcal{G}_q = \{\vartheta : (R(q, \vartheta), \vartheta) \in \Theta\}`; 2. the :math:`r \times r` minor of the generator components on :math:`\vartheta` has one sign on :math:`\Theta`, so every orbit is :math:`r`-dimensional and open in :math:`\Lambda_q` (for generators with poles, the minor of the fields times their denominators); 3. :math:`\mathcal{G}_q` is connected. The set :math:`\mathcal{G}_q` is given by one inequality :math:`\pi_k(q, \vartheta) > 0` per positive solved coordinate and square-root factor. It is connected when every inequality is convex in :math:`\vartheta` (affine, a concave quadratic, or, in one positive gauge coordinate, a polynomial with at most one sign change and so, by Descartes' rule of signs, at most one positive root), or when a gauge coordinate enters every inequality affinely with a coefficient of known sign, so that the *fibers*, the sets of that coordinate at fixed other gauge coordinates, are intervals and the set is connected with the projection, decided the same way. Square roots in :math:`\vartheta`, or of a single positive invariant, are first removed by a square substitution, which is one to one on the positive half-line. The *section point* :math:`\hat\theta(q)` then lies in :math:`\Lambda_q` and, by a *positivity certificate*, a proof that each entry is positive on the domain, in :math:`\Theta`. **Split products.** Sections equate *balances*, monomials or summands of the invariants. An invariant :math:`A - B` whose two summands each have one sign on :math:`\Theta` takes both signs across the orbits, and the orbits of either sign leave the domain on different faces. For such an invariant the products :math:`u v = 1` of a positive coordinate :math:`u` of :math:`A` and one :math:`v` of :math:`B` are candidates as well. They are tried after the other balances, alone or with one other balance, as many balances as generators, and only where the Jacobian of the logarithms of the balance ratios along the generators, a determinant of polynomials over positive denominators, has one sign on :math:`\Theta` by a sign certificate: the section is then transversal to the orbits everywhere. Injectivity, ``reach`` and the positivity of the entries are proven as for any section. **Section charts.** Where the section point solved from the invariants holds a root, the section itself can still be rational, and the count of discrete symmetries (:meth:`Symmetries.discrete`), which needs a rational reduced model, takes it so: when every orbit meets it (total coverage) exactly once (``injective``), and the balances of the section solve, one after the other, for a coordinate of degree one with a coefficient of one sign, each solved coordinate certified of the declared sign, the remaining coordinates of the section are the new parameters. The trafo is then rational and maps their domain one to one onto the points of the section in :math:`\Theta`, hence onto the orbits; the meaning of a new parameter is the coordinate of the section point of the orbit, solved from the invariants. **Coverage.** ``reach`` says that every level set of the invariants is one orbit; with *total coverage* every orbit then meets the section, under *partial coverage* exactly the orbits whose invariants lie where the solved entries are positive. Under declared bounds, i.e., expressions in ``positive``, an entry without positivity certificate is kept, with partial coverage, and listed under ``unproven``. Without bounds it is kept only when the search found no section certified on the whole domain, and only where a sampled orbit has every entry positive: the transformation then covers the orbits on which the ``sign_conditions``, the entries as inequalities in :math:`q`, hold, the sampled one among them, and no others. A positivity certificate treats an *atom*, a non-polynomial subterm such as :math:`\log x`, as positive only where the sign of the atom is proven; an AM-GM certificate, a lower bound by the inequality of arithmetic and geometric means over pairs of terms, is strict only by the positive remainder the pairs leave, on a term free of coordinates that are not declared positive where there are any. **Face sections.** A *face* is a boundary set :math:`\theta_f = 0` for coordinates :math:`\theta_f` of the block; a section on a face lies outside :math:`\Theta` and is reached only in a limit. It is tried first, and once one is found no other is searched; the new parameters are the coordinates of the face point, not invariants. With :math:`\theta_f` as gauge coordinates, the conditions above make every level set one orbit, and :math:`R(q, \theta_f) \to R(q, 0) > 0` puts the face point :math:`(0, R(q, 0))` in the closure of every orbit of :math:`\Lambda_q`. The output, constant along the orbit, equals that at the face point when the model is continuous there: no model expression has a pole at the face, every denominator in the block parameters has one sign there, and under ``equilibrate`` :math:`x^\ast(\theta)` has a limit. For that limit each generator is lifted to a field :math:`\tilde X = X + \xi_x \partial_x` tangent to the resting variety, by the state components of an exact direction or by the implicit derivative :math:`\xi_x = -J_x^{-1} J_\theta \xi_\theta`; exactly verified invariants of the lifted fields that solve for the moved states and stay positive at :math:`\theta_f = 0` give the limit along every orbit. The implicit derivative needs :math:`J_x` regular: proven when :math:`\det J_x` has one sign on :math:`\Theta`, else checked at random points. Without a lift, the resting state is continuous when :math:`f` is affine in the states with a resting Jacobian of one sign at the face, else it is checked at random face points; a checked resting state sets ``face_level`` and ``level`` of the block to ``checked``. **Injectivity.** That every orbit meets the cross-section :math:`\mathcal{C}` at most once (``injective``) is proven, for any number of generators, when the solved coordinates recover every point of :math:`\mathcal{C}` from the invariants, :math:`\hat\theta(I(\theta)) = \theta` on :math:`\mathcal{C}`, since two points of one orbit have equal invariants. The identity is shown over :math:`\mathbb{Q}` on a parametrization of the positive points of :math:`\mathcal{C}`, monomial where the section equates monomials, else by solving each equation for a coordinate of degree one; the claim is made for sections with total coverage off a face. For one generator it also holds when :math:`X` changes the pinned coordinate, or the logarithm of the quotient of the two sides of the section equation, with one sign on :math:`\Theta`. **Zero limits.** With ``zero_limits=True`` each block reports which coordinates can be set to zero: everywhere, under a condition, or in a limit along the orbits when the face is mapped into itself by the generators, and whether this is certain (``to_dict()["zero_compatibility"]``). An unproven claim is listed under ``unproven`` of the block and makes the block ``open``; a block is ``verified`` or ``checked`` when a direction or a face resting state has that level, else ``exact``. The transformation is checked over :math:`\mathbb{Q}`, and ``check=True`` runs the detection again on the reduced model (``Reduction.checks["loop"]``). .. _red-inputs: Unknown inputs -------------- In a model with ``unknown_inputs`` :math:`w`, a direction changes the input trajectory together with :math:`\theta` and the initial values, so a section in :math:`(\theta, x_0)` gives the output of a point only with another input. The reduction keeps the inputs free and proves, per direction, that they absorb the change, in one of two ways; a direction with neither proof is not reduced, and the reason names the inputs. For a model with one condition, no events and no ``equilibrate``, :math:`\dot x = f(x, \theta, w, u)`, output :math:`h(x, \theta)`, with the time derivative :math:`D = f \cdot \partial_x`: *Inversion.* Suppose there are as many observables as unknown inputs, none reads an input, and the matrix :math:`M = \partial_w D(h)` has a determinant that is not zero as a rational function. Let :math:`(\hat\theta, \hat x_0, \hat w)`, :math:`\hat w` continuous, give the output :math:`\hat g` on :math:`[0, T]` with :math:`\det M \ne 0` along the trajectory. Then every :math:`(\theta', x_0')` with :math:`h(x_0', \theta') = \hat g(0)` gives :math:`\hat g` with an input :math:`w'` wherever :math:`D(h)(x', \theta', w') = \dot{\hat g}` has a continuous solution :math:`w'` in the domain of the inputs with a state :math:`x'` of :math:`\dot x' = f(x', \theta', w')`, :math:`x'(0) = x_0'`, on :math:`[0, T]`; near :math:`(\hat\theta, \hat x_0)` it does. *Proof.* :math:`e(t) = h(x'(t), \theta') - \hat g(t)` has :math:`\dot e = D(h)(x', \theta', w') - \dot{\hat g} = 0` and :math:`e(0) = 0`. Near the trajectory, the implicit function theorem solves :math:`D(h)(x, \theta, w) = \dot{\hat g}(t)` for :math:`w = W(t, x, \theta)`, continuous in :math:`t` and :math:`C^1` in :math:`(x, \theta)` on a neighborhood of the compact graph of :math:`(\hat x, \hat\theta, \hat w)`, and the solution of :math:`\dot x = f(x, \theta, W)` exists on :math:`[0, T]` for data near :math:`(\hat x_0, \hat\theta)` by continuous dependence. :math:`\square` Every exact direction :math:`X` has :math:`X(h) = 0` at the start, the rows of order zero, so the orbits of :math:`X` in :math:`(\theta, x_0)` keep :math:`h(x_0, \theta)`, and a section of the directions, chosen as for a model without inputs, gives the output of every point under the condition above. *Pointwise lift.* Suppose the direction, up to a factor, has parameter components :math:`\xi_\theta(\theta)`, state components :math:`\xi_x(\theta, x)` (the components on the initial values read as functions of the states), and input components :math:`\xi_w(\theta, x, w)` solved from the identities .. math:: :label: eq-input-lift D(\xi_x) = V(f), \qquad V(h) = 0, \qquad V = \xi_\theta\, \partial_\theta + \xi_x\, \partial_x + \xi_w\, \partial_w , over :math:`\mathbb{Q}`, and a given initial value :math:`x_0(\theta)` moves with the parameters, :math:`\xi_x(\theta, x_0(\theta)) = \xi_\theta \cdot \partial_\theta x_0`. Let :math:`\Phi_\varepsilon` be the flow of :math:`V`. On :math:`[0, T]` set :math:`\theta(\varepsilon)`, :math:`x(t, \varepsilon)` and :math:`w(t, \varepsilon)` to the components of :math:`\Phi_\varepsilon(\hat\theta, \hat x(t), \hat w(t))`; by compactness they exist for :math:`|\varepsilon| < \varepsilon_0`, and :math:`(\theta, x)` follows the flow of :math:`(\xi_\theta, \xi_x)`, which reads no input, so :math:`x` is :math:`C^1` in :math:`t`. Then :math:`x(\cdot, \varepsilon)` solves the model with :math:`\theta(\varepsilon)` and the input :math:`w(\cdot, \varepsilon)` and gives :math:`\hat g`. *Proof.* With :math:`R = \partial_t x - f(x, \theta, w)`, :math:`\partial_\varepsilon \partial_t x = \partial_t \xi_x(\theta, x) = \partial_x \xi_x\, \partial_t x` and :math:`\partial_\varepsilon f(x, \theta, w) = V(f) = D(\xi_x) = \partial_x \xi_x\, f`, so :math:`\partial_\varepsilon R = \partial_x \xi_x\, R` with :math:`R(t, 0) = 0`, hence :math:`R = 0`; and :math:`\partial_\varepsilon h(x, \theta) = V(h) = 0`. :math:`\square` The orbits of :math:`\xi_\theta` thus keep the output as long as the input stays in the domain of the inputs, :math:`w > 0` where declared positive; near every point it does. The reduction removes the field :math:`\xi_\theta` on the parameters, with the invariants, sections and coverage of the parameter field; the initial values of the states and the inputs stay free in the reduced model. A lift with :math:`\xi_w = 0` is a symmetry of the model, reduced as without inputs. ``Reduction.blocks`` holds per block ``inputs``: the inputs, the proof (``"inversion"`` with the ``determinant``, or ``"lift"`` with the components), and the ``condition`` on the input and the trajectory, which the report repeats. The section claims of the block, ``reach`` and ``injective``, are those of the orbits of the field the reduction removes; that the section point gives the output rests on this condition. .. _red-branches: Branches of discrete symmetries ------------------------------- For a reduction, each image of the fundamental domain under the maps is a *branch*. Where a map :math:`\sigma` has one hypersurface :math:`q = 0` as fixed set and exchanges the two sides of it, :math:`q(\sigma(\theta)) = -c\, q(\theta)` with :math:`c > 0` on :math:`\Theta`, the branches are the sides :math:`s\, q > 0`, :math:`s = \pm 1`, named by the inequality, and :math:`q = 0` is their boundary. On a side, :math:`\delta = s\, q(\theta) > 0` replaces a coordinate :math:`x` in which :math:`q` is linear; :math:`x` is chosen by structure, a solution :math:`x(\delta, \theta')` with a positivity certificate first, then the smaller expression, so that neither the chart nor the name of the branch depends on the names or the order of the parameters. The chart maps free values in the positive orthant into the side and is chained with the section of the continuous symmetries. It is ``injective`` where the coefficient of :math:`x` in :math:`q` has a sign certificate, since :math:`\delta = s\, q(\theta)` inverts it, and it ``reach``-es the whole side where :math:`x(\delta, \theta')` has a positivity certificate; a claim without certificate is listed under ``unproven``. A fiber of more than two points has no branch charts.