boolean-expression

Why do I have to typecast an int in a ternary expression?

Possible Duplicate: Conditional operator cannot cast implicitly? I have run into a peculiar situation and want to know why I have to do it. I'm using .net 3.5. This works: short foo; if (isValid) foo = -1; else foo = getFoo(); This does not work: short foo; foo = isValid ? -1 : getFoo(); I have to typecast -1: ...

Python boolean expression and or

In python if you write something like foo==bar and spam or eggs python appears to return spam if the boolean statement is true and eggs otherwise. Could someone explain this behaviour? Why is the expression not being evaluated like one long boolean? Edit: Specifically, I'm trying to figure out the mechanism why 'spam' or 'eggs' is be...

How do I translate a simple boolean statement to SQL?

I have the following database table with information about people, diseases, and drugs: PERSON_T DISEASE_T DRUG_T ========= ========== ======== PERSON_ID DISEASE_ID DRUG_ID GENDER PERSON_ID PERSON_ID NAME DISEASE_ST...

c++ search text n boolean mode

Hi, basically have two questions. 1. Is there a c++ library that would do full text boolean search just like in mysql. E.g., Let's say I have: string text = "this is my phrase keywords test with boolean query."; string booleanQuery = "\"my phrase\" boolean -test -\"keywords test\" OR "; booleanQuery += "\"boolean search\" -mysql ...

SOLR AND+OR Query - how to do?

In Nutch I'm using Solr as a search server. I would like to perform something query like (hillary AND clinton) OR (barack AND obama) OR (..) How to do it? For me single OR query works, like india OR pakistan OR china query.AddNotRequiredTerm(term); single AND query works india AND paksitan AND China query.AddRequiredTerm(term); But...

XOR of three values

What is the simplest way to do a three-way exclusive OR? In other words, I have three values, and I want a statement that evaluates to true IFF only one of the three values is true. So far, this is what I've come up with: ((a ^ b) && (a ^ c) && !(b && c)) || ((b ^ a) && (b ^ c) && !(a && c)) || ((c ^ a) && (c ^ b) && !(a && b)) Is th...

Would Java interpret this boolean expression in the way I wanted it to?

This is what I want: !A || (A && B && C) Is this equivalent to the original? !A || A && B && C why or why not? ...

What is wrong with this if-elsif-else block in my Perl script?

I'm trying to write a condition for a nested if statement, but haven't found a good example of using or in if statements. The following elsif condition fails and allows the code nested beneath it to fire if $status == 6: if ($dt1 > $dt2 ) {do one thing} elsif(($status != 3) || ($status != 6)) { do something else} else {do something com...

"Boolean" operations in Python (ie: the and/or operators)

This method searches for the first group of word characters (ie: [a-zA-Z0-9_]), returning the first matched group or None in case of failure. def test(str): m = re.search(r'(\w+)', str) if m: return m.group(1) return None The same function can be rewritten as: def test2(str): m = re.search(r'(\w+)', str) r...

Why does Perl use the empty string to represent the boolean false value?

When evaluating an expression in a scalar (boolean) context, Perl uses the explicit value 1 as a result if the expression evaluates to true and the empty string if the expression evaluates to false. I'm curious why Perl uses the empty string to represent boolean false value and not 0 which seems more intuitive. Note that I'm not concern...

Can someone please help me with some basic boolean minimization ?

Hey guys, Sorry to be annoying, but I am doing a little bit of work at the moment, and am trying to simplify the following piece of boolean algebra so that I can construct the circuit : A'.B'.C.D + A'.B.C.D' + A'.B.C.D + A.B'.C'.D + A.B'.C.D + A.B.C'.D + A.B.C.D' + A.B.C.D So far I have gotten it to : (C.D) + (B.C) + (A....

binary to NAND gate - boolean algebra

I am taking a digital logic class and i am trying to multiply this binary number. I am not sure what a carry in is and a carrry out. the teachers slides are horrbile. It appears he used a truth table to do this but its confusing. X1X0 + Y1Y0 ---- Z2Z1Z0 I think thats how its set up! Now, for the multiplication part 1 ca...

boolean algebra - build a OR gate as an NAND gate

I am trying to wrap my mind around how to do this. For what i understand is that a set of logic gates is called "functionally complete" if some combination of the gates can be used to do each of the basic logic operations AND, OR, and NOT. The claim is the NAND gate is functionally complete. What i dont understand is how to build a OR g...

how to convert boolean expression to cnf file?

i need to use sat solver for checking satisfiability of boolean expressions.. I have complex boolean expression like this is there any automatic cnf file converter so that i can give it straight to sat solver? I read the cnf format file.. but how to express this expression in .cnf file? i get confused when there is a conjunction ins...

Digital Logic - truth tables

I am trying to solve these problems with truth tables using the formulas below. I am having a problem with the NOT to NAND I think i got the first 2 problems correct using: AND is equivalent to NOR, AND is equivalent to NAND The equations for AND, OR and NOT using the NAND operator are: X + Y = x' NAND y' ?? X * Y = X' = X NAND 1 ...

In C++, why does true && true || false && false = true?

I'd like to know if someone knows the way a compiler would interpret the following code: #include <iostream> using namespace std; int main() { cout << (true && true || false && false) << endl; // true } Is this true because && has a higher precedence than || or because || is a short-circuit operator (in other words, does a short cir...