> For the complete documentation index, see [llms.txt](https://heplib.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heplib.gitbook.io/doc/installation.md).

# Installation

One can install **HepLib** *automatically* or *manually*, the *recommended* one is to use the *install.sh* script or the *makefile*.

## Install Automatically

One can install **HepLib** *automatically* with the *all-in-one* script *install.sh* or the *all-in-one* *makefile*.

{% tabs %}
{% tab title="install.sh" %}

```bash
wget https://heplib.github.io/install.sh
chmod +x install.sh
INSTALL_PATH=<INSTALL PATH> jn=<jn> ./install.sh
```

{% endtab %}

{% tab title="makefile" %}

```bash
wget https://heplib.github.io/makefile
make INSTALL_PATH=<INSTALL PATH> jn=<jn>
```

{% endtab %}
{% endtabs %}

* `<INSTALL PATH>` the directory to which all *external libraries/programs* will be installed.
* `<jn>` the number of jobs in invoking `make -j $jn`.

## Install Manually

One can also install **HepLib** *manually* which is *NOT* recommended, including to install the required *external libraries*, *external programs* and **HepLib** iteself following the steps below.

{% hint style="info" %}
Assuming one has exported the *environment variable* `INSTALL_PATH`.

```bash
export INSTALL_PATH="<INSTALL PATH>"
```

{% endhint %}

### 1. Install External Libraries

* [GMP](https://gmplib.org/) : it is required for **MPFR** and **GiNaC**.

```bash
curl -L -O https://gmplib.org/download/gmp/gmp-6.2.0.tar.gz
tar zxf gmp-6.2.0.tar.gz
cd gmp-6.2.0
./configure --prefix=$INSTALL_PATH
make -j 16
make install
```

* [MPFR](https://www.mpfr.org/) : it is used to handle the *multiple precision* in the numerical integration. **MPFR** needs to be compiled with the option `--enable-float128`.

{% hint style="warning" %}
The quadruple precision type `__float128` has been changed to `_Float128` since **MPFR** *4.1.0*, so we prefer the version **MPFR** *4.0.2* for the moment, furthermore the **MPFR C++** wrapper is included in **HepLib** archive.
{% endhint %}

```bash
curl -L -O https://heplib.github.io/mpfr-4.0.2.tar.gz
tar zxf mpfr-4.0.2.tar.gz
cd mpfr-4.0.2
./configure --prefix=$INSTALL_PATH --with-gmp=$INSTALL_PATH --enable-float128 --enable-thread-safe
make -j 16
make install
```

* [CLN](https://www.ginac.de/CLN/) : it is required for **GiNaC**.

```bash
curl -L -O https://www.ginac.de/CLN/cln-1.3.6.tar.bz2
tar jxf cln-1.3.6.tar.bz2
cd cln-1.3.6
./configure --prefix=$INSTALL_PATH --with-gmp=$INSTALL_PATH
make -j 16
make install
```

* [GiNaC](https://www.ginac.de/) : The underlying language of **HepLib**, which is used for symbolic operations.

```bash
curl -L -O https://www.ginac.de/ginac-1.8.0.tar.bz2
cd ginac-1.8.0
./configure --prefix=$INSTALL_PATH PKG_CONFIG_PATH=$INSTALL_PATH/lib/pkgconfig
make -j 16
make install
```

* [QHull](http://www.qhull.org/) : it is used for *Sector Decompostion* with the geometric strategy.

```bash
curl -L -O http://www.qhull.org/download/qhull-2020.2.zip
unzip -q qhull-2020.2.zip
cd qhull-2020.2
cp Makefile Makefile.bak
cat Makefile.bak | sed "s/\/usr\/local/\$\$INSTALL_PATH/g" > Makefile
make
make install
```

* [MinUit2](http://seal.web.cern.ch/seal/snapshot/work-packages/mathlibs/minuit/) : it is used to find the minimum of a function.

```bash
curl -L -O http://project-mathlibs.web.cern.ch/project-mathlibs/sw/5_34_14/Minuit2/Minuit2-5.34.14.tar.gz
cd Minuit2-5.34.14
./configure --prefix=$INSTALL_PATH
make -j 16
make install
```

* [CUBA](http://www.feynarts.de/cuba/) : it is one of the numerical integrators.

{% hint style="info" %}
The version with *quadruple precision* **libcubaq** is actually used, by adding the option `--with--real=16 --fPIC` to the `configure` script. One may also need the option `-fcommon` while using *gcc* 10.
{% endhint %}

```bash
curl -L -O http://www.feynarts.de/cuba/Cuba-4.2.tar.gz
tar zxf Cuba-4.2.tar.gz
cd Cuba-4.2
./configure --prefix=$INSTALL_PATH --with-real=16 CFLAGS="-fPIC -fcommon" CXXFLAGS="-fPIC -fcommon"
make
make install
```

### 2. Install External Programs

* [Fermat](https://www.mpfr.org/) : it is used for matrix operation, multivariate rational polynormial simplification, *etc.*.

{% tabs %}
{% tab title="Linux OS" %}

```bash
curl -L -O http://home.bway.net/lewis/fermat64/ferl6.tar.gz
tar zxf ferl6.tar.gz
mv ferl6 $INSTALL_PATH
cd $INSTALL_PATH/bin
ln -s -f ../ferl6/fer64 .
```

{% endtab %}

{% tab title="Mac OS" %}

```bash
curl -L -O http://home.bway.net/lewis/fermat64/ferlm.tar.gz
tar zxf ferm6.tar.gz
mv ferm6 $INSTALL_PATH
cd $INSTALL_PATH/bin
ln -s -f ../ferm6/fer64 .
```

{% endtab %}
{% endtabs %}

* [Form](https://www.nikhef.nl/~form/) : it is used for *Dirac* and *Color* matrix trace, *Lorentz* index contraction, *etc.*.

{% tabs %}
{% tab title="Linux OS" %}

```bash
curl -L -O https://github.com/vermaseren/form/releases/download/v4.2.1/form-4.2.1-x86_64-linux.tar.gz
tar zxf form-4.2.1-x86_64-linux.tar.gz
cp -rf form-4.2.1-x86_64-linux/form $INSTALL_PATH/bin/
cp -rf form-4.2.1-x86_64-linux/tform $INSTALL_PATH/bin/
```

{% endtab %}

{% tab title="Mac OS" %}

```bash
curl -L -O https://github.com/vermaseren/form/releases/download/v4.2.1/form-4.2.1-x86_64-osx.tar.gz
tar zxf form-4.2.1-x86_64-osx.tar.gz
cp -rf form-4.2.1-x86_64-osx/form $INSTALL_PATH/bin/
cp -rf form-4.2.1-x86_64-osx/tform $INSTALL_PATH/bin/
```

{% endtab %}
{% endtabs %}

* [FIRE](https://bitbucket.org/feynmanIntegrals/fire/) : it is required for *IBP* reduction in `HepLib::IBP::FIRE` class.

```bash
git clone https://bitbucket.org/feynmanIntegrals/fire.git
mv fire/FIRE6 $INSTALL_PATH/FIRE6
rm -rf fire
cd $INSTALL_PATH/FIRE6
./configure --enable_zlib --enable_snappy --enable_lthreads --enable_tcmalloc --enable_zstd
make -j 16
make
```

* [KIRA](https://kira.hepforge.org/) : it is required for *IBP* reduction in `HepLib::IBP::KIRA` class.

{% tabs %}
{% tab title="Linux OS" %}

```bash
curl -L -o kira https://kira.hepforge.org/downloads?f=binaries/kira-2.0
chmod +x kira
mv -f kira $INSTALL_PATH/bin/kira
```

{% endtab %}

{% tab title="Mac OS" %}
For installation on *Mac OS*, please refer to [official page](https://kira.hepforge.org) of **KIRA**.
{% endtab %}
{% endtabs %}

### 3. Install HepLib

One can download the most recent version of **HepLib** as a compressed archive: *HepLib.tar.gz*, uncompress it and change current directory into `HepLib/src` by the commands:

```bash
wget https://heplib.github.io/HepLib.tar.gz
tar zxfv HepLib.tar.gz
cd HepLib/src
```

Create a directory for cmake to build the library as follows:

```bash
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH ..
make -j 4 && make install
```

{% hint style="info" %}
If **GiNaC** or other dependent *external library* is not installed to `CMAKE_INSTALL_PREFIX`, the user needs to specify the locations by supplying the variables `INC_PATH` and `LIB_PATH` in the cmake arguments as:

```bash
cmake -DCMAKE_INSTALL_PREFIX=path -DINC_PATH="inc1;inc2" -DLIB_PATH="lib1;lib2" ..
```

{% endhint %}
