(proposition, assumptions=True, context=global_assumptions)
return ask_full_inference(key, local_facts, known_facts_cnf)
Method for inferring properties about objects.

    **Syntax**

        * ask(proposition)

        * ask(proposition, assumptions)

            where ``proposition`` is any boolean expression

    Examples
    ========

    >>> from sympy import ask, Q, pi
    >>> from sympy.abc import x, y
    >>> ask(Q.rational(pi))
    False
    >>> ask(Q.even(x*y), Q.even(x) & Q.integer(y))
    True
    >>> ask(Q.prime(x*y), Q.integer(x) &  Q.integer(y))
    False

    **Remarks**
        Relations in assumptions are not implemented (yet), so the following
        will not give a meaningful result.

        >>> ask(Q.positive(x), Q.is_true(x > 0)) # doctest: +SKIP

        It is however a work in progress.
Method for inferring properties about objects.
Method for inferring properties about objects .
def ask(proposition, assumptions=True, context=global_assumptions):
    """
    Method for inferring properties about objects.

    **Syntax**

        * ask(proposition)

        * ask(proposition, assumptions)

            where ``proposition`` is any boolean expression

    Examples
    ========

    >>> from sympy import ask, Q, pi
    >>> from sympy.abc import x, y
    >>> ask(Q.rational(pi))
    False
    >>> ask(Q.even(x*y), Q.even(x) & Q.integer(y))
    True
    >>> ask(Q.prime(x*y), Q.integer(x) &  Q.integer(y))
    False

    **Remarks**
        Relations in assumptions are not implemented (yet), so the following
        will not give a meaningful result.

        >>> ask(Q.positive(x), Q.is_true(x > 0)) # doctest: +SKIP

        It is however a work in progress.

    """
    if not isinstance(proposition, (BooleanFunction, AppliedPredicate, bool, BooleanAtom)):
        raise TypeError("proposition must be a valid logical expression")

    if not isinstance(assumptions, (BooleanFunction, AppliedPredicate, bool, BooleanAtom)):
        raise TypeError("assumptions must be a valid logical expression")

    if isinstance(proposition, AppliedPredicate):
        key, expr = proposition.func, sympify(proposition.arg)
    else:
        key, expr = Q.is_true, sympify(proposition)

    assumptions = And(assumptions, And(*context))
    assumptions = to_cnf(assumptions)

    local_facts = _extract_facts(assumptions, expr)

    if local_facts and satisfiable(And(local_facts, known_facts_cnf)) is False:
        raise ValueError("inconsistent assumptions %s" % assumptions)

    # direct resolution method, no logic
    res = key(expr)._eval_ask(assumptions)
    if res is not None:
        return bool(res)

    if assumptions == True:
        return

    if local_facts is None:
        return

    # See if there's a straight-forward conclusion we can make for the inference
    if local_facts.is_Atom:
        if key in known_facts_dict[local_facts]:
            return True
        if Not(key) in known_facts_dict[local_facts]:
            return False
    elif local_facts.func is And and all(k in known_facts_dict for k in local_facts.args):
        for assum in local_facts.args:
            if assum.is_Atom:
                if key in known_facts_dict[assum]:
                    return True
                if Not(key) in known_facts_dict[assum]:
                    return False
            elif assum.func is Not and assum.args[0].is_Atom:
                if key in known_facts_dict[assum]:
                    return False
                if Not(key) in known_facts_dict[assum]:
                    return True
    elif (isinstance(key, Predicate) and
            local_facts.func is Not and local_facts.args[0].is_Atom):
        if local_facts.args[0] in known_facts_dict[key]:
            return False

    # Failing all else, we do a full logical inference
    return ask_full_inference(key, local_facts, known_facts_cnf)
def ask ( proposition , assumptions = True , context = global_assumptions ) : if not isinstance ( proposition , ( BooleanFunction , AppliedPredicate , bool , BooleanAtom ) ) : raise TypeError ( "proposition must be a valid logical expression" ) if not isinstance ( assumptions , ( BooleanFunction , AppliedPredicate , bool , BooleanAtom ) ) : raise TypeError ( "assumptions must be a valid logical expression" ) if isinstance ( proposition , AppliedPredicate ) : key , expr = proposition . func , sympify ( proposition . arg ) else : key , expr = Q . is_true , sympify ( proposition ) assumptions = And ( assumptions , And ( * context ) ) assumptions = to_cnf ( assumptions ) local_facts = _extract_facts ( assumptions , expr ) if local_facts and satisfiable ( And ( local_facts , known_facts_cnf ) ) is False : raise ValueError ( "inconsistent assumptions %s" % assumptions ) # direct resolution method, no logic res = key ( expr ) . _eval_ask ( assumptions ) if res is not None : return bool ( res ) if assumptions == True : return if local_facts is None : return # See if there's a straight-forward conclusion we can make for the inference if local_facts . is_Atom : if key in known_facts_dict [ local_facts ] : return True if Not ( key ) in known_facts_dict [ local_facts ] : return False elif local_facts . func is And and all ( k in known_facts_dict for k in local_facts . args ) : for assum in local_facts . args : if assum . is_Atom : if key in known_facts_dict [ assum ] : return True if Not ( key ) in known_facts_dict [ assum ] : return False elif assum . func is Not and assum . args [ 0 ] . is_Atom : if key in known_facts_dict [ assum ] : return False if Not ( key ) in known_facts_dict [ assum ] : return True elif ( isinstance ( key , Predicate ) and local_facts . func is Not and local_facts . args [ 0 ] . is_Atom ) : if local_facts . args [ 0 ] in known_facts_dict [ key ] : return False # Failing all else, we do a full logical inference return ask_full_inference ( key , local_facts , known_facts_cnf )