Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify[Sqrt[x^2], x > 0] #921

Open
fja-pedraza opened this issue Sep 19, 2023 · 1 comment
Open

Simplify[Sqrt[x^2], x > 0] #921

fja-pedraza opened this issue Sep 19, 2023 · 1 comment

Comments

@fja-pedraza
Copy link

Description

The expression Simplify[Sqrt[x^2], x > 0] does not result in x, as expected

How to Reproduce

In Django go to a new notebook cell and enter the expression: Simplify[Sqrt[x^2], x > 0]
Simultaneously press the Shift+Enter keys

Output Given

The obtained result is: Sqrt[ x ^ 2 ]

Expected behavior

The expected result is: x

Your Environment

Software Information
Python
Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Implementation: CPython 3.10.12.final.0
Mathics3 Software
Mathics3 Django: 6.0.0
Mathics3: 6.0.2
Web Software
Django: 4.2.5
mathics-threejs-backend: 1.3.1
three.js: 146
MathJax: 2.7.9
Numeric Software
mpmath: 1.3.0
Numpy: 1.24.4
Sympy: 1.12
Optional Software
cython: Not installed
lxml: 4.9.3
networkx: 3.1
nltk: 3.8.1
psutil: Not installed
skimage: Not installed
scipy: 1.11.2
wordcloud: Not installed
Settings
Django
ALLOWED_HOSTS: []
DEBUG: True
DISPLAY_EXCEPTIONS: False
Mathics3 Django
Settings$PreferredBackendMethod: "sympy" This sets whether to use mpmath, numpy or Sympy for numeric and symbolic constants and methods, when there is a choice. Settings$QuotedStrings:
If this Boolean variable is set False, hide the quotes when the top-level value is a string.
Settings$TraceGet: If this Boolean variable is set True, 'Get' traces the lines it reads that start a new expression. Settings$UseSansSerif:
If this Boolean variable is set True, MathMLForm uses a Sans-Serif font.
System information
User Name: fpedraza
Process ID: 357
System Time Zone: -6.0
File Paths
Base Directory: /home/fpedraza/.local/lib/python3.10/site-packages/mathics
Home Directory: /home/fpedraza
Installation Directory: /home/fpedraza/.local/lib/python3.10/site-packages/mathics
Root Directory: /
Temporary Directory: /tmp
Workspace Database File: /home/fpedraza/.local/var/mathics/mathics.sqlite
Doctest Data: /home/fpedraza/.local/var/mathics/doc_html_data.pcl
Machine information
Machine Name: DESKTOP-Q6RKU5O
Machine: linux
Processor Type: x86_64
Memory Available: -1
System Memory: -1
Machine Precision: 15.954589770191003
Connection Information
HTTP User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Remote User:
Remote Address: 127.0.0.1
Remote Host:

Workarounds

The desired result can be obtained with the following SymPy command: refine(sqrt(x**2), Q.positive(x))

Priority

Additional context

@mmatera
Copy link
Contributor

mmatera commented Sep 19, 2023

@fja-pedraza: indeed, something good would be to improve and enlarge the number of cases that Simplify and FullSymplify are able to handle.
Here:
sympy_result = sympy.simplify(sympy_expr, measure=complexity_function)

is where the call to Sympy.simplify is done. Maybe this routine could be improved to support more general cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants