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

Add new java printer #26522

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

stephweissm
Copy link

References to other Issues or PRs

Brief description of what is fixed or changed

JavaScript looks supported. But there is no printer for Java.

Other comments

Release Notes

  • printing
    • Code printer for Java

@sympy-bot
Copy link

Hi, I am the SymPy bot. 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.13.

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://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
JavaScript looks supported. But there is no printer for Java.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

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
  * Code printer for Java
<!-- END RELEASE NOTES -->

@sympy-bot
Copy link

sympy-bot commented Apr 20, 2024

🟠

Hi, I am the SymPy bot. I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it.

This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75.

The following commits add new files:

  • 04e23cf:
    • sympy/printing/java.py
  • 2f27c1b:
    • sympy/printing/tests/test_java.py

If these files were added/deleted on purpose, you can ignore this message.

class JavascriptCodePrinter(CodePrinter):
class AbstractJavaFamilyPrinter(CodePrinter):

def _print_Pow(self, expr):
Copy link
Member

Choose a reason for hiding this comment

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

Is this the only thing they have in common or is there more coming? It doesn't seem worth having a shard superclass for just one method.

@sylee957
Copy link
Member

Generally, Java and Javascript is not very common, shares nothing common in history, and maintained by different entities (Oracle and W3C),
and does not share much things in common, so it may not be a good idea to create superclass printers.

I think that you need to add comprehensive test cases. It's hard to believe that it can generate generally correct code for Java, unless we can read the outputs.

@bjodah
Copy link
Member

bjodah commented Apr 23, 2024

I think it is wise to reuse the names of the math functions (which are the same between Javascript and Java I believe). It does not need to use a subclass (and it doesn't look like it's an abstract one? so that would need to be renamed anyhow).

And yes, I think more tests are needed. Did you try to get the tests in test_algorithms to pass? (the choice of supported math functions lead me to believe that):

def test_newtons_method_function__rtol_cse_nan():

If so, it would be great if we could test a full java compilation & execution on the CI-server (we already do this for C).
I see that some math functions are still missing, perhaps we should add those too? log1p comes to mind.

We could duplicate the _print_Pow method, but I would be curious to see if we could even move that into codeprinter.py instead, and rely on e.g. _print_Cbrt returning NotImplemented (but I think that should be a separate PR later in that case).

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

Successfully merging this pull request may close these issues.

None yet

6 participants