# Mod(x,y) ?

### #1

Posted 19 April 2005 - 07:41 AM

If i use it with numbers it works fine

(e.g. mod(5,2)=1)

but if i try to use it with variables it behaves very strange

e.g.

mod(x,y) gives x as result

although x and y are both undefined (they have no value)

I found this when trying to use mod in a while construction in my program that calculates a mod function. It gives very strange results.

Does anyone know whats wrong with it?

thanks

### #2

Posted 19 April 2005 - 09:10 AM

it would make more sense to output an error in my opinion......

### #3 Guest_Guest_masterjoda800_*_*

Posted 19 April 2005 - 01:54 PM

Well sure, thats right.

But try the following:

In Graph/Table Menu insert the following function:

y1=mod(x,5)

then let the classpad create a table thats starts with 0 and ends with 12 or 13 ore something like that

it creates a table that looks like this:

x | y1

--+----

0 | 0

1 | 1

2 | 2

3 | 3

4 | 4

5 | 5

6 | 6

7 | 7

8 | 8

9 | 9

10 | 10

11 | 11

but thats not correct. It normaly schould calculate a table that looks like that:

x | y1

--+----

0 | 0

1 | 1

2 | 2

3 | 3

4 | 4

5 | 0

6 | 1

7 | 2

8 | 3

9 | 4

10 | 0

11 | 1

so whats wrong?

### #4

Posted 19 April 2005 - 06:23 PM

### #5

Posted 19 April 2005 - 11:08 PM

mod(x,y) gives x as result

Does anyone know whats wrong with it?

It is doing a polynomial "mod". Try mod(x^2+4*x+3,x^2+3*x+2) and you'll see what I mean

### #6 Guest_Guest_masterjoda800_*_*

Posted 20 April 2005 - 10:17 AM

sorry, but i cant follow you

### #7

Posted 20 April 2005 - 03:57 PM

If, on the other hand, you want to use a variable as a placeholder, it is a very bad feature....mod(x,5) 5

What it is doing in the graph/table is correct, but not expected. It is doing a polynomial "mod" when what you want is a numeric "mod" where "x" is a placeholder.

The graph and table application pre-evaluates the expression to speed things up. As an example, a complicated integral will graph much faster if it is pre-evaluated and reduced before graphing. In

*this*case though, it is "pre-evaluating" "mod(x,5)" and getting "x".

NOTE: The same problem exists with the "gcd" function.

### #8 Guest_Guest_mkanter_*_*

Posted 22 April 2005 - 10:06 AM

Well it is a bug, and it isn't.... "mod" will give a result with variables because it is doing a polynomial "mod". For the following case where you've entered to polynomials it is a very nice feature...mod(x^2+4*x+3,x^2+3*x+2) x+1

If, on the other hand, you want to use a variable as a placeholder, it is a very bad feature....mod(x,5) 5

What it is doing in the graph/table is correct, but not expected. It is doing a polynomial "mod" when what you want is a numeric "mod" where "x" is a placeholder.

The graph and table application pre-evaluates the expression to speed things up. As an example, a complicated integral will graph much faster if it is pre-evaluated and reduced before graphing. Inthiscase though, it is "pre-evaluating" "mod(x,5)" and getting "x".

NOTE: The same problem exists with the "gcd" function.

but then it should give some conditions on the solution like:

mod(x, 5) =

x | 0<= x < 5

I think the solution of the example above may be wrong too, if you will insert some big or small x (to met not the not given conditions of solution)

### #9

Posted 22 May 2005 - 09:43 PM

Define moda(x,y)=simplify(x-y*int(x/y))

Define modap(x,y)=simplify(x-y*intg(x/y))

seq(moda(x,3),x,-5,5,1)

seq(modap(x,3),x,-5,5,1)

Difference is in negative x values.

Best regards,

Lianna

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users