boolean-logic

Test if value exists in several lists

笑着哭i 提交于 2019-12-07 07:25:13
问题 I would like to check if a value exists in every list. The following returns True as expected, but seems un-pythonic. What is the correct/more elegant way to do this? a = [1 ,2] b = [1, 3] c = [1, 4] d = [2, 5] False in [True if 1 in l else False for l in [a, b, c, d] ] 回答1: You can use all and a generator expression: all(1 in x for x in (a, b, c, d)) Demo: >>> a = [1 ,2] >>> b = [1, 3] >>> c = [1, 4] >>> d = [2, 5] >>> all(1 in x for x in (a, b, c, d)) False >>> all(1 in x for x in (a, b, c)

What do the logical functions IMP and EQV do in VB6? Has anyone found a real world use for them?

放肆的年华 提交于 2019-12-06 20:55:21
问题 And, Or, Xor and Not I understand. What I don't get are Imp and Eqv. What do they mean? How'd they get in there? Is there any real use for them? 回答1: IMP is "material implication" "a implies b" or "if a then b", which is equivalent to NOT a OR b. EQV is "equivalence" or "if and only if", so a EQV b is the same as (a IMP b) AND (b IMP a). They got there because someone wanted to be complete. They can shorten some logical expressions, but you can always express the same thing with NOT and AND,

How would you handle a special case in this digital logic system?

只愿长相守 提交于 2019-12-06 13:12:49
问题 I posted this digital logic diagram as an answer to another stackoverflow question. It describes a logic system which will be coded in Verilog or VHDL and eventually implemented in an FPGA. alt text http://img145.imageshack.us/img145/5125/bitshifterlogicdiagramkn7.jpg The numbered boxes in the diagram represent bits in a field. Each field has K bits, and the bits for current and mask will be provided by a computer system (using a latched register or equivalent). The bits in next will be read

How to use FINDSTR in PowerShell to find lines where all words in the search string match in any order

ε祈祈猫儿з 提交于 2019-12-06 06:50:00
问题 The following findstr.exe command almost does what I want, but not quite: findstr /s /i /c:"word1 word2 word3" *.abc I have used: /s for searching all subfolders. /c: Uses specified text as a literal search string /i Specifies that the search is not to be case-sensitive. *.abc Files of type abc. The above looks for word1 word2 word3 as a literal , and therefore only finds the words in that exact order . By contrast, I want all words to match individually , in any order (AND logic, conjunction

Simplify boolean expression i.t.o variable occurrence

自作多情 提交于 2019-12-05 20:08:49
How to simplify a given boolean expression with many variables (>10) so that the number of occurrences of each variable is minimized? In my scenario, the value of a variable has to be considered ephemeral, that is, has to recomputed for each access (while still being static of course). I therefor need to minimize the number of times a variable has to be evaluated before trying to solve the function. Consider the function f(A,B,C,D,E,F) = (ABC)+(ABCD)+(ABEF) Recursively using the distributive and absorption law one comes up with f'(A,B,C,E,F) = AB(C+(EF)) I'm now wondering if there is an

Kripke semantics: learning software available?

女生的网名这么多〃 提交于 2019-12-05 16:42:45
I am stuck on Kripke semantics , and wonder if there is educational software through which I can test equivalence of statements etc, since Im starting to think its easier to learn by example (even if on abstract variables). I will use ☐A to write necessarily A ♢A for possibly A do ☐true, ☐false, ♢true, ♢false evaluate to values, if so what values or kinds of values from what set ({true, false} or perhaps {necessary,possibly})? [1] I think I read all Kripke models use the duality axiom : (☐A)->(¬♢¬A) i.e. if its necessary to paytax then its not allowed to not paytax (irrespective of wheither

De Morgan's Law

烂漫一生 提交于 2019-12-05 10:55:13
I am trying to simplify the following using DeMorgan's Law: ! (x!=0 || y !=0) Does x!=0 simplify to x>0? Or am I wrong in the following: !(x>0 || y>0) !(x>0) && !(y>0) ((x<=0) && (y<=0)) Thanks. Alexis C. Does x!=0 simplify to x>0? No that's not true. Because integers are signed. How to simplify : !(x!=0 || y !=0) ? Consider this rules : (second De Morgan's laws ) By 1., it implies !(x!=0 || y !=0) <=> (!(x!=0)) && (!(y != 0)) By 2., it implies (!(x!=0)) && (!(y != 0)) <=> (x == 0) && (y == 0) To test you can write the following loop : for(int x = -5; x < 5; x++){ for(int y = -5; y < 5; y++){

Is it useful in C# to apply DeMorgan's theorem to manually optimize boolean expressions in conditional statements (e.g. if conditions)

送分小仙女□ 提交于 2019-12-05 01:55:48
Back in the day when I did most of my work in C and C++, as a matter of course, I would manually apply deMorgan's theorem to optimize any non-trivial boolean expressions. Is it useful to do this in C# or does the optimizer render this unnecessary? On processors this fast, it's virtually impossible for rearranging boolean expressions to make any actual difference in speed. And the C# compiler is very smart, it will optimize it as well. Optimize for readability and clarity! Your first goal should be to optimize such statements for developer comprehension and ease of maintenance. DeMorgan's

Simplify boolean expression algorithm

梦想与她 提交于 2019-12-04 23:43:07
Anybody knows of an algorithm to simplify boolean expressions? I remember the boolean algebra and Karnaught maps, but this is meant for digital hardware where EVERITHING is boolean. I would like something that takes into account that some sub-expressions are not boolean. For example: a == 1 && a == 3 this could be translated to a pure boolean expression: a1 && a3 but this is expression is irreducible, while with a little bit of knowledge of arithmetics everibody can determine that the expression is just: false Some body knows some links? You might be interested in K-maps and the Quine

Converting rgba values into one integer in Javascript

大兔子大兔子 提交于 2019-12-04 23:33:19
I can already convert 32bit integers into their rgba values like this: pixelData[i] = { red: pixelValue >> 24 & 0xFF, green: pixelValue >> 16 & 0xFF, blue: pixelValue >> 8 & 0xFF, alpha: pixelValue & 0xFF }; But I don't really know how to reverse it. To reverse it, you just have to combine the bytes into an integer. Simply use left-shift and add them, and it will work. var rgb = (red << 24) + (green << 16) + (blue << 8) + (alpha); Alternatively, to make it safer, you could first AND each of them with 0xFF: var r = red & 0xFF; var g = green & 0xFF; var b = blue & 0xFF; var a = alpha & 0xFF; var