\documentclass[11pt]{book}
\usepackage[scale=.7]{geometry}
\usepackage{charter}
\usepackage[backend=biber, sorting=none]{biblatex}
\usepackage{textfit}
\usepackage{relsize}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{ytableau}
\usepackage{listings}
\usepackage[fleqn]{amsmath}
\usepackage{color}
\usepackage{changepage}
\usepackage[colorlinks=true, linkcolor=red, citecolor=red, urlcolor=black, plainpages=false, pdfpagelabels]{hyperref}
\usepackage{etoolbox}
\usepackage{amssymb}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{wallpaper}
\def\specialcolon{\mathrel{\mathop{:}}\hspace{-.5em}}
\renewcommand{\bar}[1]{\overline{#1}}
%\newcommand{\algorithm}[2]{{\tt\Large\detokenize{#1}}\\[1ex]
%  {\emph{#2}}\\[1ex]
%}
\usepackage{cprotect}
\newcommand{\algorithm}[2]{\subsection{\texttt{#1}}
{\emph{#2}}\\
}
\newcommand{\property}[2]{{\tt\Large\detokenize{#1}}\\[1ex]
{\emph{#2}}\\[1ex]
}
\newcommand{\algo}[1]{{\tt \detokenize{#1}}}
\newcommand{\prop}[1]{{\tt \detokenize{#1}}}
\renewcommand{\author}[1]{{\bfseries #1}}
\newcommand{\email}[1]{, {\tt #1}}

% Math expressions wrapped in \brwrap will get typeset with
% round brackets around them, which have the appropriate size.
% The expression itself can still be broken over multiple lines.

\newcommand\brwrap[3]{%
  \setbox0=\hbox{$#2$}
  \left#1\vbox to \the\ht0{\hbox to 0pt{}}\right.\kern-.2em
  \begingroup #2\endgroup\kern-.15em
  \left.\vbox to \the\ht0{\hbox to 0pt{}}\right#3
}

\renewcommand{\arraystretch}{1.2}
\tolerance=10000
\relpenalty=10
\binoppenalty=10
\hyphenpenalty=10
%\raggedright

%\usepackage[most]{tcolorbox}

\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstnewenvironment{python}[1][]{\lstset{language=python,
   columns=fullflexible,
   xleftmargin=1em,
   belowskip=0pt,
%   aboveskip=5pt,
   tabsize=3,
   backgroundcolor=\color{backcolour},   
   commentstyle={}, % otherwise {#} cadabra arguments look ugly
   breaklines=true,   
   basicstyle=\small\ttfamily\color{blue},
   keywordstyle={}
}}{}
  

\everymath{\displaystyle}

% Page numbers
\pagestyle{fancy}
\fancyhf{} % clear all header and footer fields
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[LE,RO]{{\small\thepage}}
\fancyfoot[LO,RE]{}

% \makeatletter\def\old@comma{,}\catcode`\,=13 \def,{%
% \ifmmode\old@comma\discretionary{}{}{}\else\old@comma\fi}\makeatother

% Ensure that maths broken over multiple lines has a bit of spacing
% between lines.
\lineskiplimit=0mm
\lineskip=1.5ex

\ytableausetup{centertableaux} % smalltableaux

% Chapter and section headers.
\usepackage[compact]{titlesec}

\newcommand{\chapterformat}[1]{\LARGE\larger\bfseries \hspace{3mm}#1}

\titleformat{\chapter}[block]
  {\large\bfseries}{}{0pt}{\hfill{\color[rgb]{.5,.5,.5}{%
  \bfseries\scaletoheight{2cm}{\thechapter}}}%
\\\hbox{~}\hfill\chapterformat}



\bibliography{the_cadabra_book}


\begin{document}
\pagestyle{empty}
\ThisLRCornerWallPaper{1.0}{book_cover}
\begin{flushright}
\today
\end{flushright}
\vspace{6ex}
{\bf \scaletowidth{15cm}{The Cadabra Book}}~\\[.8ex] 
{\it\large A field-theory motivated approach to symbolic computer algebra}\\[6ex]
{\bf \scaletowidth{5cm}{Kasper Peeters}}
\newpage
\pagestyle{empty}
\hbox{~}
\noindent {\smaller This book is available under the terms of the GNU Free
Documentation License, version~1.2.\\
The Cadabra software is available under the terms of the GNU
General Public License, version~3.}
\vfill
\noindent {\large\bf Copyright \copyright~2001-2020 ~Kasper Peeters}\\[3ex]
\href{mailto:kasper.peeters@cadabra.science}{kasper.peeters@cadabra.science}

\tableofcontents

\pagestyle{fancy} 

\chapter{Introduction and overview}
\section{Bird's eye overview}

Cadabra is a symbolic computer algebra system (CAS) designed to solve
problems in physics, in particular (but not limited to) those which
deal with classical and quantum field theory. Its input format is a
subset of TeX, which means that throughout your computations the maths
will all stay in a form which is hopefully already familiar to you.
It has a large number of facilities which make it easy to work with
tensors, anti-commuting objects, implicit indices, implicit coordinate
dependence and so on; things which help to keep mathematical
expressions compact and readable, so that your notebooks resemble what
you would do with pen-and-paper.

% Concrete types of problems you can solve include:
% \begin{itemize}
%   \item 
% \end{itemize}

Cadabra is at its core a Python module (written in C++ and exposed to
Python using pybind11), which also contains a pre-parser which turns
Cadabra's language into pure Python. You can use through a command
line client, a graphical notebook interface, or via Jupyter through
the Cadabra kernel. You can, if you want to, also use it from Python
directly, or as a C++ library.


\section{Cadabra's design philosophy}

Cadabra is built around the fact that many computations do not have
one single and unique path between the starting point and the end
result. When we do computations on paper, we often take bits of an
expression apart, do some manipulations on them, stick them back into
the main expression, and so on. Often, the manipulations that we do
are far from uniquely determined by the problem, and often there is no
way even in principle for a computer to figure out what is 'the best'
thing to do.

What we need the computer to do, in such a case, is to be good at
performing simple but tedious steps, without enforcing on the user how
to do a particular computation. In other words, we want the computer
algebra system to be a scratchpad, leaving us in control of which
steps to take, not forcing us to return to a 'canonical' expression at
every stage.

Most existing computer algebra systems allow for this kind of work
flow only by requiring to stick clumsy 'inert' or 'hold' arguments
onto expressions, by default always 'simplifying' every input to some
form they think is best. Cadabra starts from the other end of the
spectrum, and as a general rule keeps your expression untouched,
unless you explicitly ask for something to be done to it.

Another key issue in the design of symbolic computer algebra systems
has always been whether or not there should be a distinction between
the 'data language' (the language used to write down mathematical
expressions), the 'manipulation language' (the language used to write
down what you want to do with those expressions) and the
'implementation language' (the language used to implement algorithms
which act on mathematical expressions). Many computer algebra systems
take the approach in which these languages are the same (Axiom,
Reduce, Sympy) or mostly the same apart from a small core which uses a
different implementation language (Mathematica, Maple). The Cadabra
project is rooted in the idea that for many applications, it is better
to keep a clean distinction between these three languages. Cadabra
writes mathematics using LaTeX, is programmable in Python, and is
under the hood largely written in C++.

\section{History}

Cadabra was originally written around 2001 to solve a number of
problems related to higher-derivative
supergravity~\cite{Peeters:2000qj,Peeters:2003pv}. It was then
expanded and polished, and first saw its public release in
2007~\cite{kas_cdb_hep}.  During the years that followed, it became
clear that several design decisions were not ideal, such as the use of
a custom programming language and the lack of functionality for
component computations. Over the course of 2015-2016 a large rewrite
took place, which resulted in Cadabra 2.x~\cite{Peeters:2018dyg}.
This new version is programmable in Python and does both abstract and
component computations.


%==================================================================
\chapter{The input format}
\input{input_format.tex}
\input{ref_printing.tex}
\input{ref_properties.tex}
\input{ref_indices.tex}
\input{ref_implicit_versus_explicit.tex}

%==================================================================
\chapter{Mathematical properties}
\input{ref_derivatives.tex}

%==================================================================
\chapter{Manipulating expressions}
\input{ref_selecting.tex}
\input{ref_import.tex}
\input{ref_default_simplification}
\input{ref_patterns}

%==================================================================
\chapter{Writing your own packages}
\input{ref_programming}

%==================================================================
\chapter{Algorithms}

\section{Substitution and variation}

\input{distribute}
\input{product_rule}
\input{substitute}
\input{vary}
\input{expand_power}
\input{unwrap}
\input{integrate_by_parts}

\section{Metrics and bundles}

\input{eliminate_kronecker}
\input{eliminate_metric}
\input{eliminate_vielbein  }
\input{einsteinify}
\input{epsilon_to_delta}
\input{expand_delta}
\input{reduce_delta}

\section{Index manipulations}

\input{combine}
\input{explicit_indices}
\input{lower_free_indices}
\input{raise_free_indices}
\input{split_index}
\input{untrace}
\input{rename_dummies}
\input{rewrite_indices}
\input{expand}

\section{Tensor component values}

\input{complete}
\input{evaluate}

\section{Factorisation}

\input{factor_in}
\input{factor_out}

\section{Spinors and fermions}

\input{expand_diracbar}
\input{fierz}
\input{join_gamma}
\input{sort_spinors}
\input{split_gamma}

\section{Sorting and canonicalisation}
  
\input{asym}
\input{canonicalise}
\input{young_project_product}
\input{young_project_tensor}
\input{meld}
\input{sort_product}
\input{sort_sum}

\section{Weights and perturbations}

\input{drop_weight}
\input{keep_weight}

\section{Simplification}

\input{collect_factors}
\input{collect_terms}
\input{map_sympy}
\input{simplify}

\section{Representations}

\input{decompose}
\input{decompose_product}
\input{lr_tensor}

\section{Sub-expression manipulation}

\input{replace_match}
\input{take_match}
\input{zoom}

\printbibliography

\end{document}
