# Questions tagged [logical-operators]

802 questions

1

votes

1

answer

24

Views

### How to query an array for different combinations of ANDs and ORs in MongoDB Aggregation?

I am trying to search for list of students who have completed courses using different combinations of Logical ANDs and ORs.
For example I want to get student who completed ('Course 1' and 'Course 2') or 'Course 3'
Here is my data structure for each student :
{
'_id' : ObjectId('5c68841cb6b18f31975c...

0

votes

1

answer

28

Views

### What is logical and of two Integers? [duplicate]

This question already has an answer here:
Python's Logical Operator AND
6 answers
x = 100
y = 200
z = x and y
print (z)
I want to ask what type of and this is?
It is not bitwise and. Python gives me 200. How?

1

votes

2

answer

28

Views

### Replace(), replacing a value not specified

I've been learning Javascript via FCC for 6 weeks now, and decided to spend a week learning, and playing around with methods to get really close and comfortable with using them in loops, and with statements. Just playing around with strings, I was trying to replace the string 'I like milk', with 'I...

1

votes

4

answer

87

Views

### Python: Why do my 'if' statements' evaluate numbers incorrectly? [closed]

The code is as follows:
from random import *
numStars = int(input('Number of stars: ').strip())
planetTypeDict = {'O':0, 'B':0, 'A':0, 'F':0, 'G':0, 'K':0, 'M':0}
for star in range (numStars):
planetTypeChanceNum = uniform (0, 100)
if planetTypeChanceNum < 76.45:
planetType = 'M'
planetTypeDict['M'...

1

votes

4

answer

87

Views

### Nullable bool logical “AND” operator behaves differently with true and false [duplicate]

This question already has an answer here:
Nullable: and overloaded operators, bool? & bool
4 answers
Using bool? variables, can somebody explain why true & null results in null and false & null results in false?
void Main()
{
bool? a = null;
bool? b = true;
bool? c = a & b;
Console.WriteLine($'...

0

votes

2

answer

24

Views

### bash IF condition with OR logic syntax

i am confused..
i just make if file does not exist OR md5 sum is wrong
something like this
md5=20ffa23fbb589484d03d79608fe8d2ad
if ! -f /tmp/1.txt || echo -n ${md5} /tmp/1.txt | md5sum --status --check -
then
....
fi
how write valid syntax?

1

votes

0

answer

68

Views

### Possible to have logical operations (e.g. `ndarray.__eq__`) not return `bool` in NumPy?

Question
What's the most elegant way to have NumPy not always force np.equal / np.ndarray.__eq__ return arrays of type bool, especially when dtype=object?
Problem
Project issue: https://github.com/RobotLocomotion/drake/issues/8315
We're presently using NumPy in a project, and we have symbolic scalar...

1

votes

1

answer

27

Views

### The code generates the same combination twice.How can I improve it?

The code is as follows:
package AG;
import java.util.LinkedList;
import java.util.Stack;
public class ArithmeticGame {
public static void main(String[] args) {
LinkedList numbers = new LinkedList();
LinkedList number = new LinkedList();
for (int i = 1; i

0

votes

1

answer

26

Views

### Using logical operators in Python without a condition

This seems like a simple question but I was unable to find a precedent. One answer here points it out without explaining why.
Using logical operators without two variables returns not a boolean but one of the variables - the first for OR and the second for AND.
'x' or 'y'
> 'x'
3 and 4
> 4
What's th...

1

votes

1

answer

55

Views

### logical expressions in R, what makes is.na(x) return NA

I am doing the exercises in Hadley Wickham's ggplot2 book, and I am struggling with the question here, figuring out what ? represents:
Question- Fill in the question marks in this table:
There is no doubt that the first ? represents !x, since x is marked TRUE.
But, what makes is.na(x) NA? Also, I am...

1

votes

1

answer

108

Views

### multiple string comparison in a single if statement shell script using OR gate

I am trying to compare the value stored in string variable with three different possible values and if any of them does not matches then trying to throw error, in a single if statement using the logical operator OR. But everytime I am getting error even though the value stored in the variable is sam...

1

votes

1

answer

29

Views

### How to use multiple IR signals for doing the same thing?

I want to use different signals from different IR remotes to control a wheeled robot.
The robot is the Smart robot car kit v1.0 from Elegoo.
I used the infrared_remote_control_car.ino file from the disc with it.
I just added the #define JVC and the operators at the end.
The code looks like this:
#in...

1

votes

1

answer

71

Views

1

votes

0

answer

30

Views

### logical opertation !A && !B vs !(A||B)

I often see the following statement in embedded software
!A && !B
rather than
! (A || B)
Although both give the same truth table value.
I often use the http://web.stanford.edu/class/cs103/tools/truth-table-tool/ to
check complex logical operations.
Is there logical reason to it? Is there any gene...

1

votes

1

answer

400

Views

### How can I perform an OR with ScalaTest

I want to logically join two ScalaTest assertions with an OR operator.
The thing is, those two assertions are checking something completely different. There are some examples using or in similar posts but that is not what I want to do.
Most posts are checking an OR condition on the same variable,...

72

votes

7

answer

6.8k

Views

### Strange use of “and” / “or” operator

I'm trying to learn python and came across some code that is nice and short but doesn't totally make sense
the context was:
def fn(*args):
return len(args) and max(args)-min(args)
I get what it's doing, but why does python do this - ie return the value rather than True/False?
10 and 7-2
returns 5. S...

0

votes

3

answer

27

Views

### I'm having trouble with the OR operator in my python code

I'm trying to make a search system which has multiple ANDs and ORs and brackets. While I'm making the code, I'm having some trouble with the OR. I don't know if my code is wrong or if my computer is wrong, because sometimes it gives the right answer and sometimes it doesn't.
sentence = ['A', 'B',...

1

votes

1

answer

724

Views

### R: How to pass a list of selection expressions (strings in this case) to the subset function?

Here is some example data:
data = data.frame(series = c('1a', '1b', '1e'), reading = c(0.1, 0.4, 0.6))
> data
series reading
1 1a 0.1
2 1b 0.4
3 1e 0.6
Which I can pull out selective single rows using subset:
> subset (data, series == '1a')
series reading
1 1a 0.1
And...

1

votes

1

answer

268

Views

### SQL with Regular Expressions vs Indexes with Logical Merging Functions

I am trying to develop a complex textual search engine.
I have thousands of textual pages from many books.
I need to search pages that contain specified complex logical criterias.
These criterias can contain virtually any compination of the following:
A: Full words.
B: Word roots (semilar to stems;...

1

votes

1

answer

77

Views

### What does this expression do?

Is there any interpretation of this expression in the decimal system? In other words, is it an efficient implementation of calculation using the logical operation in place of arithmetic operation?
1) A number N plus a hexadecimal, i.e. (N+0x7f)
2) take the bitwise AND with the bitwise NOT of the sam...

1

votes

1

answer

428

Views

### Basic logic in MySQL

Our current mysql script that connects our Invoicing software to our website updates stock levels and what not, but there is a field in our products table which dictates if the product is visible or not which the script does not address. I want to introduce some IF logic to set the prodvisible colum...

1

votes

1

answer

880

Views

### Use logical OR || to combine two integers?

In this MSDN article on file sharing mode with std::ofstream, Microsoft writes:
To combine the filebuf::sh_read and filebuf::sh_write modes, use the logical OR (||) operator.
Both constants are of type int, as far as I can see, so I don't understand why we should use the logical OR instead of the bi...

1

votes

1

answer

144

Views

### Unexpected behavior in TSQL trigger using cursor: AND operator with values 1 AND 0 evaluates to true

I have been trying to debug some questionable database transactions produced by a trigger and when stepping through the T-SQL have encountered unexpected results. After obtaining values from the cursor via FETCH NEXT FROM Updated_Cursor , I enter a while loop and then for each row fetched from the c...

1

votes

1

answer

973

Views

### Assigning Values Using Logical Operators

I am trying to code weekends and weekdays using numeric values, such that 'Monday','Tuesday',...'Friday' = 0 and 'Saturday'/'Sunday' = 1. I presently have the following data:
head(bike.d)
Day Day.Code
Sunday 4
Sunday 4
Sunday 4
Sunday 4
Sunday 4
Sunday 4
tail(bike.d)
Day...

1

votes

1

answer

3.9k

Views

### Ternary Operator in Multiple conditions

I have one if condition in c#
if (item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 ||
item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)
{
@item.ReportTitle
}
I want to this if condition change to be used ternary operator ?
for using show and hide this a tag
(style='displa...

1

votes

4

answer

9.1k

Views

### jQuery logical operator not working as expected [duplicate]

This question already has an answer here:
Check if option is selected with jQuery, if not select a default
18 answers
I have below code which is not working.
var book_id = $('#indexBookSearch');
var tag_id = $('#indexTagSearch');
if((book_id.val() == '') || (tag_id.val() == ''))
{
$('#userMessages...

1

votes

2

answer

663

Views

### combined bit and logical operators in c

I'm confused about some of these operations (combinding bitwise and logical ops).
If x = 0x3F and y = 0x75, find the byte value of the diff c expressions:
1) x&y
2) x | y
3) ~x | ~y
4) x & ~y
5) x && y
6) x || y
7) !x || !y
8) x && ~y
attempt
FIrst, I converted the hex to binary:
x = 00111111
y = 01...

1

votes

1

answer

357

Views

### Wolfram Alpha and Logic - NOR transformation

i have some difficulties interpret some WolframAlpha logic.
I have this logical expression: !(a || b || c)
WA says, that it's minimal NOR-Form ist a NOR b NOR c.
But if you type it in, the truth tables are different.
However if you search for this (!a nor b) nor c
you'll get the correct answer.
Is t...

1

votes

1

answer

144

Views

### Prove that a proof system is not complete

I want to prove that the proof system A is not complete.
A consists of these axioms:
1. Y subset or equal X => X->Y
2. X->Y and Y->Z => X->Z (Transitive relation)
Therefore, I thought that I needed to prove that the axiom: X->Y => XZ->YZ cannot be proven using the axioms above.
I thought about pr...

1

votes

1

answer

118

Views

### Logical Evaluator

I have a program which needs to support 'User Options' to determine how it will overwrite files, the user can choose from 'Options' which can result into several combinations making it hard to code all the possible 'IF... ELSE statements', this complex result evaluation is hard to code and it is get...

1

votes

3

answer

107

Views

### PHP Multiple Logical Operator

Trying to figure out the best way to do this.
I have a PHP function that checks if something is true or not, and if it is, returns some JSON data.
The issue I'm having is that either one can return the data if the other is null, or both are true.
This is what I've tried:
if( $logic_type === true &&...

1

votes

1

answer

104

Views

### What is this logic? [long]=([long] And [long]) or [Long]

I apologize if this is a very basic logic questions, but I saw some code in an example and I'm not understanding the logic structure, so I was hoping someone could explain it to me.
In my examples I'm using [Long] simply as a representation for any Long data type object
The example looks like this:...

1

votes

2

answer

136

Views

### R subset logical

I have a list of data that I want to subset based on two variables (partition, deployment.date). Based on the articles and manuals, I should be able to do it using a single ampersand. What I am seeing however is that each one works on its own but not when combined.
> tail(x)
Composite Version...

1

votes

3

answer

125

Views

### Using logical operators stored in character variables while subsetting data frame in R

My R script get three inputs from user which are read into var1, var2 and var3.
I am trying to perform a simple subset operation for data frame. The pseudocode of my thinking is
shown below:
subset_data_frame

1

votes

1

answer

1.6k

Views

### Compound if / logical XOR bash bug?

#!/bin/bash
function logic_test()
{
left_bracket=$1
right_bracket=$2
if [[ ($left_bracket || $right_bracket) && ! ($left_bracket && $right_bracket) ]]
then
errEcho 'Input error: insertIntoConfigFile arg1 does not contain matching [].'
else
errEcho 'Passed'
fi
}
logic_test true true
logic_test true f...

1

votes

1

answer

141

Views

### java and python gives different result in logical operator

I am trying to get broadcast ip address coding in Java and Python for practice. Here is my code in java which gives me correct output:
public IPv4Address getBroadcastAddress() throws IllegalArgumentException {
long bits = 0;
bits = this.address.decimalIP() ^ (~(0xffffffff ^ (1L

1

votes

2

answer

239

Views

### How to pass default value to a variable in shell script?

I have written this piece of code to move one directory to another.
What I want with this code is as follows:
User will give a file name or a directory name.
User may give a destination folder. If user doesn't want a destination folder he/she will just press enter.
Then source directory will be copi...

1

votes

2

answer

314

Views

### how to add logical operators?

I have been trying to work this issue of on Codecademy all day. Nothing I do seems to work.
Instructions:
'Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and ||...

1

votes

1

answer

762

Views

### Solving bitwise XOR and ADD equation

Naturally XOR can be used twice to get back the original value. What if the original value is part of the mask?
Encoding:
e[i] = c[i] ^ (c[i] + c[i-1])
Assuming: starting value c[-1] = 0, ^ means bitwise XOR
In imperative C form:
void encode(byte *p, int len)
{
byte prev = 0;
for (auto i = 0; i < le...

1

votes

1

answer

58

Views

### Complex “IF”, “OR”, “AND” functions

Here is what I have done so far: (See screenshot attached)
When something is added under 'Laden' it gets a certain status. If this status is either 'Warte auf GO' or 'Warte auf Daten' AND the Date in the Datefield D2 is more than 6 days ago, I want the color of the cell under 'Laden' which has now '...