Repository navigation
Use relative root distances for transfer function minreal - #1089
Merged
baggepinnen merged 3 commits intoOct 22, 2026
Merged
baggepinnen merged 3 commits into
baggepinnen merged 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1089 +/- ##
==========================================
+ Coverage 92.22% 92.26% +0.04%
==========================================
Files 42 42
Lines 6146 6170 +24
==========================================
+ Hits 5668 5693 +25
+ Misses 478 477 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of ControlSystems.jl#1081: transfer-function pole-zero cancellation, including the implicit cancellation in ZPK addition.
The fixed
sqrt(eps(Float64))absolute distance can remove distinct slow dynamics and miss common factors at large scales or in Float32. This changes the default to the local relative distanceabs(p-z)/max(abs(p),abs(z)) < sqrt(eps(T)), withTtaken from the roots. Equal roots at zero still cancel. There is no global magnitude floor: an unrelated fast root must not make distinct slow roots eligible for cancellation. A common root scaling leaves the criterion unchanged, apart from rounding.Explicit
minreal(G, tol)keeps its existing absolute-distance meaning and strict comparison. Conjugate-pair adjustments are restricted to real-coefficient models. Complex-coefficient models cancel only the matched pole and zero, preserving all remaining roots under both relative and explicit absolute tolerances. No dependencies or state-space algorithms change.The boundary-mode conversion test now passes its existing absolute tolerance to both reductions: a numerically shifted integrator does not match an exact zero under the conservative relative default. Its response assertion is unchanged.
minreal(tf([1,1.5e-8],[1,1e-8])): DC gainzpk([],[-1e-8],1e-8) + 1: DC gainf+f,f=zpk([-2e6],[-1e6,-3e6,-4e6],1e12): stored polesThis remains a root-matching heuristic, not a response-error bound. In particular, proximity to the imaginary axis/unit circle and ill-conditioned repeated polynomial roots require care. These limitations and the tolerance semantics are documented. Large roots can now match when relatively close even if their absolute distance exceeded the old threshold.
Validation (Windows x86_64):
ControlSystemstests: 1,156 passed on Julia 1.10.12.ControlSystemsBasetests on Julia 1.13.2: 6,957 passed, 6 existing broken tests; Aqua passes.The initial Julia 1.10 Base run exposed the conversion-test assumption corrected above and a pre-existing state-space
freqrespallocation failure. The allocation reproducer is identical on unmodified master and this branch (123,472 bytes); Julia 1.13 allocates 19,184 bytes and passes the original threshold. The corrected conversion cases also pass on Julia 1.10.Reproduce the new regression file with:
julia --project=lib/ControlSystemsBase -e 'using ControlSystemsBase, Test, Random; include("lib/ControlSystemsBase/test/test_tf_minreal.jl")'AI-assisted implementation, numerical experiments, and review with Codex.
Maintainer follow-up validation (demeter2, Julia 1.13.1):
Maintainer update: host
demeter2; Codex session01a15eb9-1234-7a03-a4be-7f8814d35ca2; working directory/tmp/controlsystems-review-1089.