0
$\begingroup$

Let $x$ be an integer which can take a value of $0$ or $1$. The statement

if $(x = = 0) x = 1;$ else $x = 0;$

is equivalent to which one of the following ?

  1. $x = 1 + x;$
  2. $x = 1 - x;$
  3. $x = x - 1;$
  4. $x = 1\% x;$

My attempt :

It should be only option $(2)$ is true. but,

Can you explain little bit please, what is the value of $1\%0$ ?

AFAIK: It should be undefined, since it applied division $1/0$ which is undefined.

$\endgroup$
  • 1
    $\begingroup$ This sounds more like a programming question than a mathematics one. I suspect as code it would throw a run time error if you tried to do mod zero. $\endgroup$ – Ian Miller Nov 18 '15 at 13:36
  • 1
    $\begingroup$ Mathematicians tend not to use % as an operator, and we tend not to assign variables new values. This is a coding problem? The best definition would be that $a%0==a$ for all $a$, but who knows what it would be in the language at hand - depends precisely on the definition. $\endgroup$ – Thomas Andrews Nov 18 '15 at 13:36
  • $\begingroup$ You can find your answer over here - math.stackexchange.com/questions/516251/… $\endgroup$ – mihir Nov 18 '15 at 13:37
  • $\begingroup$ If you are talking about the C programming language, then the behaviour of 1%0 is undefined, see for example stackoverflow.com/questions/7370154/cant-mod-zero. That might be different for other programming languages. $\endgroup$ – Martin R Nov 18 '15 at 13:37
  • $\begingroup$ Mathematicians typically use = for equations, and indicate the assignment of a new value as := or a leftward pointing $\mapsto$ (not sure what the symbol for this is). In your case, since $x$ is boolean, the assignment can be written as $x := NOT x$ or $x := 1-x$, since the assignment inverts TRUE and FALSE. $\endgroup$ – Marconius Nov 19 '15 at 0:15
1
$\begingroup$

"$1\%0$" would be equivalent to $1-\Big\lfloor\frac10\Big\rfloor\times0$.

Modulo by $0$ is as meaningless as Division by $0$.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Is $\%$ operator dependents on division operator? $\endgroup$ – ً ً Nov 18 '15 at 13:49
  • $\begingroup$ @MithleshUpadhyay: Depends on what context (purely mathematical, C language standard, Python, CPU architecture, etc). Anyone can choose to "implement" it in anyway that they want, i.e., no one's "telling" how to do it, just as long as you do it correctly. $\endgroup$ – barak manos Nov 18 '15 at 13:53
  • $\begingroup$ Is $x = x\% 1$ is equivalent to $x = 1 - x$ ? $\endgroup$ – ً ً Nov 18 '15 at 13:58
  • $\begingroup$ @MithleshUpadhyay: $\forall{n\in\mathbb{Z}}:n\%1=0$. $\endgroup$ – barak manos Nov 18 '15 at 14:01
  • $\begingroup$ Yes, thanks for explanation. $\endgroup$ – ً ً Nov 18 '15 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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