code
stringlengths
17
6.64M
def sympy_set_to_list(set, vars): "\n Convert all set objects that can be returned by SymPy's solvers.\n " from sage.rings.infinity import UnsignedInfinity from sympy import FiniteSet, And, Or, Union, Interval, oo, S from sympy.core.relational import Relational if (set == S.Reals): r...
@sympify_method_args class SageSet(Set): '\n Wrapper for a Sage set providing the SymPy Set API.\n\n Parents in the category :class:`sage.categories.sets_cat.Sets`, unless\n a more specific method is implemented, convert to SymPy by creating\n an instance of this class.\n\n EXAMPLES::\n\n sa...
class ExtraTabCompletion(): def __dir__(self): "\n Add to the dir() output\n\n This is used by IPython to read off the tab completions.\n\n EXAMPLES::\n\n sage: from sage.interfaces.tab_completion import ExtraTabCompletion\n sage: obj = ExtraTabCompletion()\n ...
def completions(s, globs): "\n Return a list of completions in the given context.\n\n INPUT:\n\n - ``s`` -- a string\n\n - ``globs`` -- a string: object dictionary; context in which to\n search for completions, e.g., :func:`globals()`\n\n OUTPUT:\n\n a list of strings\n\n EXAMPLES::\n\n ...
class TachyonRT(SageObject): "\n The Tachyon Ray Tracer\n\n Usage:\n ``tachyon_rt(model, outfile='sage.png', verbose=1, block=True, extra_opts='')``\n\n INPUT:\n\n - ``model`` - a string that describes a 3d model in\n the Tachyon modeling format. Type ``sage.interfaces.tachyon?`` for a\n ...
def manyvars(s, num=70000, inlen=1, step=2000): '\n Test that > 65,000 variable names works in each system.\n ' print(('Testing -- %s' % s)) t = ('"%s"' % ('9' * int(inlen))) try: t = cputime() w = walltime() v = [] for i in range(num): if ((i % step) ...
def manyvars_all(num=70000): for s in [kash, magma, octave, maxima, mathematica]: manyvars(s, num)
def manyvars_all2(num=70000): for s in [singular, maxima, mathematica, octave]: manyvars(s, num)
def subexpressions_list(f, pars=None): "\n Construct the lists with the intermediate steps on the evaluation of the\n function.\n\n INPUT:\n\n - ``f`` -- a symbolic function of several components.\n\n - ``pars`` -- a list of the parameters that appear in the function\n this should be the symbo...
def remove_repeated(l1, l2): "\n Given two lists, remove the repeated elements in l1, and the elements\n in l2 that are on the same position.\n positions.\n\n EXAMPLES::\n\n sage: from sage.interfaces.tides import (subexpressions_list, remove_repeated)\n sage: f(a)=[1 + a^2, arcsin(a)]\n...
def remove_constants(l1, l2): "\n Given two lists, remove the entries in the first that are real constants,\n and also the corresponding elements in the second one.\n\n EXAMPLES::\n\n sage: from sage.interfaces.tides import subexpressions_list, remove_constants\n sage: f(a)=[1+cos(7)*a]\n ...
def genfiles_mintides(integrator, driver, f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16, output=''): '\n Generate the needed files for the min_tides library.\n\n INPUT:\n\n - ``integrator`` -- the name of the integrator file.\n\n - ``driver`` -- the name of the driver file.\n\n - ``f`` ...
def genfiles_mpfr(integrator, driver, f, ics, initial, final, delta, parameters=None, parameter_values=None, dig=20, tolrel=1e-16, tolabs=1e-16, output=''): '\n Generate the needed files for the mpfr module of the tides library.\n\n INPUT:\n\n - ``integrator`` -- the name of the integrator file.\n\n ...
def dowker_to_gauss(code): '\n Convert from Dowker-Thistlethwaite code to signed Gauss code.\n\n EXAMPLES::\n\n sage: from sage.knots.gauss_code import dowker_to_gauss\n sage: dowker_to_gauss([6,-12,2,8,-4,-10])\n [-3, 1, 6, -2, -1, 3, -4, 4, 2, -5, 5, -6]\n sage: dowker_to_gauss...
def recover_orientations(gauss): '\n Create diagrammatic information from signed Gauss code.\n\n This method is an auxiliary method, used for two different\n goals. The first goal is to create a knot from the signed Gauss\n code. This requires choosing at every crossing a local\n orientation, in a ...
def rectangular_diagram(gauss): '\n Return a rectangular diagram and crossing coordinates.\n\n INPUT:\n\n - signed Gauss code\n\n OUTPUT:\n\n - graph whose vertices are the corners of the knot diagram\n\n - positions of the horizontal and vertical crossings\n\n EXAMPLES::\n\n sage: fro...
class Knot(Link, Element, metaclass=InheritComparisonClasscallMetaclass): '\n A knot.\n\n A knot is defined as embedding of the circle `\\mathbb{S}^1` in the\n 3-dimensional sphere `\\mathbb{S}^3`, considered up to ambient isotopy.\n They represent the physical idea of a knotted rope, but with the\n ...
class Knots(Singleton, Parent): '\n The set for all knots, as a monoid for the connected sum.\n ' def __init__(self): '\n TESTS::\n\n sage: S = Knots()\n sage: S.cardinality()\n +Infinity\n sage: TestSuite(S).run()\n ' Parent.__i...
def eval_knotinfo(string, locals={}, to_tuple=True): "\n Preparse a string from the KnotInfo database and evaluate it by ``sage_eval``.\n\n INPUT:\n\n - ``string`` -- string that gives a value of some database entry\n - ``locals`` -- dictionary of locals passed to ``sage_eval``\n\n EXAMPLES::...
def knotinfo_bool(string): "\n Preparse a string from the KnotInfo database representing a boolean.\n\n INPUT:\n\n - ``string`` -- string that gives a value of some database entry\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import knotinfo_bool\n sage: knotinfo_bool('Y')\n ...
class KnotInfoBase(Enum): "\n Enum class to select the knots and links listed in the databases at the web-pages\n `KnotInfo <https://knotinfo.math.indiana.edu/>`__ and `LinkInfo <https://linkinfo.sitehost.iu.edu/>`__.\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import KnotInfo\n sage:...
class KnotInfoSeries(UniqueRepresentation, SageObject): "\n This class can be used to access knots and links via their index\n according to the series they belong to.\n\n INPUT:\n\n - ``crossing_number`` -- integer giving the crossing numer of this series\n of links\n - ``is_knot`` -- ...
class Link(SageObject): '\n A link.\n\n A link is an embedding of one or more copies of `\\mathbb{S}^1` in\n `\\mathbb{S}^3`, considered up to ambient isotopy. That is, a link\n represents the idea of one or more tied ropes. Every knot is a link,\n but not every link is a knot.\n\n A link can be...
class Dokchitser(SageObject): "\n Dokchitser's `L`-functions Calculator\n\n Create a Dokchitser `L`-series with\n\n Dokchitser(conductor, gammaV, weight, eps, poles, residues, init,\n prec)\n\n where\n\n - ``conductor`` -- integer, the conductor\n\n - ``gammaV`` -- list of Gamma-factor parame...
def reduce_load_dokchitser(D): X = Dokchitser(1, 1, 1, 1) X.__dict__ = D X.init_coeffs(X._Dokchitser__init) return X
class LCalc(SageObject): '\n Rubinstein\'s `L`-functions Calculator\n\n Type ``lcalc.[tab]`` for a list of useful commands that\n are implemented using the command line interface, but return\n objects that make sense in Sage. For each command the possible\n inputs for the L-function are:\n\n\n -...
class lfun_generic(): "\n Create a PARI `L`-function (:pari:`lfun` instance).\n\n The arguments are::\n\n lfun_generic(conductor, gammaV, weight, eps, poles, residues, init)\n\n where\n\n - ``conductor`` -- integer, the conductor\n\n - ``gammaV`` -- list of Gamma-factor parameters, e.g. [0] ...
def lfun_character(chi): '\n Create the L-function of a primitive Dirichlet character.\n\n If the given character is not primitive, it is replaced by its\n associated primitive character.\n\n OUTPUT:\n\n one :pari:`lfun` object\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfu...
def lfun_elliptic_curve(E): "\n Create the L-function of an elliptic curve.\n\n OUTPUT:\n\n one :pari:`lfun` object\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfun_elliptic_curve, LFunction\n sage: E = EllipticCurve('11a1')\n sage: L = LFunction(lfun_elliptic_curve(...
def lfun_number_field(K): "\n Create the Dedekind zeta function of a number field.\n\n OUTPUT:\n\n one :pari:`lfun` object\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfun_number_field, LFunction\n\n sage: L = LFunction(lfun_number_field(QQ))\n sage: L(3)\n 1....
def lfun_eta_quotient(scalings, exponents): '\n Return the L-function of an eta-quotient.\n\n This uses :pari:`lfunetaquo`.\n\n INPUT:\n\n - scalings -- a list of integers, the scaling factors\n\n - exponents -- a list of integers, the exponents\n\n EXAMPLES::\n\n sage: from sage.lfunctio...
def lfun_delta(): "\n Return the L-function of Ramanujan's Delta modular form.\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfun_delta, LFunction\n sage: L = LFunction(lfun_delta())\n sage: L(1)\n 0.0374412812685155\n " return lfun_eta_quotient([1], [24])
def lfun_quadratic_form(qf): '\n Return the L-function of a positive definite quadratic form.\n\n This uses :pari:`lfunqf`.\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfun_quadratic_form, LFunction\n sage: Q = QuadraticForm(ZZ, 2, [2, 3, 4])\n sage: L = LFunction(lfun_...
def lfun_genus2(C): "\n Return the L-function of a curve of genus 2.\n\n INPUT:\n\n - ``C`` -- hyperelliptic curve of genus 2\n\n Currently, the model needs to be minimal at 2.\n\n This uses :pari:`lfungenus2`.\n\n EXAMPLES::\n\n sage: from sage.lfunctions.pari import lfun_genus2, LFuncti...
class LFunction(SageObject): '\n Build the L-function from a PARI L-function.\n\n .. RUBRIC:: Rank 1 elliptic curve\n\n We compute with the `L`-series of a rank `1` curve. ::\n\n sage: E = EllipticCurve(\'37a\')\n sage: L = E.lseries().dokchitser(algorithm="pari"); L\n PARI L-functio...
class Sympow(SageObject): '\n Watkins Symmetric Power `L`-function Calculator\n\n Type ``sympow.[tab]`` for a list of useful commands\n that are implemented using the command line interface, but return\n objects that make sense in Sage.\n\n You can also use the complete command-line interface of sy...
class CoxeterGroup(UniqueRepresentation, Parent): @staticmethod def __classcall__(cls, cartan_type, *args, **options): "\n TESTS::\n\n sage: from sage.libs.coxeter3.coxeter_group import CoxeterGroup\n sage: CoxeterGroup(['B',2])\n Coxeter group of type ['B', 2]...
def CremonaModularSymbols(level, sign=0, cuspidal=False, verbose=0): '\n Return the space of Cremona modular symbols with given level, sign, etc.\n\n INPUT:\n\n - ``level`` -- an integer >= 2 (at least 2, not just positive!)\n - ``sign`` -- an integer either 0 (the default) or 1 or -1.\n - ``cuspi...
class mwrank_EllipticCurve(SageObject): "\n The :class:`mwrank_EllipticCurve` class represents an elliptic\n curve using the ``Curvedata`` class from ``eclib``, called here an 'mwrank\n elliptic curve'.\n\n Create the mwrank elliptic curve with invariants\n ``ainvs``, which is a list of 5 or less *...
class mwrank_MordellWeil(SageObject): '\n The :class:`mwrank_MordellWeil` class represents a subgroup of a\n Mordell-Weil group. Use this class to saturate a specified list\n of points on an :class:`mwrank_EllipticCurve`, or to search for\n points up to some bound.\n\n INPUT:\n\n - ``curve`` (:...
def load_or_compute(name, function): "\n Helper to load a cached value or compute it\n\n INPUT:\n\n - ``name`` -- string. Part of the cache filename\n\n - ``function`` -- function. To compute the value if not cached.\n\n OUTPUT:\n\n The value of ``function``, possibly cached.\n\n EXAMPLES::\n...
def list_keywords(): "\n Return the GAP reserved keywords\n\n OUTPUT:\n\n Tuple of strings.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.assigned_names import KEYWORDS\n sage: 'fi' in KEYWORDS # indirect doctest\n True\n " keywords = libgap.get_global('GAPInfo')['Keywords'...
def list_globals(): "\n Return the GAP reserved keywords\n\n OUTPUT:\n\n Tuple of strings.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.assigned_names import GLOBALS\n sage: 'ZassenhausIntersection' in GLOBALS # indirect doctest\n True\n " gvars = set((name.sage() for name...
def list_functions(): "\n Return the GAP documented global functions\n\n OUTPUT:\n\n Tuple of strings.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.assigned_names import FUNCTIONS\n sage: 'IsBound' in FUNCTIONS # is a keyword\n False\n sage: 'SubdirectProduct' in FUNCTION...
class GlobalVariableContext(): def __init__(self, variable, value): "\n Context manager for GAP global variables.\n\n It is recommended that you use the\n :meth:`sage.libs.gap.libgap.Gap.global_context` method and not\n construct objects of this class manually.\n\n INPU...
class OperationInspector(SageObject): def __init__(self, libgap_element): '\n Information about operations that can act on a given LibGAP element\n\n INPUT:\n\n - ``libgap_element`` -- libgap element.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.operations import Ope...
def timestamp(): "\n Return a time stamp for (lib)gap\n\n OUTPUT:\n\n Float. Unix timestamp of the most recently changed GAP/LibGAP file(s). In particular, the\n timestamp increases whenever a gap package is added.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.saved_workspace import timestamp\...
def workspace(name='workspace'): "\n Return the filename of the gap workspace and whether it is up to date.\n\n INPUT:\n\n - ``name`` -- string. A name that will become part of the\n workspace filename.\n\n OUTPUT:\n\n Pair consisting of a string and a boolean. The string is the\n filename ...
def test_write_to_file(): '\n Test that libgap can write to files\n\n See :trac:`16502`, :trac:`15833`.\n\n EXAMPLES::\n\n sage: from sage.libs.gap.test import test_write_to_file\n sage: test_write_to_file()\n ' fname = tmp_filename() message = "Ceci n'est pas une groupe" lib...
def test_loop_1(): '\n EXAMPLES::\n\n sage: from sage.libs.gap.test_long import test_loop_1\n sage: test_loop_1() # long time (up to 25s on sage.math, 2013)\n ' libgap.collect() for i in range(10000): G = libgap.CyclicGroup(2)
def test_loop_2(): '\n EXAMPLES::\n\n sage: from sage.libs.gap.test_long import test_loop_2\n sage: test_loop_2() # long time (10s on sage.math, 2013)\n ' G = libgap.FreeGroup(2) (a, b) = G.GeneratorsOfGroup() for i in range(100): rel = libgap([(a ** 2), (b ** 2), (((a * b...
def test_loop_3(): '\n EXAMPLES::\n\n sage: from sage.libs.gap.test_long import test_loop_3\n sage: test_loop_3() # long time (31s on sage.math, 2013)\n ' G = libgap.FreeGroup(2) (a, b) = G.GeneratorsOfGroup() for i in range(300000): lis = libgap([]) lis.Add((a ** ...
class GiacSettingsDefaultContext(): '\n Context preserve libgiac settings.\n ' def __enter__(self): '\n EXAMPLES::\n\n sage: from sage.libs.giac import GiacSettingsDefaultContext\n sage: from sage.libs.giac.giac import giacsettings\n sage: giacsettings.proba...
def local_giacsettings(func): "\n Decorator to preserve Giac's proba_epsilon and threads settings.\n\n EXAMPLES::\n\n sage: def testf(a,b):\n ....: giacsettings.proba_epsilon = a/100\n ....: giacsettings.threads = b+2\n ....: return (giacsettings.proba_epsilon, giacsetti...
@local_giacsettings def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False, elim_variables=None, *args, **kwds): '\n Compute a Groebner Basis of an ideal using ``giacpy_sage``. The result is\n automatically converted to sage.\n\n Supported term orders of the underlying polynomial ring are ...
def _lrcalc_dict_to_sage(result): '\n Translate from lrcalc output format to Sage expected format.\n\n TESTS::\n\n sage: from sage.libs.lrcalc.lrcalc import mult\n sage: mult([2,1],[3,2,1],3) # indirect doctest\n {[3, 3, 3]: 1, [4, 3, 2]: 2, [4, 4, 1]: 1, [5, 2, 2]: 1, [5, 3, 1]: 1}\n ...
def lrcoef_unsafe(outer, inner1, inner2): '\n Compute a single Littlewood-Richardson coefficient.\n\n Return the coefficient of ``outer`` in the product of the Schur\n functions indexed by ``inner1`` and ``inner2``.\n\n INPUT:\n\n - ``outer`` -- a partition (weakly decreasing list of non-negative i...
def lrcoef(outer, inner1, inner2): "\n Compute a single Littlewood-Richardson coefficient.\n\n Return the coefficient of ``outer`` in the product of the Schur\n functions indexed by ``inner1`` and ``inner2``.\n\n INPUT:\n\n - ``outer`` -- a partition (weakly decreasing list of non-negative integers...
def mult(part1, part2, maxrows=None, level=None, quantum=None): "\n Compute a product of two Schur functions.\n\n Return the product of the Schur functions indexed by the\n partitions ``part1`` and ``part2``.\n\n INPUT:\n\n - ``part1`` -- a partition\n - ``part2`` -- a partition\n - ``maxrows...
def skew(outer, inner, maxrows=(- 1)): '\n Compute the Schur expansion of a skew Schur function.\n\n Return a linear combination of partitions representing the Schur\n function of the skew Young diagram ``outer / inner``, consisting\n of boxes in the partition ``outer`` that are not in ``inner``.\n\n ...
def coprod(part, all=0): '\n Compute the coproduct of a Schur function.\n\n Return a linear combination of pairs of partitions representing\n the coproduct of the Schur function given by the partition\n ``part``.\n\n INPUT:\n\n - ``part`` -- a partition\n - ``all`` -- an integer\n\n If ``a...
def mult_schubert(w1, w2, rank=0): '\n Compute a product of two Schubert polynomials.\n\n Return a linear combination of permutations representing the\n product of the Schubert polynomials indexed by the permutations\n ``w1`` and ``w2``.\n\n INPUT:\n\n - ``w1`` -- a permutation\n - ``w2`` -- ...
def lrskew(outer, inner, weight=None, maxrows=(- 1)): '\n Iterate over the skew LR tableaux of shape ``outer / inner``.\n\n INPUT:\n\n - ``outer`` -- a partition\n - ``inner`` -- a partition\n - ``weight`` -- a partition (optional)\n - ``maxrows`` -- a positive integer (optional)\n\n OUTPUT: ...
def eval_constant(name, ring): prec = (ring.precision() + 20) return (ring(_constants_funcs[name](prec)) >> prec)
def _get_pari_instance(): '\n TESTS::\n\n sage: pari # indirect doctest\n Interface to the PARI C library\n ' from cypari2 import Pari stack_initial = (1024 * 1024) stack_max = (1024 * stack_initial) P = Pari(stack_initial, stack_max) from sage.ext.memory import init_memor...
class SingularFunctionFactory(): '\n A convenient interface to libsingular functions.\n ' def __getattr__(self, name): '\n EXAMPLES::\n\n sage: import sage.libs.singular.function_factory\n sage: groebner = sage.libs.singular.function_factory.ff.groebner\n ...
class LibSingularGBDefaultContext(): def __init__(self): "\n EXAMPLES::\n\n sage: from sage.libs.singular.standard_options import LibSingularGBDefaultContext\n sage: from sage.libs.singular.option import opt\n sage: P.<a,b,c> = PolynomialRing(QQ, 3, order='lex')\n ...
def libsingular_gb_standard_options(func): '\n Decorator to force a reduced Singular groebner basis.\n\n TESTS::\n\n sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))\n sage: J = sage.rings.ideal.Cyclic(P).homogenize()\n sage: from sage.misc.sageinspect import sage_getsource\n sage: ...
def eval_formula(tree, vdict): "\n Evaluate the tree and return a boolean value.\n\n INPUT:\n\n - ``tree`` -- a list of three elements corresponding to a branch of a\n parse tree\n\n - ``vdict`` -- a dictionary containing variable keys and boolean values\n\n OUTPUT:\n\n The result of the ev...
def eval_f(tree): "\n Evaluate the tree.\n\n INPUT:\n\n - ``tree`` -- a list of three elements corresponding to a branch of a\n parse tree\n\n OUTPUT:\n\n The result of the evaluation as a boolean value.\n\n EXAMPLES:\n\n This example illustrates how to evaluate a parse tree::\n\n ...
def eval_op(op, lv, rv): "\n Evaluate ``lv`` and ``rv`` according to the operator ``op``.\n\n INPUT:\n\n - ``op`` -- a string or character representing a boolean operator\n\n - ``lv`` -- a boolean or variable\n\n - ``rv`` -- a boolean or variable\n\n OUTPUT:\n\n The evaluation of ``lv op rv``...
class BooleanFormula(): '\n Boolean formulas.\n\n INPUT:\n\n - ``self`` -- calling object\n\n - ``exp`` -- a string; this contains the boolean expression\n to be manipulated\n\n - ``tree`` -- a list; this contains the parse tree of the expression.\n\n - ``vo`` -- a list; this contains the v...
class SymbolicLogic(): '\n EXAMPLES:\n\n This example illustrates how to create a boolean formula and print\n its table::\n\n sage: log = SymbolicLogic()\n sage: s = log.statement("a&b|!(c|a)")\n sage: t = log.truthtable(s)\n sage: log.print_table(t)\n a | b | c...
def get_bit(x, c): "\n Determine if bit ``c`` of the number ``x`` is 1.\n\n INPUT:\n\n - ``x`` -- an integer; this is the number from which to take the bit\n\n - ``c`` -- an integer; this is the bit number to be taken\n\n OUTPUT:\n\n A boolean value to be determined as follows:\n\n - ``True``...
def eval(toks): '\n Evaluate the expression contained in ``toks``.\n\n INPUT:\n\n - ``toks`` -- a list of tokens; this represents a boolean expression\n\n OUTPUT:\n\n A boolean value to be determined as follows:\n\n - ``True`` if expression evaluates to ``True``.\n\n - ``False`` if expression...
def eval_ltor_toks(lrtoks): '\n Evaluates the expression contained in ``lrtoks``.\n\n INPUT:\n\n - ``lrtoks`` -- a list of tokens; this represents a part of a boolean\n formula that contains no inner parentheses\n\n OUTPUT:\n\n A boolean value to be determined as follows:\n\n - ``True`` if ...
def reduce_bins(lrtoks): '\n Evaluate ``lrtoks`` to a single boolean value.\n\n INPUT:\n\n - ``lrtoks`` -- a list of tokens; this represents a part of a boolean\n formula that contains no inner parentheses or monotonic operators\n\n OUTPUT:\n\n ``None``; the pointer to lrtoks is now a list con...
def reduce_monos(lrtoks): '\n Replace monotonic operator/variable pairs with a boolean value.\n\n INPUT:\n\n - ``lrtoks`` -- a list of tokens; this represents a part of a boolean\n expression that contains now inner parentheses\n\n OUTPUT:\n\n ``None``; the pointer to ``lrtoks`` is now a list ...
def eval_mon_op(args): '\n Return a boolean value based on the truth table of the operator\n in ``args``.\n\n INPUT:\n\n - ``args`` -- a list of length 2; this contains the token \'NOT\' and\n then a variable name\n\n OUTPUT:\n\n A boolean value to be determined as follows:\n\n - ``True`...
def eval_bin_op(args): '\n Return a boolean value based on the truth table of the operator\n in ``args``.\n\n INPUT:\n\n - ``args`` -- a list of length 3; this contains a variable name,\n then a binary operator, and then a variable name, in that order\n\n OUTPUT:\n\n A boolean value; this i...
def eval_and_op(lval, rval): "\n Apply the 'and' operator to ``lval`` and ``rval``.\n\n INPUT:\n\n - ``lval`` -- a string; this represents the value of the variable\n appearing to the left of the 'and' operator\n\n - ``rval`` -- a string; this represents the value of the variable\n appearing...
def eval_or_op(lval, rval): "\n Apply the 'or' operator to ``lval`` and ``rval``.\n\n INPUT:\n\n - ``lval`` -- a string; this represents the value of the variable\n appearing to the left of the 'or' operator\n\n - ``rval`` -- a string; this represents the value of the variable\n appearing to...
def eval_ifthen_op(lval, rval): "\n Apply the 'if then' operator to ``lval`` and ``rval``.\n\n INPUT:\n\n - ``lval`` -- a string; this represents the value of the variable\n appearing to the left of the 'if then' operator\n\n - ``rval`` -- a string;t his represents the value of the variable\n ...
def eval_iff_op(lval, rval): "\n Apply the 'if and only if' operator to ``lval`` and ``rval``.\n\n INPUT:\n\n - ``lval`` -- a string; this represents the value of the variable\n appearing to the left of the 'if and only if' operator\n\n - ``rval`` -- a string; this represents the value of the var...
def tokenize(s, toks): '\n Tokenize ``s`` and place the tokens of ``s`` in ``toks``.\n\n INPUT:\n\n - ``s`` -- a string; this contains a boolean expression\n\n - ``toks`` -- a list; this will be populated with the tokens of ``s``\n\n OUTPUT:\n\n ``None``; the tokens of ``s`` are placed in ``toks...
def parse(s): "\n Return a parse tree from a boolean formula ``s``.\n\n INPUT:\n\n - ``s`` -- a string containing a boolean formula\n\n OUTPUT:\n\n A list containing the parse tree and a list containing the\n variables in a boolean formula in this order:\n\n 1. the list containing the parse t...
def polish_parse(s): "\n Return the full syntax parse tree from a boolean formula ``s``.\n\n INPUT:\n\n - ``s`` -- a string containing a boolean expression\n\n OUTPUT:\n\n The full syntax parse tree as a nested list.\n\n EXAMPLES:\n\n This example illustrates how to find the full syntax parse...
def get_trees(*statements): '\n Return the full syntax parse trees of the statements.\n\n INPUT:\n\n - ``*statements`` -- strings or :class:`BooleanFormula` instances\n\n OUTPUT:\n\n The parse trees in a list.\n\n EXAMPLES:\n\n This example illustrates finding the parse trees of multiple form...
def recover_formula(prefix_tree): '\n Recover the formula from a parse tree in prefix form.\n\n INPUT:\n\n - ``prefix_tree`` -- a list; this is a full syntax parse\n tree in prefix form\n\n OUTPUT:\n\n The formula as a string.\n\n EXAMPLES:\n\n This example illustrates the recovery of a ...
def recover_formula_internal(prefix_tree): '\n Recover the formula from a parse tree in prefix form.\n\n INPUT:\n\n - ``prefix_tree`` -- a list; this is a simple tree\n with at most one operator in prefix form\n\n OUTPUT:\n\n The formula as a string.\n\n EXAMPLES:\n\n This example illust...
def prefix_to_infix(prefix_tree): '\n Convert a parse tree from prefix form to infix form.\n\n INPUT:\n\n - ``prefix_tree`` -- a list; this is a full syntax parse\n tree in prefix form\n\n OUTPUT:\n\n A list containing the tree in infix form.\n\n EXAMPLES:\n\n This example illustrates co...
def to_infix_internal(prefix_tree): '\n Convert a simple parse tree from prefix form to infix form.\n\n INPUT:\n\n - ``prefix_tree`` -- a list; this is a simple parse tree\n in prefix form with at most one operator\n\n OUTPUT:\n\n The tree in infix form as a list.\n\n EXAMPLES:\n\n This ...
def tokenize(s): "\n Return the tokens and the distinct variables appearing in a boolean\n formula ``s``.\n\n INPUT:\n\n - ``s`` -- a string representation of a boolean formula\n\n OUTPUT:\n\n The tokens and variables as an ordered pair of lists in the following\n order:\n\n 1. A list cont...
def tree_parse(toks, polish=False): "\n Return a parse tree from the tokens in ``toks``.\n\n INPUT:\n\n - ``toks`` -- a list of tokens from a boolean formula\n\n - ``polish`` -- (default: ``False``) a boolean; when ``True``,\n :func:`~sage.logic.logicparser.tree_parse()` will return\n the fu...
def parse_ltor(toks, n=0, polish=False): "\n Return a parse tree from ``toks``, where each token in ``toks`` is atomic.\n\n INPUT:\n\n - ``toks`` -- a list of tokens. Each token is atomic.\n\n - ``n`` -- (default: 0) an integer representing which order of\n operations are occurring\n\n - ``pol...
def apply_func(tree, func): "\n Apply ``func`` to each node of ``tree``, and return a new parse tree.\n\n INPUT:\n\n - ``tree`` -- a parse tree of a boolean formula\n\n - ``func`` -- a function to be applied to each node of tree; this may\n be a function that comes from elsewhere in the logic mod...
class Truthtable(): '\n A truth table.\n\n INPUT:\n\n - ``t`` -- a 2-D array containing the table values\n\n - ``vo`` -- a list of the variables in the expression in order,\n with each variable occurring only once\n ' def __init__(self, t, vo): '\n Initialize the data field...
def formula(s): '\n Return an instance of :class:`BooleanFormula`.\n\n INPUT:\n\n - ``s`` -- a string that contains a logical expression\n\n OUTPUT:\n\n An instance of :class:`BooleanFormula`.\n\n EXAMPLES:\n\n This example illustrates ways to create a boolean formula::\n\n sage: f = p...
def get_formulas(*statements): '\n Convert statements and parse trees into instances of\n :class:`BooleanFormula`.\n\n INPUT:\n\n - ``*statements`` -- strings or lists; a list must be a\n full syntax parse tree of a formula, and a string must\n be a string representation of a formula\n\n ...
def consistent(*formulas): '\n Determine if the formulas are logically consistent.\n\n INPUT:\n\n - ``*formulas`` -- instances of :class:`BooleanFormula`\n\n OUTPUT:\n\n A boolean value to be determined as follows:\n\n - ``True`` - if the formulas are logically consistent\n\n - ``False`` - if...