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.

210 questions
304
votes
2 answers

How to filter an array of objects based on values in an inner array with jq?

Given this input: [ { "Id": "cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b", "Names": [ "condescending_jones", "loving_hoover" ] }, { "Id":…
Abe Voelker
  • 25,576
  • 13
  • 76
  • 95
182
votes
4 answers

Negation in Python

I'm trying to create a directory if the path doesn't exist, but the ! (not) operator doesn't work. I'm not sure how to negate in Python... What's the correct way to do this? if (!os.path.exists("/usr/share/sounds/blues")): proc =…
David Mulder
  • 6,276
  • 10
  • 40
  • 59
139
votes
12 answers

Does any language have a unary boolean toggle operator?

So this is more of a theoretical question. C++ and languages (in)directly based on it (Java, C#, PHP) have shortcut operators for assigning the result of most binary operators to the first operand, such as a += 3; // for a = a + 3 a *= 3; // for…
CompuChip
  • 8,186
  • 4
  • 20
  • 45
67
votes
1 answer

Including bean definition when a profile is NOT active

In my application I use several profiles to make certain beans eligible for autowiring. What I'm missing is the possibility to make a bean eligible for autowiring when a certain profile is NOT active. The best way of doing it that I thought about…
ShyJ
  • 4,340
  • 1
  • 17
  • 19
59
votes
2 answers

how to pass a not like operator in a sqlalchemy ORM query

I've got a query: MyModel.query.filter(Mymodel.name.contains('a_string')) I need to do the same query but with the negation (a not like operator) but didn't find any operator matching my need in the SQLAlchemy documentation. Is there any way to…
Jérôme Pigeot
  • 1,851
  • 3
  • 19
  • 24
55
votes
9 answers

Why use abs() or fabs() instead of conditional negation?

In C/C++, why should one use abs() or fabs() to find the absolute value of a variable without using the following code? int absoluteValue = value < 0 ? -value : value; Does it have something to do with fewer instructions at lower level?
Subhranil
  • 821
  • 1
  • 8
  • 21
41
votes
4 answers

Negation of %in% in R

Is there a short negation of %in% in R like !%in% or %!in%? Of course I can negate c("A", "B") %in% c("B", "C") by !(c("A", "B") %in% c("B", "C")) (cf. this question) but I would prefere a more straight forward approach and save a pair of brackets…
Qaswed
  • 2,629
  • 4
  • 21
  • 38
36
votes
3 answers

Django query negation

I know how to build filters and Q objects in django, but I don't know how to negate the operators that the API provides, for example for the contains operator I would like something like notcontains. e.g. q=Q(name__notcontains="SomeString") This…
Daniel Gollás
  • 984
  • 2
  • 9
  • 18
35
votes
3 answers

What does !! (double exclamation point) mean?

In the code below, from a blog post by Alias, I noticed the use of the double exclamation point !!. I was wondering what it meant and where I could go in the future to find explanations for Perl syntax like this. (Yes, I already searched for !! at…
Christopher Bottoms
  • 10,220
  • 7
  • 44
  • 87
34
votes
2 answers

String negation using regular expressions

Is it possible to do string negation in regular expressions? I need to match all strings that do not contain the string "..". I know you can use ^[^\.]*$ to match all strings that do not contain "." but I need to match more than one character. I…
Paul Bevis
  • 811
  • 1
  • 8
  • 14
32
votes
3 answers

Negative form of isinstance() in Python

How would I use a negative form of Python's isinstance()? Normally negation would work something like x != 1 if x not in y if not a I just haven't seen an example with isinstance(), so I'd like to know if there's a correct way to used negation…
mrl
  • 1,028
  • 2
  • 10
  • 20
19
votes
6 answers

Algorithm for Negating Sentences

I was wondering if anyone was familiar with any attempts at algorithmic sentence negation. For example, given a sentence like "This book is good" provide any number of alternative sentences meaning the opposite like "This book is not good" or even…
Kevin Dolan
  • 397
  • 1
  • 3
  • 7
15
votes
5 answers

Can I use the not operator in C++ on int values?

Strange question, but someone showed me this, I was wondering can you use the not ! operator for int in C++? (its strange to me). #include using namespace std; int main() { int a=5, b=4, c=4, d; d = !( a > b && b <= c) || a > c &&…
001
  • 55,049
  • 82
  • 210
  • 324
15
votes
4 answers

Exclamation mark in front of variable - clarification needed

I've been working with PHP for quite a while now, but this was always a mystery to me, the correct use of the exclamation mark (negative sign) in front of variables. What does !$var indicate? Is var false, empty, not set etc.? Here are some examples…
aborted
  • 4,504
  • 11
  • 59
  • 118
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,102
  • 1
  • 8
  • 17
1
2 3
13 14