2
$\begingroup$

How can an equation like this be simplified in Mathematica where q,a,b,k are all natural numbers?

q = ((a*(b - 1))/ k) + (k - (Mod[(a*(b - 1)), k]))*(1/k)
$\endgroup$

1 Answer 1

6
$\begingroup$

Try with FullSimplify:

q = ((a*(b - 1))/ k) + (k - (Mod[(a*(b - 1)), k]))*(1/k);

FullSimplify[q]

(*1 + Floor[(a (-1 + b))/k]*)

Edit: thanks to the comments by @kirma and @Syed, here are the assumptions:

FullSimplify[q, (a | b | k) \[Element] PositiveIntegers]

(*1 + Floor[(a (-1 + b))/k]*)
$\endgroup$
6
  • 1
    $\begingroup$ This is simplification doesn't make domain assumptions on variables. It does produce the same result, but to exactly make the assumption that $a$, $b$ and $k$ are natural numbers (that is, non-zero integers) is to do something like FullSimplify[q, a != 0 && b != 0 && k != 0 && (a | b | k) \[Element] Integers]. $\endgroup$
    – kirma
    Feb 22, 2023 at 5:15
  • 3
    $\begingroup$ @kirma Can we use PositiveIntegers? $\endgroup$
    – Syed
    Feb 22, 2023 at 5:44
  • 3
    $\begingroup$ @Syed cough cough ... one shouldn't write comments right after waking up, especially on sick leave. I wonder where my "natural numbers are all integers except zero" idea came from. There's some ambiguity regarding inclusion of zero on natural numbers, but I guess PositiveIntegers is the most common interpretation. $\endgroup$
    – kirma
    Feb 22, 2023 at 7:03
  • $\begingroup$ Thanks, @Syed! :-) $\endgroup$ Feb 22, 2023 at 16:12
  • 1
    $\begingroup$ You are most welcome. @E.Chan-López $\endgroup$
    – Syed
    Feb 22, 2023 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.