Questions tagged [negation]

Negation is the logic operation that inverses a value, also seen as a NOT operation. Functions in specific languages may operate with negation to specific uses. For questions specific to the use of complement patterns in regular expressions, use [regex-negation] instead.

Negation is the logic operation that inverses a value, also seen as a NOT operation. Negation may be implemented by specific languages to provide functions capable of operating with values for specific uses.

Read also the wikipedia article on Negation.

248 questions
14
votes
4 answers

Prolog implying a negative predicate

How can I write the following rule in PROLOG: if P then not Q I understand that you can easily write if P then Q the predicates like q(X) :- p(X), but how can you negate the q/1 predicate? I don't want to define new predicates with other semantics…
Robert T.
  • 1,620
  • 2
  • 13
  • 20
14
votes
2 answers

Logical Negation in Prolog

I've read quite a bit about Prolog's Negation by Failure where Prolog in order to prove that \+Goal holds tries to prove that Goal fails. This is highly connected with CWA (close world assumption) where for example if we query \+P(a) (where P is a…
coder
  • 12,832
  • 5
  • 39
  • 53
13
votes
6 answers

Implementing logical negation with only bitwise operators (except !)

~ & ^ | + << >> are the only operations I can use Before I continue, this is a homework question, I've been stuck on this for a really long time. My original approach: I thought that !x could be done with two's complement and doing something with…
Jay
  • 131
  • 1
  • 1
  • 3
12
votes
1 answer

How does the NEG instruction affect the flags on x86?

The Intel Software Development Manual says this about the neg instruction: The CF flag set to 0 if the source operand is 0; otherwise it is set to 1. The OF, SF, ZF, AF, and PF flags are set according to the result. I thought that AF and CF would…
tbodt
  • 16,609
  • 6
  • 58
  • 83
11
votes
1 answer

Boolean "not equal to" in Lua (negation of a Boolean conditional)

How do I write an if statement in Lua that negates (inverts/flips) a Boolean variable used as the condition? For example, in Java, one can write: boolean a; a = false; if (!a) { //do something } I tried to replicate the above Java code in Lua…
Venkatesh
  • 3,558
  • 8
  • 32
  • 38
10
votes
1 answer

Negating typescript types?

I wanted to create a simple NOT operator in typescript where you get all primitives combined into the union of some type A that are NOT primitive members of the union of a second type B. This can be done using conditional types. For example, if you…
Magnus
  • 3,086
  • 2
  • 29
  • 51
10
votes
2 answers

Why double negation doesn't bind in Prolog

Say I have the following theory: a(X) :- \+ b(X). b(X) :- \+ c(X). c(a). It simply says true, which is of course correct, a(X) is true because there is no b(X) (with negation as finite failure). Since there is only a b(X) if there is no c(X) and…
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
8
votes
2 answers

perl6 Negating multiple words and permutations of their chars inside a regex

What is the best way to perform, inside a regex, negation of multiple words and permutations of chars that make up those words? For instance: I do not want "zero dollar" "roze dollar" "eroz dollar" "one dollar" "noe dollar" "oen dollar" but I do…
lisprogtor
  • 5,677
  • 11
  • 17
8
votes
1 answer

Is there a way to negate @media min/max-width/height?

I use http://www.w3.org/TR/css3-mediaqueries/ to have different design depending on the available viewport. In order for my search-and-replace to work, for every time I decide to adjust the cut-off points, I'd like to clearly negate @media…
cnst
  • 25,870
  • 6
  • 90
  • 122
8
votes
1 answer

swi-prolog negation

I've had a hard time searching for clear answers on negation in Prolog, so I apologize if this is an obvious question: I'm trying to write a simple code that will logically say that "X and Y love each other if X likes Y and only Y." My .pl code…
bjscollura
  • 93
  • 1
  • 7
7
votes
2 answers

jq: select when any value is in array

Given the input json [ {"title": "first line"}, {"title": "second line"}, {"title": "third line"} ] How can we extract only the titles that contain keywords that are listed in a second "filter" array. Using a shell variable here for…
Bernard
  • 16,149
  • 12
  • 63
  • 66
7
votes
3 answers

Why the linux kernel uses double logical negations instead of casts to bools?

Given that x is a variable of type int with the number 5 as its value, consider the following statement: int y = !!x; This is what I think it happens: x is implicitly casted to a bool and the first negation is executed, after that the last negation…
Garmekain
  • 664
  • 5
  • 18
6
votes
1 answer

Repeated negation (!) operators in bash do not negate each other

So this is more an oddity I've come up against than something I really want to use. But I found something I didn't understand with the bash extended test syntax. Check this out (included my shell version in case it matters): 34>$SHELL --version GNU…
Swandog
  • 71
  • 1
6
votes
3 answers

Negation of gsub | Replace everything except strings in a certain vector

I have a vector of strings: ve <- c("N","A","A","A","N","ANN","NA","NFNFNAA","23","N","A","NN", "parnot", "important", "notall") I want to keep only three possible values in this vector: N, A, and NA. Therefore, I want to replace any element that…
benett
  • 91
  • 8
6
votes
2 answers

Idiomatically negate a filter

What's the most idiomatic way of writing a filter with a negation? Example: is_even= lambda x : x % 2 == 0 odd_numbers= filter( lambda x: not is_even(x), range(10) ) Of course, you can just use list comprehensions - but then you needn't use filter…
loopbackbee
  • 21,962
  • 10
  • 62
  • 97
1
2
3
16 17