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

printing: fix boolean operators in maple printing #26426

Merged
merged 2 commits into from
Mar 30, 2024

Conversation

voffch
Copy link
Contributor

@voffch voffch commented Mar 30, 2024

Maplesoft Maple uses and, or, not in its boolean expressions (see, e.g., its online help on this topic). However, Sympy's maple code printer outputted the default (incorrect) operators (&&, ||, !) from the base CodePrinter class. This simple fix overrides the operators in the MapleCodePrinter class with their correct values in accordance with the syntax of Maplesoft Maple. Now printing the boolean expressions and the Piecewise functions that include complex boolean expressions should produce correct Maple code.

Brief description of what is fixed or changed

The _operators dict with the correct boolean operators was added to the MapleCodePrinter class. The relevant tests were also corrected.

Release Notes

  • printing
    • fixed a bug in printing the boolean operators with the maple printer

Maplesoft Maple uses (and, or, not) in the boolean expressions.
However, Sympy's maple code printer outputted the default (incorrect)
operators (&&, ||, !) from the base CodePrinter class. This simple
fix overrides the operators in the MapleCodePrinter class with their
correct values in accordance with the syntax of Maplesoft Maple.
@sympy-bot
Copy link

sympy-bot commented Mar 30, 2024

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:

  • printing
    • fixed a bug in printing the boolean operators with the maple printer (#26426 by @voffch)

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.
Maplesoft Maple uses `and`,  `or`, `not` in its boolean expressions (see, e.g., its [online help](https://www.maplesoft.com/support/help/maple/view.aspx?path=boolean) on this topic). However, Sympy's maple code printer outputted the default (incorrect) operators (`&&`, `||`, `!`) from the base `CodePrinter` class. This simple fix overrides the operators in the `MapleCodePrinter` class with their correct values in accordance with the syntax of Maplesoft Maple. Now printing the boolean expressions and the Piecewise functions that include complex boolean expressions should produce correct Maple code.

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

The `_operators` dict with the correct boolean operators was added to the `MapleCodePrinter` class. The relevant tests were also corrected.

#### Release Notes

<!-- BEGIN RELEASE NOTES -->
* printing
  * fixed a bug in printing the boolean operators with the maple printer
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@voffch
Copy link
Contributor Author

voffch commented Mar 30, 2024

There's a "feature request" issue #17161 that I'd suggest should be closed. It feels strange to pull-request a bug fix for the feature that's already there but the relevant "feature request" issue is still, for some reason, open.

Copy link

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

| Change   | Before [a0551f77]    | After [d5819688]    |   Ratio | Benchmark (Parameter)                                                |
|----------|----------------------|---------------------|---------|----------------------------------------------------------------------|
| -        | 68.8±0.9ms           | 44.5±0.2ms          |    0.65 | integrate.TimeIntegrationRisch02.time_doit(10)                       |
| -        | 65.7±0.5ms           | 43.0±0.6ms          |    0.65 | integrate.TimeIntegrationRisch02.time_doit_risch(10)                 |
| +        | 18.3±0.2μs           | 29.7±0.1μs          |    1.62 | integrate.TimeIntegrationRisch03.time_doit(1)                        |
| -        | 5.29±0.04ms          | 2.86±0.01ms         |    0.54 | logic.LogicSuite.time_load_file                                      |
| -        | 72.7±0.3ms           | 28.8±0.1ms          |    0.4  | polys.TimeGCD_GaussInt.time_op(1, 'dense')                           |
| -        | 25.6±0.1ms           | 16.9±0.1ms          |    0.66 | polys.TimeGCD_GaussInt.time_op(1, 'expr')                            |
| -        | 73.3±0.3ms           | 28.7±0.1ms          |    0.39 | polys.TimeGCD_GaussInt.time_op(1, 'sparse')                          |
| -        | 256±2ms              | 125±1ms             |    0.49 | polys.TimeGCD_GaussInt.time_op(2, 'dense')                           |
| -        | 256±0.6ms            | 124±0.4ms           |    0.48 | polys.TimeGCD_GaussInt.time_op(2, 'sparse')                          |
| -        | 649±3ms              | 370±1ms             |    0.57 | polys.TimeGCD_GaussInt.time_op(3, 'dense')                           |
| -        | 655±5ms              | 372±1ms             |    0.57 | polys.TimeGCD_GaussInt.time_op(3, 'sparse')                          |
| -        | 493±2μs              | 286±0.9μs           |    0.58 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense')            |
| -        | 1.78±0.01ms          | 1.05±0.01ms         |    0.59 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense')            |
| -        | 5.79±0.03ms          | 3.07±0.04ms         |    0.53 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense')            |
| -        | 445±6μs              | 229±2μs             |    0.52 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense')               |
| -        | 1.45±0.01ms          | 672±6μs             |    0.46 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense')               |
| -        | 4.83±0.01ms          | 1.65±0.01ms         |    0.34 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense')               |
| -        | 376±3μs              | 205±0.7μs           |    0.55 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense')                |
| -        | 2.45±0.03ms          | 1.24±0.01ms         |    0.51 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense')                |
| -        | 10.1±0.05ms          | 4.32±0.03ms         |    0.43 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense')                |
| -        | 360±2μs              | 170±2μs             |    0.47 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense')            |
| -        | 2.50±0.01ms          | 913±7μs             |    0.37 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense')            |
| -        | 9.52±0.06ms          | 2.62±0.01ms         |    0.28 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense')            |
| -        | 1.04±0.01ms          | 425±1μs             |    0.41 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense')           |
| -        | 1.72±0.01ms          | 505±2μs             |    0.29 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse')          |
| -        | 5.88±0.03ms          | 1.79±0.01ms         |    0.3  | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense')           |
| -        | 8.42±0.02ms          | 1.47±0ms            |    0.17 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse')          |
| -        | 285±0.7μs            | 63.9±0.4μs          |    0.22 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse')             |
| -        | 3.41±0.03ms          | 395±3μs             |    0.12 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense')              |
| -        | 3.92±0.02ms          | 277±0.5μs           |    0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse')             |
| -        | 7.00±0.03ms          | 1.29±0.02ms         |    0.18 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense')              |
| -        | 8.62±0.04ms          | 825±4μs             |    0.1  | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse')             |
| -        | 4.95±0ms             | 2.97±0.01ms         |    0.6  | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| -        | 12.1±0.1ms           | 6.58±0.05ms         |    0.54 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense')  |
| -        | 22.4±0.08ms          | 8.95±0.05ms         |    0.4  | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| -        | 5.27±0.02ms          | 864±3μs             |    0.16 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse')    |
| -        | 12.5±0.1ms           | 6.97±0.02ms         |    0.56 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse')    |
| -        | 101±2ms              | 25.9±0.1ms          |    0.26 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense')     |
| -        | 166±1ms              | 53.2±0.2ms          |    0.32 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse')    |
| -        | 173±0.7μs            | 112±2μs             |    0.65 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'dense')      |
| -        | 355±4μs              | 216±2μs             |    0.61 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse')     |
| -        | 4.25±0.03ms          | 833±7μs             |    0.2  | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense')      |
| -        | 5.22±0.03ms          | 383±1μs             |    0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse')     |
| -        | 20.2±0.4ms           | 2.81±0.03ms         |    0.14 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense')      |
| -        | 22.6±0.2ms           | 621±1μs             |    0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse')     |
| -        | 484±3μs              | 135±0.7μs           |    0.28 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| -        | 4.66±0.01ms          | 609±2μs             |    0.13 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense')  |
| -        | 5.29±0.04ms          | 139±0.4μs           |    0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| -        | 13.0±0.08ms          | 1.27±0ms            |    0.1  | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense')  |
| -        | 14.0±0.1ms           | 142±0.8μs           |    0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| -        | 133±0.7μs            | 74.5±0.2μs          |    0.56 | solve.TimeMatrixOperations.time_rref(3, 0)                           |
| -        | 251±3μs              | 88.9±0.3μs          |    0.35 | solve.TimeMatrixOperations.time_rref(4, 0)                           |
| -        | 23.8±0.1ms           | 10.3±0.05ms         |    0.43 | solve.TimeSolveLinSys189x49.time_solve_lin_sys                       |
| -        | 28.1±0.2ms           | 15.3±0.07ms         |    0.54 | solve.TimeSparseSystem.time_linsolve_Aaug(20)                        |
| -        | 54.2±0.3ms           | 24.8±0.06ms         |    0.46 | solve.TimeSparseSystem.time_linsolve_Aaug(30)                        |
| -        | 27.8±0.2ms           | 15.1±0.07ms         |    0.54 | solve.TimeSparseSystem.time_linsolve_Ab(20)                          |
| -        | 54.4±0.2ms           | 24.5±0.2ms          |    0.45 | solve.TimeSparseSystem.time_linsolve_Ab(30)                          |

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@oscarbenjamin
Copy link
Collaborator

Looks good. Thanks!

@oscarbenjamin oscarbenjamin merged commit 73380d2 into sympy:master Mar 30, 2024
72 checks passed
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

3 participants