Ask Your Question
1

assume() not playing well with solve_diophantine()

asked 2023-09-24 23:22:01 +0100

Eric Snyder gravatar image

Simple code:

var('n k')
assume(n > 0)
assume(k > 0)
assume(n > k)

eqn = n^2 - (k^2 + k) == 30
print(solve_diophantine(eqn, (n,k)))

This outputs:

[(30, -30), (-6, 2), (-6, -3), (6, 2), (6, -3), (-30, 29), (-30, -30), (30, 29)]

which contains solutions where each of the assumptions is skipped (including at least one where all three assumptions are not met). Can anyone help explain what might be happening here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-09-27 11:49:41 +0100

rburing gravatar image

The explanation is that solve_diophantine simply calls sympy's diophantine, which ignores all assumptions.

So you will have to filter manually:

sage: var('n,k')
sage: eqn = n^2 - (k^2 + k) == 30
sage: [(n0, k0) for (n0, k0) in solve_diophantine(eqn, (n,k)) if n0 > 0 and k0 > 0 and n0 > k0]
[(6, 2), (30, 29)]

Filtering could be added as a post-processing step in solve_diophantine, so you could open an issue for that.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-09-24 23:22:01 +0100

Seen: 212 times

Last updated: Sep 27 '23