<commit_before>"""
This module contains the machinery handling assumptions.

All symbolic objects have assumption attributes that can be accessed via
.is_<assumption name> attribute.

Assumptions determine certain properties of symbolic objects. Assumptions
can have 3 possible values: True, False, None.  None is returned when it is
impossible to say something about the property. For example, a generic Symbol
is not known beforehand to be positive.

By default, all symbolic values are in the largest set in the given context
without specifying the property. For example, a symbol that has a property
being integer, is also real, complex, etc.

Here follows a list of possible assumption names:

    - commutative   - object commutes with any other object with
                        respect to multiplication operation.
    - real          - object can have only values from the set
                        of real numbers
    - integer       - object can have only values from the set
                        of integers
    - algebraic     - object can have only values from the set
                        of algebraic numbers
    - transcendental - object can have only values from the set
                        of transcendental numbers
    - bounded       - object absolute value is bounded
    - positive      - object can have only positive values
    - negative      - object can have only negative values
    - nonpositive      - object can have only nonpositive values
    - nonnegative      - object can have only nonnegative values
    - irrational    - object value cannot be represented exactly by Rational
    - unbounded     - object value is arbitrarily large

Implementation note: assumption values are stored in
._assumptions dictionary or are returned by getter methods (with
property decorators) or are attributes of objects/classes.

Examples
========

    >>> from sympy import Symbol
    >>> Symbol('x', real = True)
    x

"""
from __future__ import print_function, division

from sympy.core.facts import FactRules, FactKB
from sympy.core.core import BasicMeta
from sympy.core.compatibility import integer_types, with_metaclass

# This are the rules under which our assumptions function
#
# References
# ----------
#
# negative,     -- http://en.wikipedia.org/wiki/Negative_number
# nonnegative
#
# even, odd     -- http://en.wikipedia.org/wiki/Parity_(mathematics)
# imaginary     -- http://en.wikipedia.org/wiki/Imaginary_number
# composite     -- http://en.wikipedia.org/wiki/Composite_number
# finite        -- http://en.wikipedia.org/wiki/Finite
# irrational    -- http://en.wikipedia.org/wiki/Irrational_number
# transcendental -- http://en.wikipedia.org/wiki/Transcendental_number
# ...

_assume_rules = FactRules([

    'integer        ->  rational',
    'rational       ->  real',
    'rational       ->  algebraic',
    'algebraic      ->  complex',
    'real           ->  complex',
    'real           ->  hermitian',
    'imaginary      ->  complex',
    'imaginary      ->  antihermitian',
    'complex        ->  commutative',

    'odd            ==  integer & !even',
    'even           ==  integer & !odd',

    'real           ==  negative | zero | positive',
    'transcendental ==  complex & !algebraic',

    'negative       ==  nonpositive & nonzero',
    'positive       ==  nonnegative & nonzero',
    'zero           ==  nonnegative & nonpositive',

    'nonpositive    ==  real & !positive',
    'nonnegative    ==  real & !negative',

    'zero           ->  even',

    'prime          ->  integer & positive',
    'composite      ==  integer & positive & !prime',

    'irrational     ==  real & !rational',

    'imaginary      ->  !real',

    '!bounded     ==  unbounded',
    'noninteger     ==  real & !integer',
    '!zero        ==  nonzero',
])

_assume_defined = _assume_rules.defined_facts.copy()
_assume_defined.add('polar')
_assume_defined = frozenset(_assume_defined)


class StdFactKB(FactKB):
    """A FactKB specialised for the built-in rules
<commit_msg>Rename assumptions: bounded -> finite, unbounded -> infinite [1/5]<commit_after>"""
This module contains the machinery handling assumptions.

All symbolic objects have assumption attributes that can be accessed via
.is_<assumption name> attribute.

Assumptions determine certain properties of symbolic objects. Assumptions
can have 3 possible values: True, False, None.  None is returned when it is
impossible to say something about the property. For example, a generic Symbol
is not known beforehand to be positive.

By default, all symbolic values are in the largest set in the given context
without specifying the property. For example, a symbol that has a property
being integer, is also real, complex, etc.

Here follows a list of possible assumption names:

    - commutative   - object commutes with any other object with
                        respect to multiplication operation.
    - real          - object can have only values from the set
                        of real numbers
    - integer       - object can have only values from the set
                        of integers
    - algebraic     - object can have only values from the set
                        of algebraic numbers
    - transcendental - object can have only values from the set
                        of transcendental numbers
    - finite        - object absolute value is bounded
    - positive      - object can have only positive values
    - negative      - object can have only negative values
    - nonpositive      - object can have only nonpositive values
    - nonnegative      - object can have only nonnegative values
    - irrational    - object value cannot be represented exactly by Rational
    - infinite      - object value is arbitrarily large

Implementation note: assumption values are stored in
._assumptions dictionary or are returned by getter methods (with
property decorators) or are attributes of objects/classes.

Examples
========

    >>> from sympy import Symbol
    >>> Symbol('x', real = True)
    x

"""
from __future__ import print_function, division

from sympy.core.facts import FactRules, FactKB
from sympy.core.core import BasicMeta
from sympy.core.compatibility import integer_types, with_metaclass

# This are the rules under which our assumptions function
#
# References
# ----------
#
# negative,     -- http://en.wikipedia.org/wiki/Negative_number
# nonnegative
#
# even, odd     -- http://en.wikipedia.org/wiki/Parity_(mathematics)
# imaginary     -- http://en.wikipedia.org/wiki/Imaginary_number
# composite     -- http://en.wikipedia.org/wiki/Composite_number
# finite        -- http://en.wikipedia.org/wiki/Finite
# irrational    -- http://en.wikipedia.org/wiki/Irrational_number
# transcendental -- http://en.wikipedia.org/wiki/Transcendental_number
# ...

_assume_rules = FactRules([

    'integer        ->  rational',
    'rational       ->  real',
    'rational       ->  algebraic',
    'algebraic      ->  complex',
    'real           ->  complex',
    'real           ->  hermitian',
    'imaginary      ->  complex',
    'imaginary      ->  antihermitian',
    'complex        ->  commutative',

    'odd            ==  integer & !even',
    'even           ==  integer & !odd',

    'real           ==  negative | zero | positive',
    'transcendental ==  complex & !algebraic',

    'negative       ==  nonpositive & nonzero',
    'positive       ==  nonnegative & nonzero',
    'zero           ==  nonnegative & nonpositive',

    'nonpositive    ==  real & !positive',
    'nonnegative    ==  real & !negative',

    'zero           ->  even',

    'prime          ->  integer & positive',
    'composite      ==  integer & positive & !prime',

    'irrational     ==  real & !rational',

    'imaginary      ->  !real',

    '!finite        ==  infinite',
    'noninteger     ==  real & !integer',
    '!zero        ==  nonzero',
])

_assume_defined = _assume_rules.defined_facts.copy()
_assume_defined.add('polar')
_assume_defined = frozenset(_assume_defined)


class StdFactKB(FactKB):
    """A FactKB specialised for the built-in rules

{'fraction_non_alphanumeric': 0.09121122599704579, 'fraction_numerical': 0.0004923682914820286, 'mean_word_length': 2.401004604437003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1972756', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2056, 'n_words': 752}