Solving Modulo Arithmetic Problem with Variable Integer k

  • Thread starter Thread starter Mentallic
  • Start date Start date
  • Tags Tags
    Arithmetic
Click For Summary

Homework Help Overview

The discussion revolves around a modulo arithmetic problem involving a constant set of integers [m,n] with m>0, m≠n, and a variable integer k>0. The original poster seeks to define a function that outputs a specific value based on the product of k and successively increasing positive integers t, with conditions based on the interval [m,n].

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning

Approaches and Questions Raised

  • The original poster attempts to find a non-piecewise function to define the output process, while others clarify the meaning of the interval [m,n] and the conditions for t. There is also discussion on implementing the min function and absolute value without piecewise definitions.

Discussion Status

Participants are exploring various mathematical representations and functions related to the problem. Some guidance has been offered regarding the implementation of the min function and absolute value, but there is no explicit consensus on a non-piecewise solution yet.

Contextual Notes

The problem is framed within the context of a computing project, and there are considerations regarding the use of existing library functions for absolute value.

Mentallic
Homework Helper
Messages
3,802
Reaction score
95
I've stumbled across an arithmetic problem that's getting the better of me, so I need your help!

I have a constant set of integers [m,n], m>0, m\neq n and a variable integer k>0. If we multiply k by successively increasing positive integers t, we will eventually get kt > m. Now, what I want is the output to be kt if kt \in [m,n] and n if kt>n.

So for example, let's consider m = 45, n = 50 and k = 8.

We get the sequence 8, 16, 24, 32, 40, 48

At this point, we have a value larger or equal to m=45, and 48 < n=50 so the output is 48.

For k=11 we have
11, 22, 33, 44, 55

Since we now have a value larger than m, but the value is also larger than n, the output needs to be n=50.

So finally, my question is, can I create a function that isn't piecewise that defines this process? The piecewise function wasn't such a big deal,

$$
f(k,m,n) =
\begin{cases}
\Big\lceil \frac{m}{k} \Big\rceil k, & \text{if}\hspace{5 mm} \Big\lceil \frac{m}{k} \Big\rceil k < n \\ \\
n, & \text{if}\hspace{5 mm} \Big\lceil \frac{m}{k} \Big\rceil k \geq n
\end{cases}
$$


But I can't figure out how to produce a non-piecewise function.
 
Physics news on Phys.org
[m,n] means the interval from m to n?

So t is the smallest integer t such that kt >=m?

You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2, I think that should help.
 
mfb said:
[m,n] means the interval from m to n?

So t is the smallest integer t such that kt >=m?

Yes and yes. Sorry, I should have been more clear when defining my variables.

mfb said:
You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2, I think that should help.

That's perfect! Thanks mfb.
 
Mentallic said:
So finally, my question is, can I create a function that isn't piecewise that defines this process?

mfb said:
You can implement min(a,b) (the smaller value of a and b) as (|a+b|-|a-b|)/2.
Now a method to implement absolute value that isn't piecewise would be needed.
 
Last edited:
Good point, but this problem was actually for a computing project of mine and since the abs(x) function already exists as a library function, its piecewise definition isn't an issue.
 
For 32 bit signed two complement integers, and assuming the compiler does an arithmetic right shifts:

#define abs(a) ((a^(a>>31))+((a>>31)&1))
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
7
Views
4K
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K