MatPow bug or inconsistency?

Visto 29 veces
Saltar al primer mensaje no leído

Tomasz Pytel

no leída,
11 jul 2019, 11:41:1611/7/19
a sympy
Matrix([[1,0],[0,1]])**2
= Matrix([
[1, 0],
[0, 1]])

Matrix([[1,0],[0,1]])**x
= Matrix([
[1, 0],
[0, 1]])

MatPow (Matrix([[1,0],[0,1]]), 2).doit ()
= Matrix([
[1, 0],
[0, 1]])

MatPow (Matrix([[1,0],[0,1]]), x).doit ()
= Matrix([
[1, 0],
[0, 1]])**x

Gagandeep Singh (B17CS021)

no leída,
11 jul 2019, 11:45:5311/7/19
a sympy
I believe the results are looking fine. Can you please let us know what you actually expected?

Tomasz Pytel

no leída,
11 jul 2019, 12:23:4211/7/19
a sympy
Expected:

Matrix([[1,0],[0,1]])**x 
== 

Gagandeep Singh (B17CS021)

no leída,
11 jul 2019, 12:30:4511/7/19
a sympy
Ah! I missed that.
Have you tried a matrix other than identity?

Tomasz Pytel

no leída,
11 jul 2019, 12:39:1011/7/19
a sympy
Yes, various, try it with [[0,1],[1,0]] 

Gagandeep Singh (B17CS021)

no leída,
11 jul 2019, 12:40:2711/7/19
a sympy
In my opinion, it shouldn't happen. Feel free to raise an issue on github for this.

Oscar Benjamin

no leída,
11 jul 2019, 12:44:0211/7/19
a sympy
I don't have a computer to test but what happens if x is declared as an integer? For non-integer (or non-real) x the result doesn't necessarily hold.


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/def85976-42a2-4dd0-90a6-b65d7ea7b718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Bailey

no leída,
11 jul 2019, 12:47:1911/7/19
a sy...@googlegroups.com
On 11/07/2019 17:40, Gagandeep Singh (B17CS021) wrote:
In my opinion, it shouldn't happen. Feel free to raise an issue on github for this. 

A while back I was advised to report a SymPy website issue on github. The site said it would email me back (to set up a user name), and no message came. I don't know if I am the only person with that problem.

David

Tomasz Pytel

no leída,
11 jul 2019, 12:48:4511/7/19
a sympy
The point being behavior is inconsistent between ** operator and doit().

Gagandeep Singh (B17CS021)

no leída,
11 jul 2019, 12:50:2011/7/19
a sympy
I think for website the issue can be raised at, https://github.com/sympy/sympy.github.com/issues
Is it the case that you are not on github?

Jogi Miglani

no leída,
11 jul 2019, 12:58:3311/7/19
a sy...@googlegroups.com
I might had done work on this in #15712. But in that case i considered the cases where the determinent of Matrix was zero. Although something can be changed here to meet up the right requirements.

On Thu, Jul 11, 2019 at 10:20 PM Gagandeep Singh (B17CS021) <sing...@iitj.ac.in> wrote:
I think for website the issue can be raised at, https://github.com/sympy/sympy.github.com/issues
Is it the case that you are not on github?

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

David Bailey

no leída,
12 jul 2019, 7:12:5112/7/19
a sy...@googlegroups.com

I am puzzled as to whether 64 bit python under windows supports plotting. Here is a typical experiment to obtain a plot:

import sympy
from sympy import *
var('x y')
plotting.plot3d((exp(-(x**2+y**2))),(x,-3,3),(y,-3,3))


Traceback (most recent call last):
  File "C:\PythonTests\SymPyWorkbook\plottest.py", line 4, in <module>
    plotting.plot3d((exp(-(x**2+y**2))),(x,-3,3),(y,-3,3))
  File "C:\PythonSystem\lib\site-packages\sympy\plotting\plot.py", line 1756, in plot3d
    plots.show()
  File "C:\PythonSystem\lib\site-packages\sympy\plotting\plot.py", line 186, in show
    self._backend = self.backend(self)
  File "C:\PythonSystem\lib\site-packages\sympy\plotting\plot.py", line 1114, in __new__
    return MatplotlibBackend(parent)
  File "C:\PythonSystem\lib\site-packages\sympy\plotting\plot.py", line 904, in __init__
    self.plt = self.matplotlib.pyplot
AttributeError: 'NoneType' object has no attribute 'pyplot'

I have also tried creating an image file, rather than using Windows directly:

import sympy
from sympy import *
from sympy.plotting import plot
x = symbols('x')
p1 = plot(x*x, show=False)
p2 = plot(x, show=False)
# p1.append(p2[0])
p1.save('testing.png')

This also failed

David


Jean ABOU SAMRA

no leída,
12 jul 2019, 8:42:0412/7/19
a da...@dbailey.co.uk,sy...@googlegroups.com
Hi David,
Does this simple code work?

import matplotlib.pyplot as plt
plt.plot([0, 1], [2, 3])
plt.show()

Indeed, it looks like matplotlib is not installed or not available for import on your machine. SymPy relies on matplotlib for plotting (both are part of the global SciPy project). However matplotlib is not strictly necessary to use SymPy (because not everybody needs plotting) so I guess that this frame:

  File "C:\PythonSystem\lib\site-packages\sympy\plotting\plot.py", line 904, in __init__
    self.plt = self.matplotlib.pyplot
AttributeError: 'NoneType' object has no attribute 'pyplot'

just means that matplotlib couldn't be imported so the `matpotlib` variable was assigned None, assuming you don't need plotting.
If you don't have matplotlib installed, in general you just want to install it using pip (usually `python3 -m pip install matplotlib`) althought there are other methods.

Regards,
Jean Abou Samra

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Jean ABOU SAMRA

no leída,
12 jul 2019, 9:48:3612/7/19
a David Bailey,sy...@googlegroups.com
Thanks for that quick response. Here is what I get using that code:


Traceback (most recent call last):
  File "C:\PythonTests\SymPyWorkbook\t1.py", line 1, in <module>
    import matplotlib.pyplot as plt
  File "C:\PythonSystem\lib\site-packages\matplotlib\pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "C:\PythonSystem\lib\site-packages\matplotlib\pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "C:\PythonSystem\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\PythonSystem\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "C:\PythonSystem\lib\site-packages\matplotlib\backends\_backend_tk.py", line 5, in <module>
    import tkinter as Tk
ModuleNotFoundError: No module named 'tkinter'

Cough. It's more complicated than I thought at first.

I therefore tried to install mathplotlib

...\Scripts>pip install mathplotlib
Collecting mathplotlib
  ERROR: Could not find a version that satisfies the requirement mathplotlib (from versions: none)
ERROR: No matching distribution found for mathplotlib


This is just because you misspelled it, it's matplotlib, not mathplotlib (I admit I always hated this complicated name). I guess that if you do it with the h removed, you should get a message telling that matplotlib is already installed. (Beware, I don't know if it's `pip` or `pip3` in your case. Do pip --version  and verify that it mentions Python 3.7. If not, try pip3.7  .)

The error is deeper than matplotlib not being installed because you traceback tells that it _is_ installed: "C:\PythonSystem\lib\site-packages\matplotlib…".
But the problem is that Tk is not configured. maplotlib has several "backends" which you can see as the way the user interface is constructed -- see https://matplotlib.org/tutorials/introductory/usage.html#what-is-a-backend  The default backend is TkAgg (Tk anti-grain geometry) which relies on Tk, a tool that you don't have installed.

From experience, Tk can be a pain to install because it has to be compiled with your Python, so you would have to reinstall a different Python. So, I would rather recommend just using another backend, for example Qt5Agg. This requires to have PyQt5 installed, but trust me, this is _much_ simpler.

- Check your pip as I told before. You should get a pipxxx command such as pipxxx --version says "python 3.7". Normally, pip3.7 should work in all cases.
- Install or upgrade PyQt5:  pip3.7 install --upgrade PyQt5
- Now you have to tell matplotlib which backend you want to use.
  - First try this:

import matplotlib
matplotlib.use("Qt5Agg")
import sympy
from sympy import *
var('x y')
plotting.plot3d((exp(-(x**2+y**2))),(x,-3,3),(y,-3,3))

  - Now if it works, you want to set your default backend so that you don't need the matplotlib.use() part. To do that, I would advise editing the  C:\PythonSystem\lib\site-packages\matplotlib/mpl-data/matplotlibrc  file. Just put in it:
backend : Qt5Agg
Hope that helps !
Regards,
Jean Abou Samra


Jean ABOU SAMRA

no leída,
12 jul 2019, 12:00:5812/7/19
a David Bailey,sy...@googlegroups.com
> C:\PythonSystem\lib\site-packages\matplotlib/mpl-data/matplotlibrc

Sorry, that's with backslashes: C:\PythonSystem\lib\site-packages\matplotlib\mpl-data\matplotlibrc

David Bailey

no leída,
12 jul 2019, 16:47:1312/7/19
a sy...@googlegroups.com
On 12/07/2019 14:48, Jean ABOU SAMRA wrote:

Cough. It's more complicated than I thought at first.

Thank you! Amazingly, all that worked first time - I certainly would not have stumbled upon that solution on my own! Pip did the job, I did not need to use a variant:

pip --version
pip 19.1.1 from c:\pythonsystem\lib\site-packages\pip (python 3.7)

Tell me, if I want to create an application for others to use, I'd certainly not want everyone to have to go through that procedure. Do I take it that I can put a suitably configured Python directory in a subdirectory of the directory containing the application so that my code will run out of the box (so to speak)? Also are there any legal complications to doing that?

I take it more than one backend can be installed and selected by the matplotlib.use() instruction?

OK - I certainly don't want to sound grudging after helping me like that, but I guess this forum is concerned with ways to improve sympy as much as possible, so here goes.

Can't this all be tidied up a bit - users must hit this problem very often. In fact I thought I did everything in a completely standard way - I downloaded and installed Pyethon3.7, installed sympy and (I remember now) installed matplotlib. Is there any reason why that should not work by default?

Surely if a suitable backend is not available, the system could detect this and emit a meaningful error message - or better still attempt to download and install the necessary files (rather as Latex does), and then continue?

David


Jean ABOU SAMRA

no leída,
13 jul 2019, 6:50:3513/7/19
a da...@dbailey.co.uk,sy...@googlegroups.com

Le 12 juil. 2019 à 22:47, David Bailey <da...@dbailey.co.uk> a écrit :

On 12/07/2019 14:48, Jean ABOU SAMRA wrote:

Cough. It's more complicated than I thought at first.

Thank you! Amazingly, all that worked first time - I certainly would not have stumbled upon that solution on my own! Pip did the job, I did not need to use a variant:

Great! Glad you solved your problem.

pip --version
pip 19.1.1 from c:\pythonsystem\lib\site-packages\pip (python 3.7)

That's fine. I said this because on some systems (mostly Unix), `pip` refers to pip being used on Python 2 and pip with Python 3 has to be referred to as pip3. Many users get confused, so it's always worth a check.

Tell me, if I want to create an application for others to use, I'd certainly not want everyone to have to go through that procedure. Do I take it that I can put a suitably configured Python directory in a subdirectory of the directory containing the application so that my code will run out of the box (so to speak)?

You can surely do that. You will have to execute Python from the right place. But there are some problems, especially the fact that the methods to do that vary depending on the client OS. Fortunately, there are some tools around that will help you (keep reading).

Also are there any legal complications to doing that?

There aren't any because Python is free and open source software and the Python license explicitly states that you have the right to "to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python".

I take it more than one backend can be installed and selected by the matplotlib.use() instruction?

All matplotlib backends ship with matplotlib, they don't have to be "installed" but some of them have dependencies that you have to install. To use TkAgg, you need Tk, PyQt5 to use Qt5Agg, wxpython to use WXAgg, and so on. Then, you tell matplotlib which one you prefer. As https://matplotlib.org/faq/usage_faq.html#what-is-a-backend specifies, there are several methods to do this. You can set your default backend, and you can also tell matplotlib that this script absolutely requires this backend whatever the default is throug the matplotlib.use() function.

OK - I certainly don't want to sound grudging after helping me like that, but I guess this forum is concerned with ways to improve sympy as much as possible, so here goes.

Can't this all be tidied up a bit - users must hit this problem very often. In fact I thought I did everything in a completely standard way - I downloaded and installed Pyethon3.7, installed sympy and (I remember now) installed matplotlib. Is there any reason why that should not work by default?

It's a bit more complicated than this because Tk is a separate tool but it has to be detected at compile time. PyQt5 (a binding for the Qt5 framework) doesn't have this issue. Though, I'm quite puzzled because I thought that starting from 3.7, Python would always include a suitable Tk. I agree that tkinter is surprisingly difficult to install -- as https://wiki.python.org/moin/TkInter shows.

Surely if a suitable backend is not available, the system could detect this and emit a meaningful error message - or better still attempt to download and install the necessary files (rather as Latex does), and then continue?

There is better.
First, you can always specifiy PyQt5 as a dependency to your application in addition to SymPy and matplotlib. If your project is installable via pip (ie you put it on PyPI) then it's easy to tell what dependencies your app relies on and they will be automatically installed with it.
Additionally, 'm not a specialist but you certainly want to use a Python virtual environment using the virtualenv module. Your idea of putting a Python executable inside your application is quite like this. A virtual environment is an Python environment that you can separate from your system. An environment is a version of Python, and separate packages each with its version.
This way, you can manage to have PyQt5 installed locally (so any people copying the directory will get the right PyQt5 with it) and force the backend to be Qt5Agg -- through matplotlib.use() -- so everything runs smoothly.

Kind regards,
Jean Abou Samra.

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos