First time here? Check out the FAQ!

Ask Your Question
1

assume() not playing well with solve_diophantine()

asked 1 year ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

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.

Preview: (hide)
link

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: 1 year ago

Seen: 266 times

Last updated: Sep 27 '23