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

Added assumptions in Dynamicsymbols #18061

Merged
merged 13 commits into from
Dec 20, 2019
Merged

Added assumptions in Dynamicsymbols #18061

merged 13 commits into from
Dec 20, 2019

Conversation

Smit-create
Copy link
Member

@Smit-create Smit-create commented Dec 17, 2019

Added assumptions to dynamicsymbols

References to other Issues or PRs

Fixes #17739

Brief description of what is fixed or changed

Added assumptions in dynamicsymbols so it can be positive, real, etc.

Other comments

Release Notes

  • physics.vector
    • Added assumptions to dynamicsymbols
    • Added test for dynamicsymbols

@sympy-bot
Copy link

sympy-bot commented Dec 17, 2019

Hi, I am the SymPy bot (v149). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
Added assumptions to dynamicsymbols
#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes#17739

#### Brief description of what is fixed or changed
Added assumptions in dynamicsymbols so it can be positive, real, etc.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.vector
   * Added assumptions to dynamicsymbols
   * Added test for dynamicsymbols
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@moorepants
Copy link
Member

@Smit-create Thanks for this PR. Can you add a unit test?

@moorepants
Copy link
Member

You also need to add release notes for this.

@Smit-create
Copy link
Member Author

@moorepants Yes I will add both the things.

@moorepants
Copy link
Member

On last note: Please add some documentation in the docstring showing how to add assumptions.

@Smit-create
Copy link
Member Author

@moorepants Surely, I will add that too.

@codecov
Copy link

codecov bot commented Dec 17, 2019

Codecov Report

Merging #18061 into master will increase coverage by 0.029%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##            master    #18061       +/-   ##
=============================================
+ Coverage   74.864%   74.894%   +0.029%     
=============================================
  Files          640       641        +1     
  Lines       166548    166564       +16     
  Branches     39176     39179        +3     
=============================================
+ Hits        124686    124747       +61     
+ Misses       36343     36298       -45     
  Partials      5519      5519

>>> q3= dynamicsymbols('q3', positive=True)
q3(t)
>>> q3.is_positive
True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Also add a note in the Parameters section explaining what **asumptions is. You can reference the symbols() or Symbol() documentation.

f3=dynamicsymbols('f3',positive=True)
assert f1.is_real==None
assert f2.is_real
assert f3.is_positive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces around the equals and after commas, as per PEP8.

f1=dynamicsymbols('f1')
f2=dynamicsymbols('f2',real=True)
f3=dynamicsymbols('f3',positive=True)
assert f1.is_real==None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be is None.

@Smit-create
Copy link
Member Author

@moorepants Surely I will do the requires changes. Thanks for reviewing.

@moorepants
Copy link
Member

In the release notes, only add one bullet "added assumptions to dynamicsymbols" and the header should be "physics" not "physics.vector" (I think).

@Smit-create
Copy link
Member Author

In the release notes, only add one bullet "added assumptions to dynamicsymbols" and the header should be "physics" not "physics.vector" (I think).

I metioned it physics at first, but it showed be error. So, I changed it to physics.vector

@moorepants
Copy link
Member

I metioned it physics at first, but it showed be error. So, I changed it to physics.vector

Ok, I thought the comment should have a green checkmark, so I was confused. it is fine.

@@ -587,20 +587,33 @@ def dynamicsymbols(names, level=0):
level : int
Level of differentiation of the returned function; d/dt once of t,
twice of t, etc.
Assumptions :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@@ -587,20 +587,33 @@ def dynamicsymbols(names, level=0):
level : int
Level of differentiation of the returned function; d/dt once of t,
twice of t, etc.
Assumptions :
real = False
positive = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say something like "Key-value pairs of assumptions, see symbols for more information". You should read this: https://docs.sympy.org/dev/documentation-style-guide.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I have referred it from class Symbol, and it had similar kind to explanation of assumption

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that sounds like Symbol's docstring is poor then and we should make it better here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Uses symbols and Function for functions of time.

    Creates a SymPy UndefinedFunction, which is then initialized as a function
    of a variable, the default being Symbol('t').

    Parameters
    ==========

    names : str
        Names of the dynamic symbols you want to create; works the same way as
        inputs to symbols
    level : int
        Level of differentiation of the returned function; d/dt once of t,
        twice of t, etc.
    assumptions :
        real(bool) : This is used to set the dynamicsymbol as real, by default is False
        positive(bool) : This is used to set the dynamicsymbol as positive, by default is False
        commutative(bool) : This is used to set the commutative property of a dynamicsymbol, by default is True
        integer(bool) : This is used to set the dynamicsymbol as integer , by default is False

    Examples
    ========

    >>> from sympy.physics.vector import dynamicsymbols
    >>> from sympy import diff, Symbol, sqrt
    >>> q1 = dynamicsymbols('q1')
    >>> q1
    q1(t)
    >>> q2 = dynamicsymbols('q2', real=True)
    >>> q2.is_real
    True
    >>> q3 = dynamicsymbols('q3', positive=True)
    >>> q3.is_positive
    True
    >>> q4, q5 = dynamicsymbols('q4,q5', commutative=False)
    >>> bool(q4*q5 != q5*q4)
    True
    >>> q6 = dynamicsymbols('q6', integer=True)
    >>> q6.is_integer
    True
    >>> diff(q1, Symbol('t'))
    Derivative(q1(t), t)

    """

Is this the correct way to document?


Examples
========

>>> from sympy.physics.vector import dynamicsymbols
>>> from sympy import diff, Symbol
>>> from sympy import diff, Symbol, sqrt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the sqrt for?

@moorepants
Copy link
Member

Remove the sqrt and I think this is good to go after that. Thanks for the contribution.

@Smit-create
Copy link
Member Author

Remove the sqrt and I think this is good to go after that. Thanks for the contribution.

Yes, it was completely out of my notice

@Smit-create
Copy link
Member Author

Remove the sqrt and I think this is good to go after that. Thanks for the contribution.

Thanks for the help provided, as it was my first contribution I made some silly mistakes but will surely not repeat next time. Thanks for your guidance

real(bool) : This is used to set the dynamicsymbol as real, by default is False
positive(bool) : This is used to set the dynamicsymbol as positive, by default is False
commutative(bool) : This is used to set the commutative property of a dynamicsymbol, by default is True
integer(bool) : This is used to set the dynamicsymbol as integer , by default is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not render correctly when converted to HTML for the documentation. I think it will all be treated as one line. You may need to use a list like:

- thing 1
- thing 2

Also wrap the lines at 79 characters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        * real(bool) : This is used to set the dynamicsymbol as real, by default is False
        * positive(bool) : This is used to set the dynamicsymbol as positive, by default is False
        * commutative(bool) : This is used to set the commutative property of a dynamicsymbol,
                               by default is True
        * integer(bool) : This is used to set the dynamicsymbol as integer , by default is False

You mean this way should I write?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think you should check that it renders correctly by building the docs locally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have made the required changes and wrapped the lines to 79 characters

@moorepants
Copy link
Member

One more likely issue. You can build the docs locally to check if it renders correctly.

@Smit-create
Copy link
Member Author

@moorepants I am making the required changes in physics.vector.functions.py but it is showing error in sympy.utilities.lambdify.lambdify though I haven't made any changes there.

@Smit-create
Copy link
Member Author

@moorepants I am making the required changes in physics.vector.functions.py but it is showing error in sympy.utilities.lambdify.lambdify though I haven't made any changes there.

________________________________________________________________________________
______________________ sympy.utilities.lambdify.lambdify _______________________
File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/sympy-1.6.dev0-py3.6.egg/sympy/utilities/lambdify.py", line 402, in sympy.utilities.lambdify.lambdify
Failed example:
    f.__globals__['sin']
Expected:
    <ufunc 'sin'>
Got:
    <function _deprecated.<locals>.wrap.<locals>.call at 0x7fdecc2ec9d8>
**********************************************************************
File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/sympy-1.6.dev0-py3.6.egg/sympy/utilities/lambdify.py", line 404, in sympy.utilities.lambdify.lambdify
Failed example:
    f.__globals__['cos']
Expected:
    <ufunc 'cos'>
Got:
    <function _deprecated.<locals>.wrap.<locals>.call at 0x7fdecc361510>
**********************************************************************
File "/home/travis/miniconda/envs/test-environment/lib/python3.6/site-packages/sympy-1.6.dev0-py3.6.egg/sympy/utilities/lambdify.py", line 406, in sympy.utilities.lambdify.lambdify
Failed example:
    f.__globals__['sin'] is numpy.sin
Expected:
    True
Got:
    False
===== tests finished: 3689 passed, 1 failed, 2 skipped, in 278.00 seconds ======

@moorepants
Copy link
Member

There are unrelated test failures.

@Smit-create
Copy link
Member Author

Then what I did is correct?

@moorepants
Copy link
Member

Yes, I think it is good.

@Smit-create
Copy link
Member Author

Yes, I think it is good.

So will it get merged?

@moorepants
Copy link
Member

Once the tests are fixed it will.

@Smit-create
Copy link
Member Author

Yes, I think it is good.

Once the tests are fixed it will.

But they are failing unrelated test. So do I need to do anything for fixing them?

@moorepants
Copy link
Member

But they are failing unrelated test. So do I need to do anything for fixing them?

Wait on #18080 to get merged and then you'll need to merge in the master branch here.

@Smit-create
Copy link
Member Author

Is it good to go now?

@moorepants
Copy link
Member

Yes! Thank you for the contribution.

@moorepants moorepants merged commit fbf5089 into sympy:master Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dynamicsymbols needs to accept assumptions
4 participants