|
||
|
|
#26 (permalink) | |
|
Forum Newbie
Join Date: Jun 2005
Age: 31
Posts: 45
|
Quote:
First statement was: x == (y || z) They wanted to replace it with: x == y || x == z [b]I say that it's incorrect, becouse these two statements are mathe,atically inequal, and in some conditions they give different results.[b] The correct mathematical replacement is this: (x & (y || z)) || (!x & (!y & !z)) Here is the proof - binary table for all cases. x y z x == (y || z) x == y || x == z x & (y || z)] || [!x & (!y & !z) 0 0 0 1 1 1 0 1 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 So, as you can see, in case of 0|1|1 or 1|0|0 x==y||x==z gives incorrect result, and that is the thing that i originally wanted to point out. Here is the c# script to test all cases: (replace x,y,z with true|false as required) using System; namespace Test { public class MainApp { public static void Main() { bool x = true; bool y = true; bool z = true; Console.WriteLine(x == (y || z)); Console.WriteLine(x == y || x == z); Console.WriteLine((x & (y || z)) || (!x & (!y & !z))); Console.WriteLine("--ende--"); Console.Read(); } } } Last edited by yarex; 05-08-2006 at 08:22 AM. |
|
|
|
|
|
|
#27 (permalink) | |
|
Forum Expert
|
Quote:
I also noticed small mistake in your code Code:
Console.WriteLine((x & (y || z)) || (!x & (!y & !z))); Back to the topic... For comparation like X==(y||z ... ||n) you could use following method but it obvoiusly has its flaws on the preformance. Code:
public static bool RefsEquals ( object o, params object[] objs )
{
for ( int i = 0; i < objs.Length; i++ )
{
if ( o == objs[i] ) { return(true); }
}
return(false);
}
Code:
if ( RefsEquals ( x, y, z ) ) ....
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell! Last edited by arul; 05-08-2006 at 06:51 PM. |
|
|
|
|
|
|
#28 (permalink) | |
|
Forum Expert
|
Quote:
Last edited by Sep102; 05-08-2006 at 06:58 PM. |
|
|
|
|
|
|
#29 (permalink) | ||
|
Forum Expert
|
Quote:
Quote:
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell! |
||
|
|
|
|
|
#30 (permalink) | |
|
Forum Expert
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|