Ask your own question, for FREE!
LaTeX Practicing! :) 19 Online
OpenStudy (unklerhaukus):

\[\large\underline{\textbf{Addition-Assignment}}\]

OpenStudy (unklerhaukus):

The `=` symbol in computer science is slightly different to the \(=\) symbol of mathematics. `=` represents the assignment operator, a (perhaps temporary) definition. In mathematics, assignment is often denoted with \(:=\). When a variable is to be reassigned to a value that is: the old value of the variable plus some additional term; \(x := x + a\) In computer science this is written as: `x = x + a`, or using a simpler syntax, (where `+=` denotes addition-assignment): `x += a`. \(\underline{\text{My question is:}}\) \(\textit{What is the best way to represent this addition-assignment in }\LaTeX\)? [I don't think \(x :+= a\) looks right at all]

Nnesha (nnesha):

\[\huge\color{green}{+=}\]:P

OpenStudy (unklerhaukus):

but, there is too much space between the chars

OpenStudy (unklerhaukus):

i want something more like:\[\large x:\!\!\!+\!\!\!=a\]

Nnesha (nnesha):

don't u like space between numbers variables :P

OpenStudy (unklerhaukus):

it should look like the addition-assignment is a single symbol

Nnesha (nnesha):

\(\large\color{green}{{\rm -=+}}\) is it right ? :D

OpenStudy (unklerhaukus):

no?

Nnesha (nnesha):

question mark lol okay

OpenStudy (unklerhaukus):

maybe \[\large x \operatorname{:\!\!\!+} a\]

OpenStudy (e.mccormick):

So use of negative space? \(\large x:\!\!\!+\!\!\!=a\) seems a bit tight. \(\large x:\!\!+\!\!=a\) One less on both sides. \(\large x:\!\!+\!\!\!=a\) One less on the left. \(\large x:\!\!\!+\!\!=a\) One left on the right.

Nnesha (nnesha):

first one looks right

OpenStudy (unklerhaukus):

\[x\operatorname{:\!\!+\!\!=}a\]\[x\operatorname{:\!\!-\!\!=}a\]\[x\operatorname{:\!\!\times\!\!=}a\]\[x\operatorname{:\!\!\div\!\!=}a\] hmmm

OpenStudy (unklerhaukus):

\[\boxed{ \newcommand \peq {\operatorname{\mathop{:=}^+}} % += addition assignment \newcommand \teq {\operatorname{\mathop{:=}^-}} % -= take-away assignment \newcommand \meq {\operatorname{\mathop{:=}^\times}}% *= multiplication assignment \newcommand \deq {\operatorname{\mathop{:=}^\div}} % /= division assignment }%unk\]\[ x := x+a\iff x\peq a\\[3ex] x := x-a\iff x\teq a\\[3ex] x := x\times a\iff x\meq a\\[3ex] x := x/a\iff x\deq a\]

OpenStudy (unklerhaukus):

So that: \[\texttt{x = x + 1}\\ \texttt{x += 1}\\ \texttt{x++}\] performs the mathematical operation: \[x:=x+1\\ x\peq 1\\ \newcommand \pp {\!+\!\!+} % ++ plus-plus x\pp\]

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!