{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Random Constructions\n",
    "\n",
    "## Random points on the unit sphere\n",
    "\n",
    "The easiest way to randomly construct a polytope is by sampling points on the unit sphere.  The following chooses 100 points on the unit sphere in 3-space.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details><summary><pre style=\"display:inline\"><small>Click here for additional output</small></pre></summary>\n",
       "<pre>\n",
       "polymake: used package cdd\n",
       "  cddlib\n",
       "  Implementation of the double description method of Motzkin et al.\n",
       "  Copyright by Komei Fukuda.\n",
       "  http://www-oldurls.inf.ethz.ch/personal/fukudak/cdd_home/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "$p1=rand_sphere(3,100);\n",
    "print $p1->SIMPLICIAL;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Random points sampled from a normal distribution\n",
    "A second way to randomly construct a polytope is by sampling points by a standard normal distribution. The following chooses 100 points sampled from the standard normal distribution in 3-space.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true\n",
       "24 66 44"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$p2 = rand_normal(3, 100);\n",
    "print $p2 -> SIMPLICIAL, \"\\n\", $p2 -> F_VECTOR;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With probability one such polytopes under either distribution are simplicial.\n",
    "\n",
    "## Random polytopes with are neither simplicial nor simple\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false false\n",
       "30 162 251 119"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "($d,$m,$n) = (4,50,30);\n",
    "$p1=rand_sphere($d,$m);\n",
    "$p2=polarize($p1);\n",
    "$p3=new Polytope(POINTS=>rand_vert($p2->VERTICES,$n));\n",
    "print $p3->SIMPLICIAL, \" \", $p3->SIMPLE, \"\\n\", $p3->F_VECTOR;"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "polymake",
   "language": "polymake",
   "name": "polymake"
  },
  "language_info": {
   "codemirror_mode": "perl",
   "file_extension": ".pl",
   "mimetype": "text/x-polymake",
   "name": "polymake"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
