From b198a3f0f2128016aefeb0134c61ee357a115bc9 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Sat, 5 Dec 2015 09:42:19 +0100 Subject: [PATCH 1/2] 19035: document syncing of generic assumptions on symbols/functions with Pynac --- src/sage/symbolic/assumptions.py | 55 ++++++++++++++++++++++++++++++-- src/sage/symbolic/expression.pyx | 28 ++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/sage/symbolic/assumptions.py b/src/sage/symbolic/assumptions.py index 698273ded02..b8c52cdb048 100644 --- a/src/sage/symbolic/assumptions.py +++ b/src/sage/symbolic/assumptions.py @@ -1,5 +1,56 @@ """ Assumptions + +The ``GenericDeclaration`` class provides assumptions about a symbol or +function in verbal form. Such assumptions can be made using the :meth:`assume` +function in this module, which also can take any relation of symbolic +expressions as argument. Use :meth:`forget()` to clear all assumptions. +Creating a variable with a specific domain is equivalent with making an +assumption about it. + +There is only rudimentary support for consistency and satisfiability checking +in Sage. Assumptions are used both in Maxima and Pynac to support or refine +some computations. In the following we show how to make and query assumptions. +Please see the respective modules for more practical examples. + +EXAMPLES: + +The default domain of a symbolic variable is the complex plain:: + + sage: var('x') + x + sage: x.is_real() + False + sage: assume(x,'real') + sage: x.is_real() + True + sage: forget() + sage: x.is_real() + False + +Here is the list of acceptable features:: + + sage: maxima('features') + [integer,noninteger,even,odd,rational,irrational,real,imaginary,complex,analytic,increasing,decreasing,oddfun,evenfun,posfun,constant,commutative,lassociative,rassociative,symmetric,antisymmetric,integervalued] + +Set positive domain using a relation:: + + sage: assume(x>0) + sage: x.is_positive() + True + sage: x.is_real() + True + sage: assumptions() + [x > 0] + +Assumptions are added and in some cases checked for consistency:: + + sage: assume(x>0) + sage: assume(x<0) + Traceback (most recent call last): + ... + ValueError: Assumption is inconsistent + sage: forget() """ from sage.structure.sage_object import SageObject from sage.rings.all import ZZ, QQ, RR, CC @@ -11,8 +62,8 @@ class GenericDeclaration(SageObject): """ This class represents generic assumptions, such as a variable being an integer or a function being increasing. It passes such - information to maxima's declare (wrapped in a context so it is able - to forget). + information to Maxima's declare (wrapped in a context so it is able + to forget) and to Pynac. INPUT: diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 98341bacfe3..4a5347ea880 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -1907,6 +1907,14 @@ cdef class Expression(CommutativeRingElement): sage: (x*x.conjugate()).is_real() False + + Assumption of real has the same effect as setting the domain:: + + sage: forget() + sage: assume(x, 'real') + sage: x.is_real() + True + sage: forget() """ return self._gobj.info(info_real) @@ -1930,6 +1938,18 @@ cdef class Expression(CommutativeRingElement): True sage: (t0*x).is_positive() False + + :: + + sage: forget() + sage: assume(x>0) + sage: x.is_positive() + True + sage: f = function('f')(x) + sage: assume(f>0) + sage: f.is_positive() + True + sage: forget() """ return self._gobj.info(info_positive) @@ -1970,6 +1990,14 @@ cdef class Expression(CommutativeRingElement): sage: _ = var('n', domain='integer') sage: n.is_integer() True + + Assumption of integer has the same effect as setting the domain:: + + sage: forget() + sage: assume(x, 'integer') + sage: x.is_integer() + True + sage: forget() """ return self._gobj.info(info_integer) From 3f00cf951135867df76a55e81ad03269df826789 Mon Sep 17 00:00:00 2001 From: Ralf Stephan Date: Mon, 7 Dec 2015 07:30:11 +0100 Subject: [PATCH 2/2] fix typos --- src/sage/symbolic/assumptions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/assumptions.py b/src/sage/symbolic/assumptions.py index b8c52cdb048..5b2ef9d6cb2 100644 --- a/src/sage/symbolic/assumptions.py +++ b/src/sage/symbolic/assumptions.py @@ -2,9 +2,9 @@ Assumptions The ``GenericDeclaration`` class provides assumptions about a symbol or -function in verbal form. Such assumptions can be made using the :meth:`assume` +function in verbal form. Such assumptions can be made using the :func:`assume` function in this module, which also can take any relation of symbolic -expressions as argument. Use :meth:`forget()` to clear all assumptions. +expressions as argument. Use :func:`forget` to clear all assumptions. Creating a variable with a specific domain is equivalent with making an assumption about it. @@ -15,7 +15,7 @@ EXAMPLES: -The default domain of a symbolic variable is the complex plain:: +The default domain of a symbolic variable is the complex plane:: sage: var('x') x