Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

hope I spelled that right. Heard you take it in 3d game programming.

Also boolean algebra. Whats that about? In C++, type "bool" is a variable that only returns true or false. It does not hold a value.

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Discrete math is a compilation of different types of math. My discrete math started off with something like boolean algebra.

Boolean algebra allows you to reduce statements into simpler ones. For example:

Let a, b, and c be boolean.

(a and b) or (a and c) = a or (b and c), i.e. these two statements have the same truth values for any a, b, or c. If (a and b) or (a and c) is false, so is a or (b and c).

It also has rules for negations:

not (a and b) = (not a) or (not b)

In programming, it makes writing if statements much more clear.

Discrete math, for me, went from boolean algebra, to proofs (forward, contrapositive, contradiction, and induction), to sets, operations, and functions.

The only application for discrete math in programming is function analysis, i.e. seeing how long a piece of code would take to run.

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Interesting. Thanks for the description.

A logarithm is just a misspelled algorithm.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,559

mikau wrote:

It does not hold a value.

Ah, but it does! It holds a binary value, the basis of life as we know it.

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

In C++, type "bool" is a variable that only returns true or false. It does not hold a value.

Little known fact, most compilers have a bool as 8 bits, even though only one is needed.

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Yeah I meant it doesn't store a numerical value for the user.

Why the heck is it 8 bits on some compilers? I thought the purpose was to save memory for switch variables. Peculiar...

A logarithm is just a misspelled algorithm.

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

Does boolean algebra have a distributive property?

For example, I often wish I could say: a == (b or c or d)

instead of: (a == b) or (a == c) or (a == d)

...but the first form doesn't work.

El que pega primero pega dos veces.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

like in C++?

*Last edited by mikau (2006-02-01 10:34:52)*

A logarithm is just a misspelled algorithm.

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

Well, PHP. I've never written a line of C++, and hope I never have to.

El que pega primero pega dos veces.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Its not that hard to use once you know it. But it can very hard to learn sometimes.

A logarithm is just a misspelled algorithm.

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Does boolean algebra have a distributive property?

For example, I often wish I could say: a == (b or c or d)

instead of: (a == b) or (a == c) or (a == d)

...but the first form doesn't work.

Not quite. There is no equality in boolean algebra. Instead, each variable is either true or false.

So for your example, if you had:

a and (b or c or d)

the equivalent would be:

(a and b) or (a and c) or (a and d)

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

Why the heck is it 8 bits on some compilers? I thought the purpose was to save memory for switch variables. Peculiar...

This is a bit of a complex question (pun intended). Computers run much faster if all data is stored in whole bytes. To understand why, you need to understand the underlying architecture, which would take me a while to describe.

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

Heh, I think exactly opposite. My first programming language was C at age 13. My first OOP language was Java at age 18. Both were very easy to learn, but using Java is *much easier.* This is mainly due to Java's memory handling and extensive API. And after using a language that abstracts strings, I just can't bring myself to use a language that doesn't (of course, I'm sure people have abstracted strings tons of times in C++, but I doubt it's as slick as native support).

I'm starting to learn Ruby, which is supposedly nice enough to make PHP blush with shame.

El que pega primero pega dos veces.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

Well in the case of C++, there are I believe three logical operators, And "&&" Or, "||" and Not "!"

Really an if statement returns true if the statement is true, and false if the statement is false, but you can use simple values instead of relational opererators such as ==, >, <, etc. A variable with a value of zero evaluates false. All others evaluate true.

If for instance you were to say:

if(5) { statement; }

it will evaluate true and always will since 5 does not equal zero, and the statement will be excecuted.

if(0) { statement; }

this will not be executed. Zero returns false.

When you use the logical operators, you can use the "or" and "and" operaters to execute a statement if either, or only if both are true.

you could say

if(0 || 1) { statement; }

that would return true. ( "||" means or)

if (0 && 1) { statement; }

that would not return true since both must be true.

But when you say if ( x == (5 || 7)) { statement;}

I believe this is incorrect use of the or operator. The or operator is used between two expressions that are evaluated for their truth or falsity. Not their value.

A logarithm is just a misspelled algorithm.

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

OK. Too right. I still wish their were a language construct for compacting conditions wherein a variable could equal one of several things that trigger the condition.

El que pega primero pega dos veces.

Offline

**mikau****Member**- Registered: 2005-08-22
- Posts: 1,504

maybe there is. Many computer languages hold secret techniques only known by the ninja's.

A logarithm is just a misspelled algorithm.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,559

ryos wrote:

OK. Too right. I still wish their were a language construct for compacting conditions wherein a variable could equal one of several things that trigger the condition.

Isn't that the "select" statement (aso called "case" or "switch") ?

Example (Visual Basic code to replace any non-alphanumeric with "_"):

```
Select Case c
Case "a" To "z", "A" To "Z", "0" To "9"
Mid$(x, i, 1) = c
Case Else
Mid$(x, i, 1) = "_"
End Select
```

I chose VB because it has such a rich case statement, PHP can only have one value per "case":

```
switch ($MatchType) {
case "=":
$s .= $MatchVar . "=" . $MatchVal;
break;
case "Like":
$s .= $MatchVar . ' like "%' . $MatchVal . '%"';
break;
default:
$s .= $MatchVar . $MatchVal; break;
}
```

But PHP, like C, will continue to run statements below it without the "break;", so this can be used to put several "case" statments in sequence:

```
switch ($MatchType) {
case "=":
case "equal":
case "same":
$s .= $MatchVar . "=" . $MatchVal;
break;
case "Like":
$s .= $MatchVar . ' like "%' . $MatchVal . '%"';
break;
default:
$s .= $MatchVar . $MatchVal; break;
}
```

But there is a trick in PHP: use switch (TRUE) and then the "case"s can be conditions like "($x >5)" or "in_array()" etc.

Sorry, didn't mean to ramble on.

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

Hmm...case true eh? Pretty slick. I had thought of the rollover switch, but it seems like using a sledgehammer to open a can. Almost easier to just use a knife. But what I really need is a can opener...

El que pega primero pega dos veces.

Offline

**MathsIsFun****Administrator**- Registered: 2005-01-21
- Posts: 7,559

```
canopener ($problem) {
$result = solved;
}
```

"The physicists defer only to mathematicians, and the mathematicians defer only to God ..." - Leon M. Lederman

Offline

**ryos****Member**- Registered: 2005-08-04
- Posts: 394

```
<?php
function canOpener ($can) {
$canOpened = false;
$args = func_get_args();
unset ($args[0]); //that's $can; we have that one
foreach ($args as $compareTo) {
if ($can == $compareTo) { $canOpened = true; }
}
return $canOpened;
}
?>
```

El que pega primero pega dos veces.

Offline

**John E. Franklin****Member**- Registered: 2005-08-29
- Posts: 3,585

Also on the topic of discrete math for electronics is Karnaugh mapping created in 1950's.

And Logic Circuit Minimization.

**igloo** **myrtilles** **fourmis**

Offline

Pages: **1**