---
title: 'PiecewiseHilbert: Analytical Hilbert Transforms'
url: https://www.emergentmind.com/topics/piecewisehilbert
type: topic
---

# PiecewiseHilbert: Analytical Hilbert Transforms

Searching arXiv for the primary paper and a few contextual Hilbert-transform references.

PiecewiseHilbert is a companion Julia module in the Piecewise ecosystem whose purpose is to add Hilbert-transform capabilities to the pre-defined `Formula` types provided by `Piecewise`, allowing the Hilbert transform of a `PiecewiseFunction` to be evaluated without resorting to numerical quadrature [2509.18829]. Within that ecosystem, a piecewise function of a real variable is represented on a union of intervals, each interval carrying a rule that is typically a linear combination of elementary formulas, and the central design principle is that, when closed-form antiderivatives are available for the kernel-dependent integrands, integral transforms reduce to evaluating primitives at interval boundaries rather than performing numerical integration [2509.18829]. PiecewiseHilbert specializes this principle to the Hilbert kernel, so that a fitted piecewise approximation built from supported basis formulas such as `POLY` and `LOG` can be transformed analytically, with the resulting transform represented again as a `PiecewiseFunction` [2509.18829].

## 1. Position within the Piecewise ecosystem

The `Piecewise` Julia module provides a general infrastructure for 1D piecewise functions. Its core types are `Formula`, which holds a user-defined function of a real variable and parameters, `Piece`, which holds an interval, a rule, and formula parameters, and `PiecewiseFunction`, which holds a collection of `Piece` objects together with a parity flag such as `:even` or `:odd` [2509.18829]. The module also provides a fitting mechanism, exemplified by
```julia
f = piecewisefit(x -> some_function(x),
                 (a, b), [POLY, LOG],
                 parity = :even, rtol = 1e-5)
```
which constructs a `PiecewiseFunction` fitted to a target function with specified formulas and tolerance [2509.18829].

The motivating application is fast evaluation of integral transforms for functions with critical points such as discontinuities, cusps, and logarithmic singularities, where polynomial interpolations and numerical quadratures are slow or inaccurate [2509.18829]. In the general formulation,
$$
(K \circ f)(\mathbf{X}) = \int_{-\infty}^{\infty} dx\, f(x)\, K(x, \mathbf{X}),
$$
the transform becomes a boundary-evaluation problem whenever each elementary piece $F_i(x)$ admits a closed-form antiderivative $P_i$ satisfying
$$
\frac{d}{dx} P_i(x,\mathbf{X}) = F_i(x)\,K(x,\mathbf{X}).
$$
The base `Piecewise` module defines seven pre-built `Formula` types with known moment integrals, the `PiecewiseHilbert` module supplements those formulas with methods for fast Hilbert transforms, and the `PiecewiseLorentz` module extends some formulas for a Lorentz-type transform [2509.18829].

In this setting, PiecewiseHilbert is not a generic Hilbert-transform package for arbitrary user-defined formulas. Its fast path is tied to the subset of formulas for which analytic Hilbert-transform methods have been implemented. This suggests that its scope is deliberately kernel-specific and basis-specific rather than universal.

## 2. Mathematical formulation

The Hilbert transform is presented through the kernel
$$
K(x,y) = \frac{1}{y - x + i0^+},
$$
or, more generally,
$$
K(x,z) = \frac{1}{z - x}, \quad z \in \mathbb{C} \setminus \mathbb{R},
$$
with finite imaginary part [2509.18829]. In real-variable form, the standard transform is
$$
\mathcal{H}[f](y) = \frac{1}{\pi} \, \operatorname{p.v.} \int_{-\infty}^{\infty} \frac{f(x)}{y - x} \, dx,
$$
where $\operatorname{p.v.}$ denotes the Cauchy principal value [2509.18829].

For a piecewise representation
$$
f(x) = \sum_{k} f_k(x) \, \chi_{(a_k, b_k)}(x),
$$
with each $f_k$ a linear combination of supported formulas on $(a_k,b_k)$, the transform becomes
$$
\mathcal{H}[f](y) = \frac{1}{\pi} \operatorname{p.v.} \sum_k \int_{a_k}^{b_k} \frac{f_k(x)}{y-x}\, dx.
$$
If $y$ lies outside $(a_k,b_k)$, the integral is regular; if $y$ lies inside $(a_k,b_k)$, the principal-value prescription is required [2509.18829]. PiecewiseHilbert exploits linearity by expressing
$$
f_k(x) = \sum_i c_{k,i} F_i(x)
$$
and precomputing
$$
H_i(y; a_k,b_k) = \frac{1}{\pi} \operatorname{p.v.} \int_{a_k}^{b_k} \frac{F_i(x)}{y-x}\, dx,
$$
so that
$$
\mathcal{H}[f](y) = \sum_k \sum_i c_{k,i} H_i(y; a_k,b_k)
$$
is assembled analytically from basis contributions [2509.18829].

For the polynomial basis `POLY`, the paper gives the decomposition
$$
\frac{x^n}{y-x}
= -x^{n-1} - y x^{n-2} - \cdots - y^{n-1} - \frac{y^n}{y-x},
$$
which reduces the transform of $x^n$ on $(a,b)$ to regular power integrals plus a logarithmic term, yielding an expression of the form
$$
H_{\text{POLY},n}(y; a,b)
= A_n(a,b,y) \,+\, B_n(y)\, \log\left|\frac{y-a}{y-b}\right|,
$$
with $A_n$ and $B_n$ polynomial [2509.18829]. For the logarithmic basis `LOG`, the transform of terms such as $\log|x|$ on finite intervals is likewise treated analytically, with built-in expressions involving logarithmic or polylogarithmic structure [2509.18829].

This analytic strategy differs sharply from FFT-based and quadrature-based Hilbert transforms. FFT methods typically assume a periodic, uniformly sampled grid, while quadrature-based approaches confront the principal-value singularity directly [2509.18829]. By contrast, PiecewiseHilbert avoids numerical quadrature entirely for supported formulas, and its cost is described as essentially proportional to the number of pieces and the number of evaluation points [2509.18829].

## 3. Formula types, fitting, and transform construction

The `Piecewise` module ships with a small set of built-in `Formula` types, explicitly including `POLY` and `LOG`, and covers many practical cases [2509.18829]. PiecewiseHilbert supplements those formula types with Hilbert-transform methods, so that a fitted `PiecewiseFunction` can be mapped to another `PiecewiseFunction` representing its Hilbert transform [2509.18829].

A typical workflow uses `Piecewise` to fit the target and `PiecewiseHilbert` to transform the fit:
```julia
using Piecewise
# Suppose g(x) is expensive to evaluate and has a singularity at x=0
pw = piecewisefit(x -> g(x),
                  (xmin, xmax),
                  [POLY, LOG],      # choose basis functions
                  parity = :even,
                  rtol = 1e-6)
```
followed by
```julia
using PiecewiseHilbert

Hpw = hilbert(pw)  # returns a PiecewiseFunction for H[g](x)
```
after which `Hpw(x)` evaluates $\mathcal{H}[g](x)$ analytically on the domain [2509.18829].

The parity field in `PiecewiseFunction` is operational rather than decorative. Many physical problems are even or odd, and the `:even` or `:odd` flag allows symmetry exploitation to reduce domain size and improve accuracy and speed [2509.18829]. This is consistent with broader Hilbert-transform literature in which parity can determine whether singular contributions cancel or persist. For example, finite-part formulas on symmetric intervals show that the presence or absence of the singular term depends on the interval of integration and on the parity of the function under transformation about the origin [2210.14462].

The supported formula repertoire is intentionally limited. The short article explicitly mentions `POLY` and `LOG` and states that PiecewiseHilbert only works “fast” for formulas carrying the extra Hilbert-transform methods; arbitrary user-defined formulas would need corresponding analytic primitives supplied by the user, or would fall back to numerical approaches or remain unsupported [2509.18829]. A plausible implication is that the module is best viewed as a framework for analytic transforms over a curated basis library rather than a symbolic engine for arbitrary kernels and rules.

## 4. Numerical behavior and comparison with alternative Hilbert-transform strategies

The paper does not provide explicit numerical tables in the short format, but it states the main performance rationale clearly [2509.18829]. Compared with quadrature-based Hilbert transforms, piecewise-analytic transforms require only evaluation of closed-form expressions at each point, with cost proportional to the number of pieces and basis functions, whereas quadrature typically scales with the number of grid points and may require adaptive refinement near singularities [2509.18829]. Compared with FFT-based transforms, the piecewise approach works in continuous space, on arbitrary finite intervals, and treats singularities exactly rather than through periodic extension, padding, or windowing [2509.18829].

The approximation error is attributed solely to the initial fit produced by `piecewisefit` [2509.18829]. Once the piecewise representation is fixed, the Hilbert transform of that approximant is exact within floating-point arithmetic because it is evaluated from analytic formulas [2509.18829]. In the density-of-states example discussed below, the fitted piecewise approximation attains relative accuracy better than $10^{-5}$ over the full support $[-4,4]$ despite discontinuities and a logarithmic singularity [2509.18829].

This design addresses a class of numerical pathologies that also appear in other Hilbert-transform settings. A simple delta–delta discretization of the finite Hilbert transform on an interval has convergence that is non-uniform, with order $O(h^2)$ in the interior but a boundary layer where the consistency error does not tend to zero [2303.13693]. Multi-domain spectral methods on the real line improve behavior for piecewise analytic functions by decomposing the domain into subintervals and applying Chebyshev-based quadrature locally, but they remain numerical spectral schemes rather than analytic piecewise transforms [2101.02473]. PiecewiseHilbert belongs to a different design point: rather than resolve singular structure numerically, it attempts to encode that structure directly in the basis formulas.

The stability argument in PiecewiseHilbert is therefore structural. Principal-value handling is built into the analytic expressions, critical points are represented with dedicated formulas such as `LOG`, and symmetry can be built into the representation through parity flags [2509.18829]. This suggests that numerical robustness is achieved less by adaptive integration and more by choosing an approximation space that mirrors the singular geometry of the target function.

## 5. Canonical example: two-dimensional lattice density of states

The explicit example in the paper concerns a two-dimensional lattice density of states with dispersion
$$
\varepsilon(\mathbf{k}) = 2 (\cos k_x + \cos k_y)
$$
and density of states
$$
N(E) = \frac{1}{2\pi^2}
          K\left(1 - \left(\frac{E}{4}\right)^2\right)\,
          \theta(4 - |E|),
$$
where $K(\cdot)$ is the complete elliptic integral [2509.18829]. The critical points are discontinuities at $E=\pm4$ and a logarithmic singularity at $E=0$ [2509.18829].

The known singular part is represented directly as a `PiecewiseFunction`:
```julia
singularity = PiecewiseFunction(:even,
    Piece((0, 4), (false, true), LOG,
          [0, -1 / (2 * pi^2)]))
```
and the regular residual is then fitted polynomially:
```julia
f = piecewisefit(E -> N(E) - singularity(E),
                 (0, 4), [POLY], parity = :even, rtol = 5e-6)
f += singularity
```
The resulting `PiecewiseFunction` has one piece on `(0,4)` combining `POLY` and `LOG` formulas [2509.18829]. The paper reports the verification
```julia
maximum(LinRange(-4, 4, 1000) .|> E ->
    abs(f(E) ./ N(E) - 1)) < 1e-5
```
which establishes relative error below $10^{-5}$ across the full support [2509.18829].

Although the short article stops at the fit, the linked Tutorial 2 shows how PiecewiseHilbert is used to solve an implicit equation involving Hilbert transforms [2509.18829]. The motivating physical pattern is a Kramers–Kronig-type relation such as
$$
\Re \Sigma(\omega) = \frac{1}{\pi} \operatorname{p.v.} \int_{-\infty}^{\infty} d\omega'
  \frac{\Im \Sigma(\omega')}{\omega' - \omega},
$$
where the imaginary part is represented as a piecewise function with singular features captured analytically and the real part is recovered efficiently through the Hilbert transform [2509.18829].

This example also clarifies what “fast” means in context. The gain does not come from asymptotically faster transforms in the FFT sense; it comes from eliminating repeated numerical quadrature in iterative workflows once the piecewise approximation has been constructed.

## 6. Applications, related transforms, and limitations

The code was written to support applications including `MagnetoTransport.jl`, linear magneto-transport with local self-energy, and the paper associates the broader framework with problems such as superconductivity in metallic hydrogen and Hall response of correlated electrons [2509.18829]. In these contexts, Hilbert transforms occur inside coupled integral equations and self-consistent spectral calculations, where repeated evaluation of Cauchy-type transforms is a bottleneck [2509.18829].

The relation to `PiecewiseLorentz` is close. The Lorentz transform uses kernels of the form
$$
K(x,z) = \frac{1}{z - x}, \quad z \in \mathbb{C} \setminus \mathbb{R},
$$
so `PiecewiseHilbert` and `PiecewiseLorentz` are both built on Cauchy-type kernels and differ mainly in whether the evaluation point is real or complex [2509.18829]. The base `Piecewise` module’s seven moment formulas are likewise part of the same analytic-integration philosophy, with the kernel $K(x,n)=x^n$ replacing the Hilbert kernel [2509.18829].

Several limitations are explicit. Fast analytic Hilbert transforms are available only for the pre-defined formulas extended by PiecewiseHilbert [2509.18829]. The library targets one-dimensional transforms of functions of a single real variable, and multi-dimensional Hilbert transforms are not supported [2509.18829]. The representation is tied to a finite union of intervals on the real line, so infinite support requires truncation or another compactification strategy chosen by the user [2509.18829]. The methodology also presumes that the user can choose basis formulas matching the singularities of the problem [2509.18829].

These limitations distinguish PiecewiseHilbert from other Hilbert-transform frameworks. One-sided Hilbert transforms on the half-line are naturally analyzed in Mellin space, where the transform acts by multiplication with $-\cot(\pi s)$ and solutions can develop a universal $t^{-1/2}$ singularity at the origin when the Mellin transform of the data does not vanish at $s=1/2$ [2302.03521]. Finite Hilbert transforms on bounded intervals can require delicate handling of endpoint layers under discretization [2303.13693]. Curved Hilbert transforms along monomial curves require non-isotropic cube systems and curve-adapted BMO spaces [1909.02118]. PiecewiseHilbert does not attempt to subsume these geometrically different theories; it addresses the narrower but practically important case of analytic Cauchy-type transforms of fitted one-dimensional piecewise models.

A plausible implication is that the module’s future development would most naturally proceed by enlarging the basis family and adding new transform kernels rather than by generalizing immediately to higher-dimensional singular integral geometry. The paper explicitly suggests increasing the repertoire of basis formulas, extending the methodology to new kernels, and possibly exploring multi-dimensional generalizations or automated symbolic generation of transform formulas [2509.18829].

Source: https://www.emergentmind.com/topics/piecewisehilbert