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 the fold_frac_powers and fold_short_frac flag to mathml printer #16075

Merged
merged 6 commits into from Mar 2, 2019
Merged

added the fold_frac_powers and fold_short_frac flag to mathml printer #16075

merged 6 commits into from Mar 2, 2019

Conversation

shubhamabhang77
Copy link
Contributor

@shubhamabhang77 shubhamabhang77 commented Feb 26, 2019

References to other Issues or PRs

Brief description of what is fixed or changed

  • Added the Fold_frac_powers and fold_short_frac flags to the mathml presentation printer

Other comments

Release Notes

  • printing

    • Added the Fold_frac_powers and fold_short_frac flags to the mathml presentation printer

@sympy-bot
Copy link

sympy-bot commented Feb 26, 2019

Hi, I am the SymPy bot (v142). 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:

  • printing
    • Added the Fold_frac_powers and fold_short_frac flags to the mathml presentation printer (#16075 by @shubhamabhang77)

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

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. -->

#### 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. -->


#### Brief description of what is fixed or changed

- Added the Fold_frac_powers and fold_short_frac flags to the mathml presentation printer

#### 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 -->
- printing 

    - Added the Fold_frac_powers and fold_short_frac flags to the mathml presentation printer
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@shubhamabhang77
Copy link
Contributor Author

I haven't added the test cases till now. Once all changes are made then I will add them.

@@ -554,6 +554,8 @@ def multiply(expr, mrow):
numer, denom = fraction(expr)
if denom is not S.One:
frac = self.dom.createElement('mfrac')
if self._settings["fold_short_frac"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should one make some sort of length test here? Or does one already know that the length is short?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right. I forgot it there.

x.appendChild(self._print(e.exp))
return x
if e.exp.is_negative:
if self._settings['fold_short_frac'] and len(str(e.base)) < 3:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please provide an example of MathML code generated from this part of the code? I cannot really figure out what it looks like (and when this happens).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In [3]: a= 1/(x)                                                                                                                                                                                                   

In [4]: print_mathml(a, printer='presentation', fold_short_frac=True)                                                                                                                                              
<mfrac bevelled="true">
	<mn>1</mn>
	<msup>
		<mrow>
			<mfenced>
				<mi>x</mi>
			</mfenced>
		</mrow>
		<mn>1</mn>
	</msup>
</mfrac> 

Is this how you want?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

I am not sure if this should happen or not. Well, this particular example shouldn't happen, but in general.

Here, you will need to check if the exponent is one and in that case not print the exponent, now it looks like
image

There is a method in another PR to check if there should be brackets around the expression, now maybe one could check if it e.base is Symbol and if it is not print the bracket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which PR is that to check for e.base is Symbol ? or to check for brackets?

Copy link
Contributor

Choose a reason for hiding this comment

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

The bracket check is actually merged. I didn't realize that (I have two outstanding PRs on this and I though it was in one of those). See #16069

I have also realized that the behavior of the MathML Rational is completely different to the LaTeX one, so as long as the 1-exponent is not printed I think this would be good to go for now. One can always come back and make it more like the LaTeX one if that is preferred.

@oscargus
Copy link
Contributor

I think it looks good! Just some minor comments for now. Please add some tests as it will be easier to see the effect of the change then.

@@ -554,6 +554,9 @@ def multiply(expr, mrow):
numer, denom = fraction(expr)
if denom is not S.One:
frac = self.dom.createElement('mfrac')
print(expr)
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh sorry. That was by mistake. It was just for testing purpose.

mrow.appendChild(self._print(e.base))
frac.appendChild(mrow)
return frac
if type(e.base) == symbol.Symbol:
Copy link
Contributor

Choose a reason for hiding this comment

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

I realized that you can do e.base.is_symbol (correct syntax would otherwise by e.base is Symbol).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh Yeah. It's working.

@shubhamabhang77
Copy link
Contributor Author

Can Anyone merge this PR? I want to make another PR.

@oscargus
Copy link
Contributor

oscargus commented Mar 2, 2019

I think the added functionality makes sense. A problem is that the original MathML printer is inconsistent with the LaTeX printer.

Hence, I merge this for now.

@shubhamabhang77 it makes sense to always start a new branch/PR/functionality from master, unless you are actually using some code from a previous PR. There may still be some issues with the other PR even after merging this.

@oscargus oscargus merged commit b786c99 into sympy:master Mar 2, 2019
@shubhamabhang77 shubhamabhang77 deleted the configuration_fold_frac_powers_and_fold_short_frac branch March 2, 2019 13:02
@shubhamabhang77
Copy link
Contributor Author

I think the added functionality makes sense. A problem is that the original MathML printer is inconsistent with the LaTeX printer.

Hence, I merge this for now.

@shubhamabhang77 it makes sense to always start a new branch/PR/functionality from master, unless you are actually using some code from a previous PR. There may still be some issues with the other PR even after merging this.

Tell me if there are any changes that has to be.

@oscargus
Copy link
Contributor

oscargus commented Mar 2, 2019

I wil try to prepare some things related to that now that the functionality is in. The main thing is really that the LaTeX and MathML presentation printers prints things like 1/y**2 differently. But that is really nothing that affects this PR.

@shubhamabhang77
Copy link
Contributor Author

I think the added functionality makes sense. A problem is that the original MathML printer is inconsistent with the LaTeX printer.

Hence, I merge this for now.

@shubhamabhang77 it makes sense to always start a new branch/PR/functionality from master, unless you are actually using some code from a previous PR. There may still be some issues with the other PR even after merging this.

I made another branch but I don't know what happened when I opened another PR, commits from PR was also listed there.

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.

None yet

4 participants