My Math Forum conditions without if statements

 Algebra Pre-Algebra and Basic Algebra Math Forum

 April 2nd, 2010, 11:43 AM #1 Newbie   Joined: Apr 2010 Posts: 1 Thanks: 0 conditions without if statements I have no idea where to post this, but it's something mathematical I've been wondering about, and found these forums. I recently ran into a situation where I wanted to represent a programming if-statement purely with math. In other words, write an equation to replace an if statement. For example: a = b + c if c > 0 After much tooling around, I found that using absolute values in a roundabout way would get me what I was looking for: a = b + .5(c + |c|) This works because if c is positive, it will be doubled then divided by 2 again to reach its original value. If c is negative, however, adding its absolute value will bring it to 0, negating its role in the equation. Thus it will only be added in this case if it's positive. As for my question: is there a formal name for this type of expression? Is it something common or just some convoluted crap I cooked up to satisfy the issue? Furthermore, if you're a programmer, is there even a situation where you'd want to do something like this instead of an if-statement anyway?
 April 2nd, 2010, 02:46 PM #2 Senior Member   Joined: Apr 2008 Posts: 435 Thanks: 0 Re: conditions without if statements I haven't seen this particular build before, and I don't think it has a name. When I have programmed, I have used addition mod2 as a sort of if-statement before, especially when I am thinking in terms of logic gates. That is the closest sort of expression I can think of.
 April 2nd, 2010, 06:46 PM #3 Member   Joined: Dec 2009 Posts: 66 Thanks: 0 Re: conditions without if statements When I programmed BASIC, before moving onto the eloquent and beautiful language of Java, I created my own sort of conditional statements. They weren't really for positive or negative numbers like your explaining, usually just the rounded down form in order to keep my expression as integers instead of gross decimals. (For example, $\cos(179)= -1$in my case). I don't even know if this can even be counted though, because the methods used to do this might have used If statements I don't think they really have a formal name. Don't seem to pose that much of a benefit either. Lone if statements (not a chain, or if-then-else, ect.) take up so little time for computation that there doesn't seem to be a real need for shortening them even further.
 April 3rd, 2010, 04:53 AM #4 Global Moderator   Joined: Dec 2006 Posts: 20,747 Thanks: 2133 There are situations where you might want to keep code short and avoid a conditional statement. For example, it may be convenient to use some weird-looking, but correct code. If someone else copies your code, you then have some evidence that they did so, as it's unlikely they'd independently devise precisely the same weird-looking code. Similarly, you might prefer brief (albeit odd-looking) code in a spreadsheet macro. Also, it may be convenient to use the same code in several places within a program. With some Fortran compilers, a special statement (which can include normal arithmetic but not an "if") is supported which defines a function within a routine to be used in that way within that routine only. Another example: some graphing calculators require the graph to be defined by an equation, without support for conditional statements.

 Tags conditions, statements

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post rhymin Applied Math 4 March 24th, 2013 11:20 AM layd33foxx Calculus 8 September 26th, 2011 01:14 PM jstarks4444 Applied Math 2 March 10th, 2011 02:00 PM r-soy Physics 1 December 26th, 2010 09:50 PM jstarks4444 Number Theory 2 December 31st, 1969 04:00 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top