Skip to content

Commit f22622c

Browse files
lkdvosclaude
andcommitted
Update truncations documentation for TruncationUnion and minrank
Add examples for the `minrank` keyword argument and the `|` operator, and add `@docs` entries for `TruncationIntersection` and `TruncationUnion`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0fd7a90 commit f22622c

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

docs/src/user_interface/truncations.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ all(>(2.9), diagview(Dtrunc))
5656
true
5757
```
5858

59+
Use `maxrank` together with a tolerance to keep at most `maxrank` values above the tolerance (intersection):
60+
5961
```jldoctest truncations; output=false
6062
Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = (maxrank = 2, atol = 2.9));
6163
size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
@@ -64,6 +66,16 @@ size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
6466
true
6567
```
6668

69+
Use `minrank` together with a tolerance to guarantee at least `minrank` values are kept (union):
70+
71+
```jldoctest truncations; output=false
72+
Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = (atol = 3.5, minrank = 2));
73+
size(Dtrunc, 1) >= 2
74+
75+
# output
76+
true
77+
```
78+
6779
In general, the keyword arguments that are supported can be found in the `TruncationStrategy` docstring:
6880

6981
```@docs; canonical = false
@@ -84,6 +96,8 @@ size(Dtrunc, 1) <= 2
8496
true
8597
```
8698

99+
Strategies can be combined with `&` (intersection: keep values satisfying **all** conditions):
100+
87101
```jldoctest truncations; output=false
88102
Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = truncrank(2) & trunctol(; atol = 2.9))
89103
size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
@@ -92,6 +106,17 @@ size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
92106
true
93107
```
94108

109+
Strategies can also be combined with `|` (union: keep values satisfying **any** condition).
110+
This is useful to set a lower bound on the number of kept values with `minrank`:
111+
112+
```jldoctest truncations; output=false
113+
Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = trunctol(; atol = 3.5) | truncrank(2))
114+
size(Dtrunc, 1) >= 2
115+
116+
# output
117+
true
118+
```
119+
95120
## Truncation Strategies
96121

97122
MatrixAlgebraKit provides several built-in truncation strategies:
@@ -104,11 +129,20 @@ truncfilter
104129
truncerror
105130
```
106131

107-
Truncation strategies can be combined using the `&` operator to create intersection-based truncation.
108-
When strategies are combined, only the values that satisfy all conditions are kept.
132+
Strategies can be composed using the `&` operator ([`TruncationIntersection`](@ref)) to keep only values
133+
satisfying all conditions, or the `|` operator ([`TruncationUnion`](@ref)) to keep values satisfying any condition.
134+
135+
```@docs; canonical=false
136+
TruncationIntersection
137+
TruncationUnion
138+
```
109139

110140
```julia
141+
# Keep at most 10 values, all above tolerance (intersection)
111142
combined_trunc = truncrank(10) & trunctol(; atol = 1e-6);
143+
144+
# Keep values above tolerance, but always at least 3 (union)
145+
combined_trunc = trunctol(; atol = 1e-6) | truncrank(3);
112146
```
113147

114148
## Truncation Error

0 commit comments

Comments
 (0)