← All challenges
mediumsympy/sympy · v1.4

Product pretty print could be improved

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to210 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

This is what the pretty printing for Product looks like:

>>> pprint(Product(1, (n, 1, oo)))
  ∞
┬───┬
│   │ 1
│   │
n = 1
>>> pprint(Product(1/n, (n, 1, oo)))
   ∞
┬──────┬
│      │ 1
│      │ ─
│      │ n
│      │
 n = 1
>>> pprint(Product(1/n**2, (n, 1, oo)))
    ∞
┬────────┬
│        │ 1
│        │ ──
│        │  2
│        │ n
│        │
  n = 1
>>> pprint(Product(1, (n, 1, oo)), use_unicode=False)
  oo
_____
|   | 1
|   |
n = 1
>>> pprint(Product(1/n, (n, 1, oo)), use_unicode=False)
   oo
________
|      | 1
|      | -
|      | n
|      |
 n = 1
>>> pprint(Product(1/n**2, (n, 1, oo)), use_unicode=False)
    oo
__________
|        | 1
|        | --
|        |  2
|        | n
|        |
  n = 1

(if those don't look good in your browser copy paste them into the terminal)

This could be improved:

  • Why is there always an empty line at the bottom of the ∏? Keeping everything below the horizontal line is good, but the bottom looks asymmetric, and it makes the ∏ bigger than it needs to be.
  • The ∏ is too fat IMO.
  • It might look better if we extended the top bar. I'm unsure about this.

Compare this

    ∞
─┬─────┬─
 │     │  1
 │     │  ──
 │     │   2
 │     │  n
  n = 1

That's still almost twice as wide as the equivalent Sum, but if you make it much skinnier it starts to look bad.

  ∞
 ____
 ╲
  ╲   1
   ╲  ──
   ╱   2
  ╱   n
 ╱
 ‾‾‾‾
n = 1
The environment starts at commit 41490b75f362 (sympy/sympy 1.4), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.