Hi Fabian!
On Fri, Jan 23, 2009 at 3:38 AM, Fabian Seoane <[email protected]> wrote:
>
> In this email, I'll expose some design ideas for the new assumptions system.
> It would be great if I get some feedback and we agree on a clear design that
> we can implement.
First of all, many thanks for all the work you have done lately, it's
really helpful and also thanks for pushing these assumptions forward.
I have also concentrated on this lately, here is what I think:
The main problem I can see with your model is, that compared to
Mathematica below, it is a more complex, compare the one liner in
mathematica and 2 or more lines in sympy:
> Comparison with Mathematica's assumption system
> ================================================
>
> What would the examples from mathematica's web page [2] look like ?
>
> M = Mathematica
> S = Sympy
>
> M: Simplify[1/Sqrt[x] - Sqrt[1/x], x > 0]
> S: x = Symbol('x', assumptions=IsPositive)
> symplify(1/sqrt(x) - sqrt(1/x))
>
> M: FunctionExpand[Log[x y], x > 0 && y > 0]
> S: x, y = Symbol('x', assumptions=IsPositive), Symbol('y',
> assumptions=IsPositive)
> log(x*y).expand()
>
> M: Simplify[Sin[n Pi], n \[Element] Integers]
> S: n = Symbol('n', assumptions=IsInteger)
> simplify(sin(n*pi))
>
> M: FunctionExpand[
> EulerPhi[m n], {m, n} \[Element] Integers && GCD[m, n] == 1]
> S: n = Symbol('n', assumptions=IsInteger)
> m = Symbol('m', assumptions=IsInteger)
> n.assumptions.add(Eq(gcd(m, n) - 1))
> euler_phi(m, n)
Also I don't like that the assumptions are assigned to the symbols
directly. See also the issue #1047 for some arguments against it.
For example, if that is possible, I'd like to have the core really
simple, so that we can easily hook our Cython core into sympy.
However, thinking about it, your model can in fact be also transformed
into my idea how things could work, let me show it on the examples
above first:
M ... Mathematica
S1 .... SymPy, your approach
S2 .... SymPy, my approach
M: Simplify[1/Sqrt[x] - Sqrt[1/x], x > 0]
S1: x = Symbol('x', assumptions=IsPositive)
simplify(1/sqrt(x) - sqrt(1/x))
S2: simplify(1/sqrt(x) - sqrt(1/x), Assumptions(x>0))
M: FunctionExpand[Log[x y], x > 0 && y > 0]
S1: x, y = Symbol('x', assumptions=IsPositive), Symbol('y',
assumptions=IsPositive)
log(x*y).expand()
S2: log(x*y).expand(Assumptions([x>0, y>0]))
M: Simplify[Sin[n Pi], n \[Element] Integers]
S1: n = Symbol('n', assumptions=IsInteger)
simplify(sin(n*pi))
S2: simplify(sin(n*pi), Assumptions(Element(n, Integer)))
# we can talk about the syntax of Element(n, Integer)
M: FunctionExpand[
EulerPhi[m n], {m, n} \[Element] Integers && GCD[m, n] == 1]
S1: n = Symbol('n', assumptions=IsInteger)
m = Symbol('m', assumptions=IsInteger)
n.assumptions.add(Eq(gcd(m, n) - 1))
euler_phi(m, n)
S2: euler_phi(m, n).expand(Assumptions([Element(n, Integer),
Element(m, Integer), Eq(gcd(m, n) - 1)]))
# again we can talk about the syntax of Element(n, Integer)
I started to implement that as well. Pull from:
http://github.com/certik/sympy/tree/assume
And use like:
In [1]: from sympy import var, Assumptions, sqrt
In [3]: var("x y z")
Out[3]: (x, y, z)
In [5]: e = abs(x)
In [6]: print e
abs(x)
In [7]: print e.refine(Assumptions(x>0))
x
In [8]: print e.refine(Assumptions(x<0))
-x
What do you think?
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---