%% Write  basic article template

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}
\usepackage{sagetex}
\usepackage{minted}
\usepackage{subcaption}
\usepackage[]{breqn}

\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\chern}{\operatorname{ch}}
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\firsttilt}[1]{\mathcal{B}^{#1}}
\newcommand{\bddderived}{\mathcal{D}^{b}}
\newcommand{\centralcharge}{\mathcal{Z}}
\newcommand{\minorheading}[1]{{\noindent\normalfont\normalsize\bfseries #1}}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemmadfn}{Lemma/Definition}[section]
\newtheorem{dfn}{Definition}[section]

\begin{document}

\begin{sagesilent}
# Requires extra package:
#! sage -pip install "pseudowalls==0.0.3" --extra-index-url https://gitlab.com/api/v4/projects/43962374/packages/pypi/simple

from pseudowalls import *

Δ = lambda v: v.Q_tilt()
mu = stability.Mumford().slope
\end{sagesilent}

\title{Explicit Formulae for Bounds on the Ranks of Tilt Destabilizers and
Practical Methods for Finding Pseudowalls}

\author{Luke Naylor}

\maketitle

\section{Introduction}
\label{sec:intro}

[ref] shows that for any rational $\beta_0$,
the vertical line $\{\sigma_{\alpha,\beta_0} \colon \alpha \in \RR_{>0}\}$ only
intersects finitely many walls. A consequence of this is that if
$\beta_{-}$ is rational, then there can only be finitely many circular walls to the
left of the vertical wall $\beta = \mu$.
On the other hand, when $\beta_{-}$ is not rational, [ref] showed that there are
infinitely many walls.

This dichotomy does not only hold for real walls, realised by actual objects in
$\bddderived(X)$, but also for pseudowalls. Here pseudowalls are defined as
`potential' walls, induced by hypothetical Chern characters of destabilizers
which satisfy certain numerical conditions which would be satisfied by any real
destabilizer, regardless of whether they are realised by actual semistabilizers
in $\bddderived(X)$.

Since real walls are a subset of pseudowalls, the irrational $\beta_{-}$ case
follows immediately from the corresponding case for real walls.
However, the rational $\beta_{-}$ case involves showing that the following
conditions only admit finitely many solutions (despite the fact that the same
conditions admit infinitely many solutions when $\beta_{-}$ is irrational).


For a destabilizing sequence
$E \hookrightarrow F \twoheadrightarrow G$ in $\mathcal{B}^\beta$
we have the following conditions.
There are some Bogomolov-Gieseker type inequalities:
$0 \leq \Delta(E), \Delta(G)$ and $\Delta(E) + \Delta(G) \leq \Delta(F)$.
We also have a condition relating to the tilt category $\firsttilt\beta$:
$0 \leq \chern^\beta_1(E) \leq \chern^\beta_1(F)$.
Finally, there's a condition ensuring that the radius of the circular wall is
strictly positive: $\chern^{\beta_{-}}_2(E) > 0$.

For any fixed $\chern_0(E)$, the inequality
$0 \leq \chern^{\beta}_1(E) \leq \chern^{\beta}_1(F)$,
allows us to bound $\chern_1(E)$. Then, the other inequalities allow us to
bound $\chern_2(E)$. The final part to showing the finiteness of pseudowalls
would be bounding $\chern_0(E)$. This has been hinted at in [ref] and done
explicitly by Benjamin Schmidt within a computer program which computes
pseudowalls. Here we discuss these bounds in more detail, along with the methods
used, followed by refinements on them which give explicit formulae for tighter
bounds on $\chern_0(E)$ of potential destabilizers $E$ of $F$.


\section{Characteristic Curves of Stability Conditions Associated to Chern
Characters}

\begin{sagesilent}
v = Chern_Char(3, 2, -2)
u = Chern_Char(1, 0, 0)

alpha = stability.Tilt().alpha
beta = stability.Tilt().beta

coords_range = (beta, -5, 5), (alpha, 0, 5)

charact_curve_plot = (
	implicit_plot(stability.Tilt().degree(u), *coords_range , rgbcolor = "red")
	+ implicit_plot(stability.Tilt().degree(v), *coords_range )
	+ line([(mu(v),0),(mu(v),5)], linestyle = "dashed", legend_label =
	r"$(3,2\ell,-4\ell^2/2)$")
	+ line([(mu(u),0),(mu(u),5)], rgbcolor = "red", linestyle =
	"dashed", legend_label = r"$(1,0,0)$")
	+ implicit_plot(stability.Tilt().wall_eqn(u,v)/alpha,
	*coords_range , rgbcolor = "black")
)
charact_curve_plot.xmax(1)
charact_curve_plot.xmin(-2)
charact_curve_plot.ymax(1.5)
charact_curve_plot.axes_labels([r"$\beta$", r"$\alpha$"])
\end{sagesilent}

\begin{figure}
  \centering
	\sageplot[width=\linewidth]{charact_curve_plot}
	\caption{}
  \label{fig:characteristic-curves-example}
\end{figure}

Talk about figure \ref{fig:characteristic-curves-example}.


\section{Loose Bounds on $\chern_0(E)$ for Semistabilizers Along Fixed
$\beta\in\QQ$}

\begin{dfn}[Twisted Chern Character]
\label{sec:twisted-chern}
For a given $\beta$, define the twisted Chern character as follows.
\[\chern^\beta(E) = \chern(E) \cdot \exp(-\beta \ell)\]
\noindent
Component-wise, this is:
\begin{align*}
	\chern^\beta_0(E) &= \chern_0(E)
\\
	\chern^\beta_1(E) &= \chern_1(E) - \beta \chern_0(E)
\\
	\chern^\beta_2(E) &= \chern_2(E) - \beta \chern_1(E) + \frac{\beta^2}{2} \chern_0(E)
\end{align*}

% TODO I think this^ needs adjusting for general Surface with $\ell$
\end{dfn}

$\chern^\beta_1(E)$ is the imaginary component of the central charge
$\centralcharge_{\alpha,\beta}(E)$ and any element of $\firsttilt\beta$
satisfies $\chern^\beta_1 \geq 0$. This, along with additivity gives us, for any
destabilizing sequence [ref]:
\begin{equation}
	\label{eqn-tilt-cat-cond}
	0 \leq \chern^\beta_1(E) \leq \chern^\beta_1(F)
\end{equation}

When finding Chern characters of potential destabilizers $E$ for some fixed
Chern character $\chern(F)$, this bounds $\chern_1(E)$.

The Bogomolov form applied to the twisted Chern character is the same as the
normal one. So $0 \leq \Delta(E)$ yields:

\begin{equation}
	\label{eqn-bgmlv-on-E}
	2\chern^\beta_0(E) \chern^\beta_2(E) \leq \chern^\beta_1(E)^2
\end{equation}

\begin{theorem}[Bound on $r$ - Benjamin Schmidt]
Given a Chern character $v$ such that $\beta_{-}(v)\in\QQ$, the rank $r$ of
any semistabilizer $E$ of some $F \in \firsttilt\beta$ with $\chern(F)=v$ is
bounded above by:

\begin{equation*}
	r \leq \frac{mn^2 \chern^\beta_1(v)^2}{\gcd(m,2n^2)}
\end{equation*}
\end{theorem}

\begin{proof}

The restrictions on $\chern^\beta_0(E)$ and $\chern^\beta_2(E)$
is best seen with the following graph:

% TODO: hyperbola restriction graph (shaded)
\begin{sagesilent}
var("m") # Initialize symbol for variety parameter
\end{sagesilent}

This is where the rationality of $\beta_{-}$ comes in. If $\beta_{-} = \frac{*}{n}$
for some $*,n \in \ZZ$.
Then $\chern^\beta_2(E) \in \frac{1}{\lcm(m,2n^2)}\ZZ$ where $m$ is the integer
which guarantees $\chern_2(E) \in \frac{1}{m}\ZZ$ (determined by the variety).
In particular, since $\chern_2(E) > 0$ we must also have
$\chern^\beta_2(E) \geq \frac{1}{\lcm(m,2n^2)}$, which then in turn gives a bound
for the rank of $E$:

\begin{align}
	\chern_0(E) &= \chern^\beta_0(E) \\
	&\leq \frac{\lcm(m,2n^2) \chern^\beta_1(E)^2}{2} \\
	&\leq \frac{mn^2 \chern^\beta_1(F)^2}{\gcd(m,2n^2)}
\end{align}

\end{proof}

\section{B.Schmidt's Method}

\section{Limitations}

\section{Refinement}
\label{sec:refinement}

To get tighter bounds on the rank of destabilizers $E$ of some $F$ with some
fixed Chern character, we will need to consider each of the values which
$\chern_1^{\beta}(E)$ can take.
Doing this will allow us to eliminate possible values of $\chern_0(E)$ for which
each $\chern_1^{\beta}(E)$ leads to the failure of at least one of the inequalities.
As opposed to only eliminating possible values of $\chern_0(E)$ for which all
corresponding $\chern_1^{\beta}(E)$ fail one of the inequalities (which is what
was implicitly happening before).

First, let us fix a Chern character for $F$,
$\chern(F) = (R,C,D)$, and consider the possible Chern characters
$\chern(E) = (r,c,d)$ of some semistabilizer $E$.
 
\begin{sagesilent}
# Requires extra package:
#! sage -pip install "pseudowalls==0.0.3" --extra-index-url https://gitlab.com/api/v4/projects/43962374/packages/pypi/simple

from pseudowalls import *

v = Chern_Char(*var("R C D", domain="real"))
u = Chern_Char(*var("r c d", domain="real"))

Δ = lambda v: v.Q_tilt()
\end{sagesilent}

Recall [ref] that $\chern_1^{\beta}$ has fixed bounds in terms of
$\chern(F)$, and so we can write:

\begin{sagesilent}
ts = stability.Tilt
var("beta", domain="real")

c_lower_bound = -(
	ts(beta=beta).rank(u)
	/ts().alpha
).expand() + c

var("q", domain="real")
c_in_terms_of_q = c_lower_bound + q
\end{sagesilent}

\begin{equation}
	\label{eqn-cintermsofm}
	c=\chern_1(E) = \sage{c_in_terms_of_q}
	\qquad 0 \leq q \leq \chern_1^{\beta}(F)
\end{equation}

Furthermore, $\chern_1 \in \ZZ$ so we only need to consider
$q \in \frac{1}{n} \ZZ \cap [0, \chern_1^{\beta}(F)]$.
For the next subsections, we consider $q$ to be fixed with one of these values,
and we shall be varying $\chern_0(E) = r$ to see when certain inequalities fail.


\subsection{
	\texorpdfstring{
		$\Delta(E) + \Delta(G) \leq \Delta(F)$
	}{
		Δ(E) + Δ(G) ≤ Δ(F)
	}
}
\label{subsect-d-bound-bgmlv1}

This condition expressed in terms of $R,C,D,r,c,d$ looks as follows:

\begin{sagesilent}
# First Bogomolov-Gieseker form expression that must be non-negative:
bgmlv1 = Δ(v) - Δ(u) - Δ(v-u)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv1.expand() }
\end{equation}


\noindent
Expressing $c$ in terms of $q$ as defined in (eqn \ref{eqn-cintermsofm})
we get the following:

\begin{sagesilent}
bgmlv1_with_q = (
	bgmlv1
	.expand()
	.subs(c == c_in_terms_of_q)
)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv1_with_q}
\end{equation}


\noindent
This can be rearranged to express a bound on $d$ as follows:

\begin{sagesilent}
var("r_alt",domain="real") # r_alt = r - R/2 temporary substitution

bgmlv1_with_q_reparam = (bgmlv1_with_q.subs(r == r_alt + R/2)/r_alt).expand()

bgmlv1_d_ineq = (
	((0 >= -bgmlv1_with_q_reparam)/4 + d) # Rearrange for d
	.subs(r_alt == r - R/2) # Resubstitute r back in
	.expand()
)

bgmlv1_d_lowerbound = bgmlv1_d_ineq.rhs() # Keep hold of lower bound for d
\end{sagesilent}

\begin{dmath}
	\label{eqn-bgmlv1_d_lowerbound}
	\sage{bgmlv1_d_ineq}
\end{dmath}

\begin{sagesilent}
# Separate out the terms of the lower bound for d
bgmlv1_d_lowerbound_without_hyp = bgmlv1_d_lowerbound.subs(1/(R-2*r) == 0)

bgmlv1_d_lowerbound_exp_term = (
	bgmlv1_d_lowerbound
	- bgmlv1_d_lowerbound_without_hyp
).expand()

bgmlv1_d_lowerbound_const_term = bgmlv1_d_lowerbound_without_hyp.subs(r==0)

bgmlv1_d_lowerbound_linear_term = (
	bgmlv1_d_lowerbound_without_hyp
	- bgmlv1_d_lowerbound_const_term
).expand()

# Verify the simplified forms of the terms that will be mentioned in text
var("chbv",domain="real") # symbol to represent ch_1^\beta(v)

assert bgmlv1_d_lowerbound_const_term == (
	(
		# Keep hold of this alternative expression:
		bgmlv1_d_lowerbound_const_term_alt :=
		(
			chbv/2
			+ beta*q
		)
	)
	.subs(chbv == v.twist(beta).ch[2])
	.expand()
)

assert bgmlv1_d_lowerbound_exp_term == (
	(
		# Keep hold of this alternative expression:
		bgmlv1_d_lowerbound_exp_term_alt :=
		(
			- R*chbv/2
			- R*beta*q
			+ C*q
			- q^2
		)/(R-2*r)
	)
	.subs(chbv == v.twist(beta).ch[2])
	.expand()
)
\end{sagesilent}


\noindent
Viewing equation \ref{eqn-bgmlv1_d_lowerbound} as a lower bound for $d$ given
as a function of $r$, the terms can be rewritten as follows.
The constant term in $r$ is
$\chern^{\beta}_2(F)/2 + \beta q$.
The linear term in $r$ is
$\sage{bgmlv1_d_lowerbound_linear_term}$.
Finally, there's an hyperbolic term in $r$ which tends to 0 as $r \to \infty$,
and can be written:
$\frac{R\chern^{\beta}_2(F)/2 + R\beta q - Cq + q^2  }{2r-R}$.
In the case $\beta = \beta_{-}$ (or $\beta_{+}$) we have
$\chern^{\beta}_2(F) = 0$,
so some of these expressions simplify.

\subsection{
	\texorpdfstring{
		$\Delta(E) \geq 0$
	}{
		Δ(E) ≥ 0
	}
}

This condition expressed in terms of $R,C,D,r,c,d$ looks as follows:

\begin{sagesilent}
# First Bogomolov-Gieseker form expression that must be non-negative:
bgmlv2 = Δ(u)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv2.expand() }
\end{equation}


\noindent
Expressing $c$ in terms of $q$ as defined in (eqn \ref{eqn-cintermsofm})
we get the following:

\begin{sagesilent}
bgmlv2_with_q = (
	bgmlv2
	.expand()
	.subs(c == c_in_terms_of_q)
)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv2_with_q}
\end{equation}


\noindent
This can be rearranged to express a bound on $d$ as follows:

\begin{sagesilent}
bgmlv2_d_ineq = (
	(0 <= bgmlv2_with_q)/2/r # rescale assuming r > 0
	+ d # Rearrange for d
).expand()

# Keep hold of lower bound for d
bgmlv2_d_upperbound = bgmlv2_d_ineq.rhs()
\end{sagesilent}

\begin{equation}
	\label{eqn-bgmlv2_d_upperbound}
	\sage{bgmlv2_d_ineq}
\end{equation}

\begin{sagesilent}
# Seperate out the terms of the lower bound for d

bgmlv2_d_upperbound_without_hyp = (
	bgmlv2_d_upperbound
	.subs(1/r == 0)
)

bgmlv2_d_upperbound_const_term = (
	bgmlv2_d_upperbound_without_hyp
	.subs(r==0)
)

bgmlv2_d_upperbound_linear_term = (
	bgmlv2_d_upperbound_without_hyp
	- bgmlv2_d_upperbound_const_term
).expand()

bgmlv2_d_upperbound_exp_term = (
	bgmlv2_d_upperbound
	- bgmlv2_d_upperbound_without_hyp
).expand()
\end{sagesilent}

Viewing equation \ref{eqn-bgmlv2_d_upperbound} as a lower bound for $d$ in term
of $r$ again, there's a constant term
$\sage{bgmlv2_d_upperbound_const_term}$,
a linear term
$\sage{bgmlv2_d_upperbound_linear_term}$,
and a hyperbolic term
$\sage{bgmlv2_d_upperbound_exp_term}$.
Notice that for $\beta = \beta_{-}$ (or $\beta_{+}$), that is when
$\chern^{\beta}_2(F)=0$, the constant and linear terms match up with the ones
for the bound found for $d$ in subsection \ref{subsect-d-bound-bgmlv1}.

\subsection{
	\texorpdfstring{
		$\Delta(G) \geq 0$
	}{
		Δ(G) ≥ 0
	}
}
\label{subsect-d-bound-bgmlv3}

This condition expressed in terms of $R,C,D,r,c,d$ looks as follows:

\begin{sagesilent}
# Third Bogomolov-Gieseker form expression that must be non-negative:
bgmlv3 = Δ(v-u)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv3.expand() }
\end{equation}


\noindent
Expressing $c$ in terms of $q$ as defined in (eqn \ref{eqn-cintermsofm})
we get the following:

\begin{sagesilent}
bgmlv3_with_q = (
	bgmlv3
	.expand()
	.subs(c == c_in_terms_of_q)
)
\end{sagesilent}

\begin{equation}
	\sage{0 <= bgmlv3_with_q}
\end{equation}


\noindent
This can be rearranged to express a bound on $d$ as follows:

\begin{sagesilent}
var("r_alt",domain="real") # r_alt = r - R temporary substitution

bgmlv3_with_q_reparam = (
	bgmlv3_with_q
	.subs(r == r_alt + R)
	/r_alt # This operation assumes r_alt > 0
).expand()

bgmlv3_d_ineq = (
	((0 <= bgmlv3_with_q_reparam)/2 + d) # Rearrange for d
	.subs(r_alt == r - R) # Resubstitute r back in
	.expand()
)

# Check that this equation represents a bound for d
assert bgmlv3_d_ineq.lhs() == d

bgmlv3_d_upperbound = bgmlv3_d_ineq.rhs() # Keep hold of lower bound for d
\end{sagesilent}

\begin{dmath}
	\label{eqn-bgmlv3_d_upperbound}
	\sage{bgmlv3_d_ineq}
\end{dmath}

\begin{sagesilent}
# Seperate out the terms of the lower bound for d

bgmlv3_d_upperbound_without_hyp = (
	bgmlv3_d_upperbound
	.subs(1/(R-r) == 0)
)

bgmlv3_d_upperbound_const_term = (
	bgmlv3_d_upperbound_without_hyp
	.subs(r==0)
)

bgmlv3_d_upperbound_linear_term = (
	bgmlv3_d_upperbound_without_hyp
	- bgmlv3_d_upperbound_const_term
).expand()

bgmlv3_d_upperbound_exp_term = (
	bgmlv3_d_upperbound
	- bgmlv3_d_upperbound_without_hyp
).expand()

# Verify the simplified forms of the terms that will be mentioned in text

var("chbv",domain="real") # symbol to represent ch_1^\beta(v)

assert bgmlv3_d_upperbound_const_term == ( 
	(
		# keep hold of this alternative expression:
		bgmlv3_d_upperbound_const_term_alt := (
			chbv
			+ beta*q
		)
	)
	.subs(chbv == v.twist(beta).ch[2]) # subs real val of ch_1^\beta(v)
	.expand()
)

assert bgmlv3_d_upperbound_exp_term == (
	(
		# Keep hold of this alternative expression:
		bgmlv3_d_upperbound_exp_term_alt :=
		(
			R*chbv
			+ (C - q)^2/2
			+ R*beta*q
			- D*R
		)/(r-R)
	)
	.subs(chbv == v.twist(beta).ch[2]) # subs real val of ch_1^\beta(v)
	.expand()
)
\end{sagesilent}


\noindent
Viewing equation \ref{eqn-bgmlv3_d_upperbound} as an upper bound for $d$ give:
as a function of $r$, the terms can be rewritten as follows.
The constant term in $r$ is
$\chern^{\beta}_2(F) + \beta q$.
The linear term in $r$ is
$\sage{bgmlv3_d_upperbound_linear_term}$.
Finally, there's an hyperbolic term in $r$ which tends to 0 as $r \to \infty$,
and can be written:
$\frac{R\chern^{\beta}_2(F) + (C-q)^2/2 + R\beta q - DR}{r-R}$.
In the case $\beta = \beta_{-}$ (or $\beta_{+}$) we have
$\chern^{\beta}_2(F) = 0$,
so some of these expressions simplify, and in particular, the constant and
linear terms match those of the other bounds in the previous subsections.

\subsection{Bounds on \texorpdfstring{$r$}{r}}

Now, the inequalities from the last three subsections will be used to find, for
each given $q=\chern^{\beta}_1(E)$, how large $r$ needs to be in order to leave
no possible solutions for $d$. At that point, there are no Chern characters
$(r,c,d)$ that satisfy all inequalities to give a pseudowall.

\subsubsection{All circular pseudowalls left of vertical wall}

Suppose we take $\beta = \beta_{-}$ (so that $\chern^{\beta}_2(F)=0$)
in the previous subsections, to find all circular walls to the left of the
vertical wall (TODO as discussed in ref).

% redefine \beta (especially coming from rendered SageMath expressions)
% to be \beta_{-} for the rest of this subsubsection
\bgroup

\let\originalbeta\beta
\renewcommand\beta{{\originalbeta_{-}}}

\begin{align}
	d &\geq&
	\sage{bgmlv1_d_lowerbound_linear_term}
	&+ \sage{bgmlv1_d_lowerbound_const_term_alt.subs(chbv == 0)}
	+& \sage{bgmlv1_d_lowerbound_exp_term_alt.subs(chbv == 0)},
	 &\qquad\text{when\:} r > \frac{R}{2}
	 \label{eqn:bgmlv1_d_bound_betamin}
\\
	d &\leq&
	\sage{bgmlv2_d_upperbound_linear_term}
	&+ \sage{bgmlv2_d_upperbound_const_term}
	+& \sage{bgmlv2_d_upperbound_exp_term},
	 &\qquad\text{when\:} r > 0
	 \label{eqn:bgmlv2_d_bound_betamin}
\\
	d &\leq&
	\sage{bgmlv3_d_upperbound_linear_term}
	&+ \sage{bgmlv3_d_upperbound_const_term_alt.subs(chbv == 0)}
	+& \sage{bgmlv3_d_upperbound_exp_term_alt.subs(chbv == 0)},
	 &\qquad\text{when\:} r > R
	 \label{eqn:bgmlv3_d_bound_betamin}
\end{align}

Furthermore, we get an extra bound for $d$ resulting from the condition that the
radius of the circular wall must be positive. As discussed in (TODO ref), this
is equivalent to $\chern^{\beta}_2(E) > 0$, which yields:

\begin{sagesilent}
positive_radius_condition = (
	(
		(0 > - u.twist(beta).ch[2])
		+ d # rearrange for d
	)
	.subs(solve(q == u.twist(beta).ch[1], c)[0]) # express c in term of q
	.expand()
)
\end{sagesilent}

\begin{equation}
	\label{eqn:positive_rad_d_bound_betamin}
	\sage{positive_radius_condition}
\end{equation}
\begin{sagesilent}
def beta_min(chern):
  ts = stability.Tilt()
  return min(
    map(
      lambda soln: soln.rhs(),
      solve(
        (ts.degree(chern))
          .expand()
          .subs(ts.alpha == 0),
        beta
      )
    )
  )

v_example = Chern_Char(3,2,-2)
q_example = 7/3

def plot_d_bound(
  v_example,
  q_example,
  ymax=5,
  ymin=-2,
  xmax=20,
  aspect_ratio=None
):

  # Equations to plot imminently representing the bounds on d:
  eq1 = (
    bgmlv1_d_lowerbound
    .subs(R == v_example.ch[0])
    .subs(C == v_example.ch[1])
    .subs(D == v_example.ch[2])
    .subs(beta = beta_min(v_example))
    .subs(q == q_example)
  )

  eq2 = (
    bgmlv2_d_upperbound
    .subs(R == v_example.ch[0])
    .subs(C == v_example.ch[1])
    .subs(D == v_example.ch[2])
    .subs(beta = beta_min(v_example))
    .subs(q == q_example)
  )

  eq3 = (
    bgmlv3_d_upperbound
    .subs(R == v_example.ch[0])
    .subs(C == v_example.ch[1])
    .subs(D == v_example.ch[2])
    .subs(beta = beta_min(v_example))
    .subs(q == q_example)
  )

  eq4 = (
    positive_radius_condition.rhs()
    .subs(q == q_example)
    .subs(beta = beta_min(v_example))
  )

  example_bounds_on_d_plot = (
    plot(
      eq3,
      (r,v_example.ch[0],xmax),
      color='green',
			linestyle = "dashed",
      legend_label=r"upper bound: $\Delta(G) \geq 0$",
    )
    + plot(
      eq2,
      (r,0,xmax),
      color='blue',
			linestyle = "dashed",
      legend_label=r"upper bound: $\Delta(E) \geq 0$"
    )
    + plot(
      eq4,
      (r,0,xmax),
      color='orange',
			linestyle = "dotted",
      legend_label=r"lower bound: $\mathrm{ch}_2^{\beta_{-}}(E)>0$"
    )
    + plot(
      eq1,
      (r,v_example.ch[0]/2,xmax),
      color='red',
			linestyle = "dotted",
      legend_label=r"lower bound: $\Delta(E) + \Delta(G) \leq \Delta(F)$"
    )
  )
  example_bounds_on_d_plot.ymin(ymin)
  example_bounds_on_d_plot.ymax(ymax)
  example_bounds_on_d_plot.axes_labels(['$r$', '$d$'])
  if aspect_ratio:
    example_bounds_on_d_plot.set_aspect_ratio(aspect_ratio)
  return example_bounds_on_d_plot

\end{sagesilent}

\begin{figure}
\centering
\begin{subfigure}{.45\textwidth}
  \centering
	\sageplot[width=\linewidth]{plot_d_bound(v_example, 0)}
	\caption{$q = 0$ (all bounds other than green coincide on line)}
  \label{fig:d_bounds_xmpl_min_q}
\end{subfigure}%
\hfill
\begin{subfigure}{.45\textwidth}
  \centering
	\sageplot[width=\linewidth]{plot_d_bound(v_example, 4)}
	\caption{$q = \chern^{\beta}(F)$ (all bounds other than blue coincide on line)}
  \label{fig:d_bounds_xmpl_max_q}
\end{subfigure}
\caption{
	Bounds on $d:=\chern_2(E)$ in terms of $r:=\chern_0(E)$ for fixed, extreme,
	values of $q:=\chern_1^{\beta}(E)$.
	Where $\chern(F) = (3,2,-2)$.
}
\label{fig:d_bounds_xmpl_extrm_q}
\end{figure}

Recalling that $q := \chern^{\beta}_1(E) \in [0, \chern^{\beta}_1(F)]$,
it's worth noting that the extreme values of $q$ in this range lead to the
tightest bounds on $d$, as illustrated in figure
(\ref{fig:d_bounds_xmpl_extrm_q}).
In fact, in each case, one of the weak upper bounds coincides with one of the
weak lower bounds, (implying no possible destabilizers $E$ with
$\chern_0(E)=:r>R:=\chern_0(F)$ for these $q$-values).
This indeed happens in general since the right hand sides of
(eqn \ref{eqn:bgmlv2_d_bound_betamin}) and
(eqn \ref{eqn:positive_rad_d_bound_betamin}) match when $q=0$.
In the other case, $q=\chern^{\beta}_1(F)$, it's the right hand sides of
(eqn \ref{eqn:bgmlv3_d_bound_betamin}) and
(eqn \ref{eqn:positive_rad_d_bound_betamin}) which match.


The more generic case, when $0 < q:=\chern_1^{\beta}(E) < \chern_1^{\beta}(F)$
for the bounds on $d$ in terms of $r$ is illustrated in figure
(\ref{fig:d_bounds_xmpl_gnrc_q}).
The question of whether there are pseudo-destabilizers of arbitrarily large
rank, in the context of the graph, comes down to whether there are points
$(r,d) \in \ZZ \oplus \frac{1}{m} \ZZ$ (with large $r$)
% TODO have a proper definition for pseudo-destabilizers/walls
that fit above the yellow line (ensuring positive radius of wall) but below the
blue and green (ensuring $\Delta(E), \Delta(G) > 0$).
These lines have the same assymptote at $r \to \infty$
(eqns \ref{eqn:bgmlv2_d_bound_betamin},
\ref{eqn:bgmlv3_d_bound_betamin},
\ref{eqn:positive_rad_d_bound_betamin}).
As mentioned in the introduction (sec \ref{sec:intro}), the finiteness of these
solutions is entirely determined by whether $\beta$ is rational or irrational.
Some of the details around the associated numerics are explored next.

\begin{figure}
\centering
\sageplot[
	width=\linewidth
]{plot_d_bound(v_example, 2, ymax=6, ymin=-0.5, aspect_ratio=1)}
\caption{
	Bounds on $d:=\chern_2(E)$ in terms of $r:=\chern_0(E)$ for a fixed
	value $\chern_1^{\beta}(F)/2$ of $q:=\chern_1^{\beta}(E)$.
	Where $\chern(F) = (3,2,-2)$.
}
\label{fig:d_bounds_xmpl_gnrc_q}
\end{figure}


\minorheading{Rational $\beta\not=0$}

The strategy here is similar to what was shown in (sect \ref{sec:twisted-chern}),
% ref to Schmidt?

\begin{sagesilent}
var("a_F b_q n") # Define symbols introduce for values of beta and q
beta_value_expr = (beta == a_F/n)
q_value_expr = (q == b_q/n)
\end{sagesilent}

\renewcommand{\aa}{{a_F}}
\newcommand{\bb}{{b_q}}
Suppose $\beta = \frac{\aa}{n}$ for some coprime $n \in \NN,\aa \in \ZZ$.
Then fix a value of $q$:
\begin{equation}
	q:=\chern_1^{\beta}(E)
	  =\frac{\bb}{n}
	\in
	\frac{1}{n} \ZZ
	\cap [0, \chern_1^{\beta}(F)]
\end{equation}
as noted at the beginning of this section (\ref{sec:refinement}).

Substituting the current values of $q$ and $\beta$ into the condition for the
radius of the pseudo-wall being positive
(eqn \ref{eqn:positive_rad_d_bound_betamin}) we get:

\begin{equation}
\label{eqn:positive_rad_condition_in_terms_of_q_beta}
	\frac{1}{m}\ZZ
	\ni
	\qquad
	\sage{positive_radius_condition.subs([q_value_expr,beta_value_expr]).factor()}
	\qquad
	\in
	\frac{1}{2n^2}\ZZ
\end{equation}

\begin{theorem}[Bound on $r$ \#1]
\label{thm:rmax_with_uniform_eps}
	Let $v = (R,C,D)$ be a fixed Chern character. Then the ranks of the
	pseudo-semistabilizers for $v$ are bounded above by the following expression.

	\begin{align*}
		&\frac{\lcm(m,2n^2)}{2}
		\max_{q \in [0,\chern_1^\beta(v)]}
	\\
		&\left\{
			\min
			\left(
				q^2,
				2R\beta q
				+C^2
				-2DR
				-2Cq
				+q^2
				+\frac{R}{\lcm(m,2n^2)}
			\right)
		\right\}
	\end{align*}
\end{theorem}

\begin{proof}

\noindent
Both $d$ and the lower bound in
(eqn \ref{eqn:positive_rad_condition_in_terms_of_q_beta})
are elements of $\frac{1}{\lcm(m,2n^2)}\ZZ$.
So, if any of the two upper bounds on $d$ come to within
$\frac{1}{\lcm(m,2n^2)}$ of this lower bound, then there are no solutions for
$d$.

Considering equations
\ref{eqn:bgmlv2_d_bound_betamin},
\ref{eqn:bgmlv3_d_bound_betamin},
\ref{eqn:positive_rad_d_bound_betamin},
this happens when:

\bgroup

\let\originalepsilon\epsilon
\renewcommand\epsilon{{\originalepsilon_{F}}}

\begin{sagesilent}
var("epsilon")

# Tightness conditions:

bounds_too_tight_condition1 = (
	bgmlv2_d_upperbound_exp_term
	< epsilon
)

bounds_too_tight_condition2 = (
	bgmlv3_d_upperbound_exp_term_alt.subs(chbv==0)
	< epsilon
)
\end{sagesilent}

\begin{equation}
	\min\left(
		\sage{bgmlv2_d_upperbound_exp_term},
		\sage{bgmlv3_d_upperbound_exp_term_alt.subs(chbv==0)}
	\right)
	< \epsilon := \frac{1}{\lcm(m,2n^2)}
\end{equation}

\begin{sagesilent}
# rearrange the "tightness" conditions in terms of r

bounds_too_tight_condition1 = (
	(bounds_too_tight_condition1 * r / epsilon)
	.expand()
)
bounds_too_tight_condition2 = (
	(bounds_too_tight_condition2 * (r - R) / epsilon + R)
	.expand()
)

# Check that these are indeed rearranged for r
assert bounds_too_tight_condition1.rhs() == r
assert bounds_too_tight_condition2.rhs() == r
\end{sagesilent}

\noindent
This is equivalent to:

\begin{equation}
	r >
	\min\left(
		\sage{
			bounds_too_tight_condition1.lhs()
			.expand()
			.factor()
		} ,
		\sage{
			bounds_too_tight_condition2.lhs()
			.expand()
			.factor()
		}
	\right)
\end{equation}

If this condition holds for all $q$, then there are no solutions for $d$,
and therefore $r$ cannot satisfy this condition for all $q$.
Taking the maximum of all these expressions over $q$, and substituting the value
for $\epsilon$ gives the result.

\egroup % end scope where epsilon redefined

\end{proof}

%% TODO simplified expression for rmax by predicting which q gives rmax

%% refinements using specific values of q and beta

This bound can be refined a bit more by considering restrictions from the
possible values that $r$ take.
Furthermore, the proof of theorem \ref{thm:rmax_with_uniform_eps} uses the fact
that, given an element of $\frac{1}{2n^2}\ZZ$, the closest non-equal element of
$\frac{1}{m}\ZZ$ is at least $\frac{1}{\lcm(m,2n^2)}$ away. However this a
conservative estimate, and a larger gap can sometimes be guaranteed if we know
this value of $\frac{1}{2n^2}\ZZ$ explicitly. 

The expressions that will follow will be a bit more complicated and have more
parts which depend on the values of $q$ and $\beta$, even their numerators
$\aa,\bb$ specifically. The upcoming theorem (TODO ref) is less useful as a
`clean' formula for a bound on the ranks of the pseudo-semistabilizers, but has a
purpose in the context of writing a computer program to find
pseudo-semistabilizers. Such a program would iterate through possible values of
$q$, then iterate through values of $r$ within the bounds (dependent on $q$),
which would then determine $c$, and then find the corresponding possible values
for $d$.


Firstly, we only need to consider $r$-values for which $c:=\chern_1(E)$ is
integral:

\begin{equation}
	c =
	\sage{c_in_terms_of_q.subs([q_value_expr,beta_value_expr])}
	\in \ZZ
\end{equation}

\noindent
That is, $r \equiv -\aa^{-1}\bb$ mod $n$ ($\aa$ is coprime to
$n$, and so invertible mod $n$).

\begin{sagesilent}
rhs_numerator = (
	positive_radius_condition
	.rhs()
	.subs([q_value_expr,beta_value_expr])
	.factor()
	.numerator()
)
\end{sagesilent}

\noindent
Let $\aa^{'}$ be an integer representative of $\aa^{-1}$ in $\ZZ/n\ZZ$.

Next, we seek to find a larger $\epsilon$ to use in place of $\epsilon_F$ in the
proof of theorem \ref{thm:rmax_with_uniform_eps}:

\begin{lemmadfn}[
	Finding better alternatives to $\epsilon_F$:
	$\epsilon_{q,1}$ and $\epsilon_{q,2}$
]
\label{lemdfn:epsilon_q}
Suppose $d \in \frac{1}{m}\ZZ$ satisfies the condition in
eqn \ref{eqn:positive_rad_condition_in_terms_of_q_beta}.
That is:

\begin{equation*}
	\sage{positive_radius_condition.subs([q_value_expr,beta_value_expr]).factor()}
\end{equation*}

\noindent
Then we have:

\begin{equation*}
	d - \frac{(\aa r + 2\bb)\aa}{2n^2}
	\geq \epsilon_{q,2} \geq \epsilon_{q,1} > 0
\end{equation*}

Where $\epsilon_{q,1}$ and $\epsilon_{q,2}$ are defined as follows:

\begin{equation*}
	\epsilon_{q,1} :=
	\frac{k_q^1}{2mn^2}
	\qquad
	\epsilon_{q,2} :=
	\frac{k_q^2}{2mn^2}
\end{equation*}
\begin{align*}
	\text{where }
	&k_q^1 \text{ is the least }
	k\in\ZZ_{>0}\: s.t.:\:
	k \equiv -\aa\bb m \mod n
\\
	&k_q^2 \text{ is the least }
	k\in\ZZ_{>0}\: s.t.:\:
	k \equiv \aa\bb m (\aa\aa^{'}-2)
	\mod n\gcd(2n,\aa^2 m)
\end{align*}
	
\end{lemmadfn}

It is worth noting that $\epsilon_{q,2}$ is potentially larger than
$\epsilon_{q,2}$
but calculating it involves a $\gcd$, a modulo reduction, and a modulo $n$
inverse, for each $q$ considered.

\begin{proof}

Consider the following tautology:

\begin{align}
	\frac{ x }{ m }
	- \frac{
		(\aa r+2\bb)\aa
	}{
		2n^2
	}
	= \frac{ k }{ 2mn^2 }
	\quad \text{for some } x \in \ZZ
	\span \span \span \span \span
	\label{eqn:finding_better_eps_problem}
\\ &\Longleftrightarrow& 
	- (\aa r+2\bb)\aa m
	&\equiv k &&
	\mod 2n^2
\\ &\Longleftrightarrow&
	- \aa^2 m r - 2\aa\bb m
	&\equiv k &&
	\mod 2n^2
\\ &\Longrightarrow&
  \aa^2 \aa^{'}\bb m - 2\aa\bb m
	&\equiv k &&
	\mod \gcd(2n^2, \aa^2 mn)
	\label{eqn:better_eps_problem_k_mod_gcd2n2_a2mn}
\\ &\Longrightarrow&
  -\aa\bb m
	&\equiv k &&
	\mod n
	\label{eqn:better_eps_problem_k_mod_n}
\end{align}

In our situation, we want to find the least $k$ satisfying 
eqn \ref{eqn:finding_better_eps_problem}.
Since such a $k$ must also satisfy eqn \ref{eqn:better_eps_problem_k_mod_n},
we can pick the smallest $k_q^1 \in \ZZ_{>0}$ which satisfies this new condition
(a computation only depending on $q$ and $\beta$, but not $r$).
We are then guaranteed that the gap $\frac{k}{2mn^2}$ is at least
$\epsilon_{q,1}$.
Furthermore, $k$ also satisfies
eqn \ref{eqn:better_eps_problem_k_mod_gcd2n2_a2mn}
so we can also pick the smallest $k_q^2 \in \ZZ_{>0}$ satisfying this condition,
which also guarantees that the gap $\frac{k}{2mn^2}$ is at least $\epsilon_{q,2}$.

\end{proof}


\begin{theorem}[Bound on $r$ \#3]
\label{thm:rmax_with_eps1}
	Let $v = (R,C,D)$ be a fixed Chern character. Then the ranks of the
	pseudo-semistabilizers for $v$ with
	$\chern_1^\beta = q = \frac{a_q}{n}$
	are bounded above by the following expression (with $i=1$ or 2).

	\begin{equation*}
		\frac{1}{2 \epsilon_{q,i}}
			\min
			\left(
				q^2,
				2R\beta q
				+C^2
				-2DR
				-2Cq
				+q^2
				+\frac{R}{\lcm(m,2n^2)}
				+R \epsilon_{q,i}
			\right)
	\end{equation*}
	Where $\epsilon_{q,i}$ is defined as in definition/lemma \ref{lemdfn:epsilon_q}.
\end{theorem}


\minorheading{Irrational $\beta$}

\egroup % end scope where beta redefined to beta_{-}

\section{Conclusion}

\newpage
\section{Appendix - SageMath code}

\usemintedstyle{tango}

\begin{footnotesize}
\inputminted[
	obeytabs=true,
	tabsize=2,
	breaklines=true,
	breakbefore=./
]{python}{filtered_sage.txt}
\end{footnotesize}

\end{document}
