code
stringlengths
17
6.64M
def sage_latex_macros(): "\n Return list of LaTeX macros for Sage. This just runs the function\n :func:`produce_latex_macro` on the list ``macros`` defined in this\n file, and appends ``sage_configurable_latex_macros``. To add a new\n macro for permanent use in Sage, modify ``macros``.\n\n EXAMPLES...
def sage_mathjax_macros(): "\n Return Sage's macro definitions for usage with MathJax.\n\n This feeds each item output by :func:`sage_latex_macros` to\n :func:`convert_latex_macro_to_mathjax`.\n\n EXAMPLES::\n\n sage: from sage.misc.latex_macros import sage_mathjax_macros\n sage: sage_ma...
class Standalone(SageObject): '\n LaTeX standalone document class.\n\n INPUT:\n\n - ``content`` -- string, the content to be added in the document\n between lines ``r\'\\begin{document}\'`` and ``r\'\\end{document}\'``\n - ``document_class_options`` -- list of strings (default: ``[]``),\n la...
class TikzPicture(Standalone): '\n A TikzPicture embedded in a LaTeX standalone document class.\n\n INPUT:\n\n - ``content`` -- string, tikzpicture code starting with ``r\'\\begin{tikzpicture}\'``\n and ending with ``r\'\\end{tikzpicture}\'``\n - ``standalone_config`` -- list of strings (default:...
class LazyFormat(str): '\n Lazy format strings\n\n .. NOTE::\n\n We recommend to use :func:`sage.misc.lazy_string.lazy_string` instead,\n which is both faster and more flexible.\n\n An instance of :class:`LazyFormat` behaves like a usual format\n string, except that the evaluation of the...
def get_cache_file(): "\n Return the canonical filename for caching names of lazily imported\n modules.\n\n EXAMPLES::\n\n sage: from sage.misc.lazy_import_cache import get_cache_file\n sage: get_cache_file()\n '...-lazy_import_cache.pickle'\n sage: get_cache_file().startswith...
def map_threaded(function, sequence): '\n Apply the function to the elements in the sequence by threading\n recursively through all sub-sequences in the sequence.\n\n EXAMPLES::\n\n sage: # needs sage.symbolic\n sage: map_threaded(log, [[1,2], [3,e]])\n [[0, log(2)], [log(3), 1]]\n ...
def list_function(x): return ('MATHML version of the list %s' % (x,))
def tuple_function(x): return ('MATHML version of the tuple %s' % (x,))
def bool_function(x): return ('MATHML version of %s' % (x,))
def str_function(x): return ('MATHML version of the string %s' % (x,))
class MathML(str): def __repr__(self): return str(self)
def mathml(x): '\n Output x formatted for inclusion in a MathML document.\n ' try: return MathML(x._mathml_()) except (AttributeError, TypeError): for (k, f) in mathml_table.items(): if isinstance(x, k): return MathML(f(x)) if (x is None): ...
def pushover(message, **kwds): '\n Send a push notification with ``message`` to ``user`` using https://pushover.net/.\n\n Pushover is a platform for sending and receiving push notifications. On the server side, it\n provides an HTTP API for queueing messages to deliver to devices. On the device side, iOS...
class MethodDecorator(SageObject): def __init__(self, f): '\n EXAMPLES::\n\n sage: from sage.misc.method_decorator import MethodDecorator\n sage: class Foo:\n ....: @MethodDecorator\n ....: def bar(self, x):\n ....: return x**2...
def sage_makedirs(dirname, mode=511): '\n Python version of ``mkdir -p``: try to create a directory, and also\n create all intermediate directories as necessary. Succeed silently\n if the directory already exists (unlike ``os.makedirs()``).\n Raise other errors (like permission errors) normally.\n\n ...
def try_read(obj, splitlines=False): "\n Determine if a given object is a readable file-like object and if so\n read and return its contents.\n\n That is, the object has a callable method named ``read()`` which takes\n no arguments (except ``self``) then the method is executed and the\n contents ar...
@lazy_string def SAGE_TMP(): '\n EXAMPLES::\n\n sage: from sage.misc.misc import SAGE_TMP\n sage: SAGE_TMP\n doctest:warning...\n DeprecationWarning: SAGE_TMP is deprecated; please use python\'s\n "tempfile" module instead.\n See https://github.com/sagemath/sage/issues...
@lazy_string def ECL_TMP(): '\n Temporary directory that should be used by ECL interfaces launched from\n Sage.\n\n EXAMPLES::\n\n sage: from sage.misc.misc import ECL_TMP\n sage: ECL_TMP\n doctest:warning...\n DeprecationWarning: ECL_TMP is deprecated and is no longer used\n ...
@lazy_string def SPYX_TMP(): '\n EXAMPLES::\n\n sage: from sage.misc.misc import SPYX_TMP\n sage: SPYX_TMP\n doctest:warning...\n DeprecationWarning: SPYX_TMP is deprecated;\n use sage.misc.temporary_file.spyx_tmp instead\n See https://github.com/sagemath/sage/issues/3...
def union(x, y=None): '\n Return the union of x and y, as a list. The resulting list need not\n be sorted and can change from call to call.\n\n INPUT:\n\n\n - ``x`` - iterable\n\n - ``y`` - iterable (may optionally omitted)\n\n\n OUTPUT: list\n\n EXAMPLES::\n\n sage: answer = union([...
def exactly_one_is_true(iterable): '\n Return whether exactly one element of ``iterable`` evaluates ``True``.\n\n INPUT:\n\n - ``iterable`` -- an iterable object\n\n OUTPUT:\n\n A boolean.\n\n .. NOTE::\n\n The implementation is suggested by\n `stackoverflow entry <https://stackove...
def strunc(s, n=60): "\n Truncate at first space after position n, adding '...' if\n nontrivial truncation.\n " n = int(n) s = str(s) if (len(s) > n): i = n while ((i < len(s)) and (s[i] != ' ')): i += 1 return (s[:i] + ' ...') return s
def newton_method_sizes(N): "\n Return a sequence of integers\n `1 = a_1 \\leq a_2 \\leq \\cdots \\leq a_n = N` such that\n `a_j = \\lceil a_{j+1} / 2 \\rceil` for all `j`.\n\n This is useful for Newton-style algorithms that double the\n precision at each stage. For example if you start at precisio...
def compose(f, g): "\n Return the composition of one-variable functions: `f \\circ g`\n\n See also :func:`nest()`\n\n INPUT:\n - `f` -- a function of one variable\n - `g` -- another function of one variable\n\n OUTPUT:\n A function, such that compose(f,g)(x) = f(g(x))\n\n EXAMP...
def nest(f, n, x): "\n Return `f(f(...f(x)...))`, where the composition occurs n times.\n\n See also :func:`compose()` and :func:`self_compose()`\n\n INPUT:\n - `f` -- a function of one variable\n - `n` -- a nonnegative integer\n - `x` -- any input for `f`\n\n OUTPUT:\n `f(...
class BackslashOperator(): '\n Implements Matlab-style backslash operator for solving systems::\n\n A \\ b\n\n The preparser converts this to multiplications using\n ``BackslashOperator()``.\n\n EXAMPLES::\n\n sage: preparse("A \\\\ matrix(QQ,2,1,[1/3,\'2/3\'])")\n "A * Backslash...
def is_iterator(it) -> bool: "\n Tests if it is an iterator.\n\n The mantra ``if hasattr(it, 'next')`` was used to tests if ``it`` is an\n iterator. This is not quite correct since ``it`` could have a ``next``\n methods with a different semantic.\n\n EXAMPLES::\n\n sage: it = iter([1,2,3])\n...
def random_sublist(X, s): '\n Return a pseudo-random sublist of the list X where the probability\n of including a particular element is s.\n\n INPUT:\n\n\n - ``X`` - list\n\n - ``s`` - floating point number between 0 and 1\n\n\n OUTPUT: list\n\n EXAMPLES::\n\n sage: from sage.misc.mi...
def is_sublist(X, Y): '\n Test whether ``X`` is a sublist of ``Y``.\n\n EXAMPLES::\n\n sage: from sage.misc.misc import is_sublist\n sage: S = [1, 7, 3, 4, 18]\n sage: is_sublist([1, 7], S)\n True\n sage: is_sublist([1, 3, 4], S)\n True\n sage: is_sublist([1,...
def some_tuples(elements, repeat, bound, max_samples=None): '\n Return an iterator over at most ``bound`` number of ``repeat``-tuples of\n ``elements``.\n\n INPUT:\n\n - ``elements`` -- an iterable\n - ``repeat`` -- integer (default ``None``), the length of the tuples to be returned.\n If ``No...
def _some_tuples_sampling(elements, repeat, max_samples, n): '\n Internal function for :func:`some_tuples`.\n\n TESTS::\n\n sage: from sage.misc.misc import _some_tuples_sampling\n sage: l = list(_some_tuples_sampling(range(3), 3, 2, 3))\n sage: len(l)\n 2\n sage: all(len(...
def exists(S, P): '\n If S contains an element x such that P(x) is True, this function\n returns True and the element x. Otherwise it returns False and\n None.\n\n Note that this function is NOT suitable to be used in an\n if-statement or in any place where a boolean expression is\n expected. Fo...
def forall(S, P): '\n If P(x) is true every x in S, return True and None. If there is\n some element x in S such that P is not True, return False and x.\n\n Note that this function is NOT suitable to be used in an\n if-statement or in any place where a boolean expression is\n expected. For those si...
def word_wrap(s, ncols=85): t = [] if (ncols == 0): return s for x in s.split('\n'): if ((not x) or (x.lstrip()[:5] == 'sage:')): t.append(x) continue while (len(x) > ncols): k = ncols while ((k > 0) and (x[k] != ' ')): ...
def pad_zeros(s, size=3): "\n EXAMPLES::\n\n sage: pad_zeros(100)\n '100'\n sage: pad_zeros(10)\n '010'\n sage: pad_zeros(10, 5)\n '00010'\n sage: pad_zeros(389, 5)\n '00389'\n sage: pad_zeros(389, 10)\n '0000000389'\n " return (('0' ...
def is_in_string(line, pos): "\n Return ``True`` if the character at position ``pos`` in ``line`` occurs\n within a string.\n\n EXAMPLES::\n\n sage: from sage.misc.misc import is_in_string\n sage: line = 'test(\\'#\\')'\n sage: is_in_string(line, line.rfind('#'))\n True\n ...
def get_main_globals(): '\n Return the main global namespace.\n\n EXAMPLES::\n\n sage: from sage.misc.misc import get_main_globals\n sage: G = get_main_globals()\n sage: bla = 1\n sage: G[\'bla\']\n 1\n sage: bla = 2\n sage: G[\'bla\']\n 2\n sag...
def inject_variable(name, value, warn=True): '\n Inject a variable into the main global namespace.\n\n INPUT:\n\n - ``name`` -- a string\n - ``value`` -- anything\n - ``warn`` -- a boolean (default: :obj:`False`)\n\n EXAMPLES::\n\n sage: from sage.misc.misc import inject_variable\n ...
def inject_variable_test(name, value, depth): '\n A function for testing deep calls to inject_variable\n\n EXAMPLES::\n\n sage: from sage.misc.misc import inject_variable_test\n sage: inject_variable_test("a0", 314, 0)\n sage: a0\n 314\n sage: inject_variable_test("a1", 31...
def run_once(func): '\n Runs a function (successfully) only once.\n\n The running can be reset by setting the ``has_run`` attribute to False\n\n TESTS::\n\n sage: from sage.repl.ipython_extension import run_once\n sage: @run_once\n ....: def foo(work):\n ....: if work:\n ...
@contextlib.contextmanager def increase_recursion_limit(increment): '\n Context manager to temporarily change the Python maximum recursion depth.\n\n INPUT:\n\n - `increment`: increment to add to the current limit\n\n EXAMPLES::\n\n sage: from sage.misc.misc import increase_recursion_limit\n ...
def _len(L): "\n Determines the length of ``L``.\n\n Uses either ``cardinality`` or ``__len__`` as appropriate.\n\n EXAMPLES::\n\n sage: from sage.misc.mrange import _len\n sage: _len(ZZ)\n +Infinity\n sage: _len(range(4))\n 4\n sage: _len(4)\n Traceback (...
def _is_finite(L, fallback=True): '\n Determines whether ``L`` is finite.\n\n If ``L`` implements none of ``is_finite``, ``cardinality`` or\n ``__len__``, we assume by default that it is finite for speed\n reasons. This choice can be overridden by passing in\n ``fallback``.\n\n EXAMPLES::\n\n ...
def _xmrange_iter(iter_list, typ=list): "\n This implements the logic for :func:`mrange_iter` and :class:`xmrange_iter`.\n\n Note that with typ==list, we will be returning a new copy each\n iteration. This makes it OK to modified the returned list. This\n functionality is relied on in the polynomial i...
def mrange_iter(iter_list, typ=list): "\n Return the multirange list derived from the given list of iterators.\n\n This is the list version of :func:`xmrange_iter`. Use :class:`xmrange_iter`\n for the iterator.\n\n More precisely, return the iterator over all objects of type ``typ`` of\n n-tuples o...
class xmrange_iter(): "\n Return the multirange iterate derived from the given iterators and\n type.\n\n .. note::\n\n This basically gives you the Cartesian product of sets.\n\n More precisely, return the iterator over all objects of type typ of\n n-tuples of Python ints with entries between...
def _xmrange(sizes, typ=list): n = len(sizes) if (n == 0): (yield typ([])) return for i in sizes: if (i <= 0): return v = ([0] * n) v[(- 1)] = (- 1) ptr_max = (n - 1) ptr = ptr_max while True: while True: if ((ptr != (- 1)) and ((...
def mrange(sizes, typ=list): '\n Return the multirange list with given sizes and type.\n\n This is the list version of :class:`xmrange`.\n Use :class:`xmrange` for the iterator.\n\n More precisely, return the iterator over all objects of type typ of\n n-tuples of Python ints with entries between 0 ...
class xmrange(): "\n Return the multirange iterate with given sizes and type.\n\n More precisely, return the iterator over all objects of type typ of\n n-tuples of Python ints with entries between 0 and the integers in\n the sizes list. The iterator is empty if sizes is empty or contains\n any non-...
def cartesian_product_iterator(X): "\n Iterate over the Cartesian product.\n\n INPUT:\n\n - ``X`` - list or tuple of lists\n\n OUTPUT: iterator over the Cartesian product of the elements of X\n\n EXAMPLES::\n\n sage: list(cartesian_product_iterator([[1,2], ['a','b']]))\n [(1, 'a'), (...
def cantor_product(*args, **kwds): "\n Return an iterator over the product of the inputs along the diagonals a la\n :wikipedia:`Cantor pairing <Pairing_function#Cantor_pairing_function>`.\n\n INPUT:\n\n - a certain number of iterables\n\n - ``repeat`` -- an optional integer. If it is provided, the ...
def multiple_replace(dic, text): '\n Replace in \'text\' all occurrences of any key in the given\n dictionary by its corresponding value. Returns the new string.\n\n EXAMPLES::\n\n sage: from sage.misc.multireplace import multiple_replace\n sage: txt = "This monkey really likes the bananas...
def install_doc(package, doc): "\n Install the docstring ``doc`` to the package.\n\n TESTS:\n\n sage: from sage.misc.namespace_package import install_doc\n sage: install_doc('sage', 'hello')\n sage: from inspect import getdoc\n sage: getdoc(sage)\n 'hello'\n " pkg =...
def install_dict(package, dic): "\n Install ``dic`` to the ``__dict__`` of the package.\n\n TESTS:\n\n sage: from sage.misc.namespace_package import install_dict\n sage: install_dict('sage', {'greeting': 'hello'})\n sage: sage.greeting\n 'hello'\n " pkg = import_module(pac...
class MultiplexFunction(): '\n A simple wrapper object for functions that are called on a list of\n objects.\n ' def __init__(self, multiplexer, name): "\n EXAMPLES::\n\n sage: from sage.misc.object_multiplexer import Multiplex, MultiplexFunction\n sage: m = Mult...
class Multiplex(): '\n Object for a list of children such that function calls on this\n new object implies that the same function is called on all\n children.\n ' def __init__(self, *args): "\n EXAMPLES::\n\n sage: from sage.misc.object_multiplexer import Multiplex\n ...
def pkgname_split(name): "\n Split a pkgname into a list of strings, 'name, version'.\n\n For some packages, the version string might be empty.\n\n EXAMPLES::\n\n sage: from sage.misc.package import pkgname_split\n sage: pkgname_split('hello_world-1.2')\n ['hello_world', '1.2']\n ...
def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False): "\n Return the version of this pip package available on PyPI.\n\n INPUT:\n\n - ``pkg`` -- the package\n\n - ``pypi_url`` -- (string, default: standard PyPI url) an optional Python\n package repository to use\n\n - ``ign...
def spkg_type(name): "\n Return the type of the Sage package with the given name.\n\n INPUT:\n\n - ``name`` -- string giving the subdirectory name of the package under\n ``SAGE_PKGS``\n\n EXAMPLES::\n\n sage: from sage.misc.package import spkg_type\n sage: spkg_type('pip') ...
def pip_installed_packages(normalization=None): "\n Return a dictionary `name->version` of installed pip packages.\n\n This command returns *all* pip-installed packages. Not only Sage packages.\n\n INPUT:\n\n - ``normalization`` -- (optional, default: ``None``) according to which rule to\n normal...
class PackageInfo(NamedTuple): 'Represents information about a package.' name: str type: Optional[str] = None source: Optional[str] = None installed_version: Optional[str] = None remote_version: Optional[str] = None def is_installed(self) -> bool: '\n Whether the package is...
def list_packages(*pkg_types: str, pkg_sources: List[str]=['normal', 'pip', 'script'], local: bool=False, ignore_URLError: bool=False, exclude_pip: bool=False) -> Dict[(str, PackageInfo)]: "\n Return a dictionary of information about each package.\n\n The keys are package names and values are named tuples w...
def _spkg_inst_dirs(): '\n Generator for the installation manifest directories as resolved paths.\n\n It yields first ``SAGE_LOCAL_SPKG_INST``, then ``SAGE_VENV_SPKG_INST``,\n if defined; but it both resolve to the same directory, it only yields\n one element.\n\n EXAMPLES::\n\n sage: from s...
def installed_packages(exclude_pip=True): '\n Return a dictionary of all installed packages, with version numbers.\n\n INPUT:\n\n - ``exclude_pip`` -- (optional, default: ``True``) whether "pip" packages\n are excluded from the list\n\n EXAMPLES:\n\n Below we test for a standard package withou...
def is_package_installed(package, exclude_pip=True): '\n Return whether (any version of) ``package`` is installed.\n\n INPUT:\n\n - ``package`` -- the name of the package\n\n - ``exclude_pip`` -- (optional, default: ``True``) whether to consider pip\n type packages\n\n\n EXAMPLES::\n\n ...
def is_package_installed_and_updated(package: str) -> bool: '\n Return whether the given package is installed and up-to-date.\n\n INPUT:\n\n - ``package`` -- the name of the package.\n\n EXAMPLES::\n\n sage: from sage.misc.package import is_package_installed_and_updated\n sage: is_packag...
def package_versions(package_type, local=False): '\n Return version information for each Sage package.\n\n INPUT:\n\n - ``package_type`` -- (string) one of ``"standard"``, ``"optional"`` or\n ``"experimental"``\n\n - ``local`` -- (boolean, default: ``False``) only query local data (no internet ne...
def standard_packages(): "\n Return two lists. The first contains the installed and the second\n contains the not-installed standard packages that are available\n from the Sage repository.\n\n OUTPUT:\n\n - installed standard packages (as a list)\n\n - NOT installed standard packages (as a list)...
def optional_packages(): "\n Return two lists. The first contains the installed and the second\n contains the not-installed optional packages that are available\n from the Sage repository.\n\n OUTPUT:\n\n - installed optional packages (as a list)\n\n - NOT installed optional packages (as a list)...
def experimental_packages(): '\n Return two lists. The first contains the installed and the second\n contains the not-installed experimental packages that are available\n from the Sage repository.\n\n OUTPUT:\n\n - installed experimental packages (as a list)\n\n - NOT installed experimental pack...
def package_manifest(package): "\n Return the manifest for ``package``.\n\n INPUT:\n\n - ``package`` -- package name\n\n The manifest is written in the file\n ``SAGE_SPKG_INST/package-VERSION``. It is a JSON file containing a\n dictionary with the package name, version, installation date, list\n...
class PackageNotFoundError(RuntimeError): '\n This class defines the exception that should be raised when a\n function, method, or class cannot detect a Sage package that it\n depends on.\n\n This exception should be raised with a single argument, namely\n the name of the package.\n\n When a ``P...
class SourceDistributionFilter(): "\n A :class:`collections.abc.Container` for source files in distributions.\n\n INPUT:\n\n - ``include_distributions`` -- (default: ``None``) if not ``None``,\n should be a sequence or set of strings: include files whose\n ``distribution`` (from a ``# sage_setu...
def read_distribution(src_file): "\n Parse ``src_file`` for a ``# sage_setup:`` ``distribution = PKG`` directive.\n\n INPUT:\n\n - ``src_file`` -- file name of a Python or Cython source file\n\n OUTPUT:\n\n - a string, the name of the distribution package (``PKG``); or the empty\n string if no...
def update_distribution(src_file, distribution, *, verbose=False): '\n Add or update a ``# sage_setup:`` ``distribution = PKG`` directive in ``src_file``.\n\n For a Python or Cython file, if a ``distribution`` directive\n is not already present, it is added.\n\n For any other file, if a ``distribution...
def is_package_or_sage_namespace_package_dir(path, *, distribution_filter=None): "\n Return whether ``path`` is a directory that contains a Python package.\n\n Ordinary Python packages are recognized by the presence of ``__init__.py``.\n\n Implicit namespace packages (PEP 420) are only recognized if they...
@contextmanager def cython_namespace_package_support(): '\n Activate namespace package support in Cython 0.x\n\n See https://github.com/cython/cython/issues/2918#issuecomment-991799049\n ' import Cython.Build.Dependencies import Cython.Build.Cythonize import Cython.Utils orig_is_package_d...
def walk_packages(path=None, prefix='', onerror=None): "\n Yield :class:`pkgutil.ModuleInfo` for all modules recursively on ``path``.\n\n This version of the standard library function :func:`pkgutil.walk_packages`\n addresses https://github.com/python/cpython/issues/73444 by handling\n the implicit na...
def _all_filename(distribution): if (not distribution): return 'all.py' return f"all__{distribution.replace('-', '_')}.py"
def _distribution_from_all_filename(filename): if (m := re.match('all(__(.*?))?[.]py', filename)): if (distribution_per_all_filename := m.group(2)): return distribution_per_all_filename.replace('_', '-') return '' return False
def pager(): import IPython.core.page return IPython.core.page.page
def _pyrand(): '\n A tiny private helper function to return an instance of\n random.Random from the current \\sage random number state.\n Only for use in prandom.py; other modules should use\n current_randstate().python_random().\n\n EXAMPLES::\n\n sage: set_random_seed(0)\n sage: fro...
def getrandbits(k): '\n getrandbits(k) -> x. Generates a long int with k random bits.\n\n EXAMPLES::\n\n sage: getrandbits(10) in range(2^10)\n True\n sage: getrandbits(200) in range(2^200)\n True\n sage: getrandbits(4) in range(2^4)\n True\n ' return _pyran...
def randrange(start, stop=None, step=1): '\n Choose a random item from range(start, stop[, step]).\n\n This fixes the problem with randint() which includes the\n endpoint; in Python this is usually not what you want.\n\n EXAMPLES::\n\n sage: s = randrange(0, 100, 11)\n sage: 0 <= s < 100...
def randint(a, b): '\n Return random integer in range [a, b], including both end points.\n\n EXAMPLES::\n\n sage: s = [randint(0, 2) for i in range(15)]; s # random\n [0, 1, 0, 0, 1, 0, 2, 0, 2, 1, 2, 2, 0, 2, 2]\n sage: all(t in [0, 1, 2] for t in s)\n True\n sage: -100 ...
def choice(seq): '\n Choose a random element from a non-empty sequence.\n\n EXAMPLES::\n\n sage: s = [choice(list(primes(10, 100))) for i in range(5)]; s # random # needs sage.libs.pari\n [17, 47, 11, 31, 47]\n sage: all(t in primes(10, 100) for t in s) ...
def shuffle(x): '\n x, random=random.random -> shuffle list x in place; return None.\n\n Optional arg random is a 0-argument function returning a random\n float in [0.0, 1.0); by default, the sage.misc.random.random.\n\n EXAMPLES::\n\n sage: shuffle([1 .. 10])\n ' return _pyrand().shuffl...
def sample(population, k): '\n Choose k unique random elements from a population sequence.\n\n Return a new list containing elements from the population while\n leaving the original population unchanged. The resulting list is\n in selection order so that all sub-slices will also be valid random\n ...
def random(): '\n Get the next random number in the range [0.0, 1.0).\n\n EXAMPLES::\n\n sage: sample = [random() for i in [1 .. 4]]; sample # random\n [0.111439293741037, 0.5143475134191677, 0.04468968524815642, 0.332490606442413]\n sage: all(0.0 <= s <= 1.0 for s in sample)\n ...
def uniform(a, b): '\n Get a random number in the range [a, b).\n\n Equivalent to \\code{a + (b-a) * random()}.\n\n EXAMPLES::\n\n sage: s = uniform(0, 1); s # random\n 0.111439293741037\n sage: 0.0 <= s <= 1.0\n True\n\n sage: s = uniform(e, pi); s # random ...
def betavariate(alpha, beta): '\n Beta distribution.\n\n Conditions on the parameters are alpha > 0 and beta > 0.\n Returned values range between 0 and 1.\n\n EXAMPLES::\n\n sage: s = betavariate(0.1, 0.9); s # random\n 9.75087916621299e-9\n sage: 0.0 <= s <= 1.0\n True\n\...
def expovariate(lambd): '\n Exponential distribution.\n\n lambd is 1.0 divided by the desired mean. (The parameter would be\n called "lambda", but that is a reserved word in Python.) Returned\n values range from 0 to positive infinity.\n\n EXAMPLES::\n\n sage: sample = [expovariate(0.001) ...
def gammavariate(alpha, beta): '\n Gamma distribution. Not the gamma function!\n\n Conditions on the parameters are alpha > 0 and beta > 0.\n\n EXAMPLES::\n\n sage: sample = gammavariate(1.0, 3.0); sample # random\n 6.58282586130638\n sage: sample > 0\n True\n sage: s...
def gauss(mu, sigma): '\n Gaussian distribution.\n\n mu is the mean, and sigma is the standard deviation. This is\n slightly faster than the normalvariate() function, but is not\n thread-safe.\n\n EXAMPLES::\n\n sage: [gauss(0, 1) for i in range(3)] # random\n [0.9191011757657915, 0.7...
def lognormvariate(mu, sigma): "\n Log normal distribution.\n\n If you take the natural logarithm of this distribution, you'll get a\n normal distribution with mean mu and standard deviation sigma.\n mu can have any value, and sigma must be greater than zero.\n\n EXAMPLES::\n\n sage: [lognor...
def normalvariate(mu, sigma): '\n Normal distribution.\n\n mu is the mean, and sigma is the standard deviation.\n\n EXAMPLES::\n\n sage: [normalvariate(0, 1) for i in range(3)] # random\n [-1.372558980559407, -1.1701670364898928, 0.04324100555110143]\n sage: [normalvariate(0, 100) for ...
def vonmisesvariate(mu, kappa): '\n Circular data distribution.\n\n mu is the mean angle, expressed in radians between 0 and 2*pi, and\n kappa is the concentration parameter, which must be greater than or\n equal to zero. If kappa is equal to zero, this distribution reduces\n to a uniform random a...
def paretovariate(alpha): '\n Pareto distribution. alpha is the shape parameter.\n\n EXAMPLES::\n\n sage: sample = [paretovariate(3) for i in range(1, 5)]; sample # random\n [1.0401699394233033, 1.2722080162636495, 1.0153564009379579, 1.1442323078983077]\n sage: all(s >= 1.0 for s in ...
def weibullvariate(alpha, beta): '\n Weibull distribution.\n\n alpha is the scale parameter and beta is the shape parameter.\n\n EXAMPLES::\n\n sage: sample = [weibullvariate(1, 3) for i in range(1, 5)]; sample # random\n [0.49069775546342537, 0.8972185564611213, 0.357573846531942, 0.73937...