{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Describe\nThis example focuses on the usage of the :func:`pylops.utils.describe.describe`\nmethod, which allows expressing any PyLops operator into its equivalent\nmathematical representation. This is done with the aid of\n[sympy](https://docs.sympy.org), a Python library for symbolic computing\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport pylops\nfrom pylops.utils.describe import describe\n\nplt.close(\"all\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let's start by defining 3 PyLops operators. Note that once an operator is\ndefined we can attach a name to the operator; by doing so, this name will\nbe used in the mathematical description of the operator. Alternatively,\nthe describe method will randomly choose a name for us.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "A = pylops.MatrixMult(np.ones((10, 5)))\nA.name = \"A\"\nB = pylops.Diagonal(np.ones(5))\nB.name = \"A\"\nC = pylops.MatrixMult(np.ones((10, 5)))\n\n# Simple operator\ndescribe(A)\n\n# Transpose\nAT = A.T\ndescribe(AT)\n\n# Adjoint\nAH = A.H\ndescribe(AH)\n\n# Scaled\nA3 = 3 * A\ndescribe(A3)\n\n# Sum\nD = A + C\ndescribe(D)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "So far so good. Let's see what happens if we accidentally call two different\noperators with the same name. You will see that PyLops catches that and\nchanges the name for us (and provides us with a nice warning!)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "D = A * B\ndescribe(D)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We can move now to something more complicated using various composition\noperators\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "H = pylops.HStack((A * B, C * B))\ndescribe(H)\n\nH = pylops.Block([[A * B, C], [A, A]])\ndescribe(H)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Finally, note that you can get the best out of the describe method if working\ninside a Jupyter notebook. There, the mathematical expression will be\nrendered using a LeTex format! See an example [notebook](https://github.com/mrava87/pylops_notebooks/blob/master/developement/Sympy.ipynb).\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}