How are we doing? Please help us improve Stack Overflow. Take our short survey

Questions tagged [logical-operators]

Logical operators are symbols that aid in evaluating boolean expressions. These are found in just about every programming language that supports boolean. Common examples are && (AND), || (OR), ! (NOT), == ([value] equal to), === ([value and type] equal to), >= (Greater than or equal to), <= (Less than or equal to), > (Greater than), and < (less than)

Filter by
Sorted by
Tagged with
0 votes
3 answers
78 views

Combine logical vectors to create non-logical vector

I have two logical vectors in a data frame: df <- data.frame(log1 = c(FALSE, FALSE, TRUE, FALSE, TRUE), log2 = c(TRUE, FALSE, FALSE, FALSE, TRUE)) I want to make a third column by combining these ...
Peter Thwaites's user avatar
-3 votes
0 answers
22 views

While loop pauses [closed]

I realized that during while I’m usin a While True loop there are unnecessary little pauses why is that occuring? Using a while True loop, I didn’t expect little pauses but to continue running without ...
Demilade Omosehin Spyxxer's user avatar
-3 votes
0 answers
25 views

Compute all true bytes from boolean expression without testing each possible byte

Given is a boolean expression f = f(x_1,x_2,...x_n). How do I find all bytes of size n that make f=1? I want to do this without having to check for each possible byte of size n, see if they result in ...
Nenunathel's user avatar
0 votes
1 answer
33 views

How to cancel a while loop by typing 'quit' into either of two prompts

I have made a printer install script for our regional offices. It first asks you what office you are in and the asks if you want to add or remove a printer I'm trying to enable the user to type 'quit' ...
ubercaw's user avatar
0 votes
1 answer
22 views

Efficient way to drop dates Jupyter notebook

I have the next code: Date = df_new[['Date']].groupby(['Date']).sum().reset_index() for z in Date['Date']: df_old=df_old[df_old.Date != z ] df_old but it takes too long if Im trying to replace ...
Rafael del Rincón's user avatar
1 vote
2 answers
44 views

Apply logical operation on a dataframe in pyspark

I have a dataframe with many columns and in one of the columns I have the logical operation which I need to perform on the dataframe. As an example look at the dataframe below I need to perform the ...
Naveen Balachandran's user avatar
1 vote
1 answer
72 views

ANTLR accepting special characters like . (dot) and , (comma) in identifier or expression

I'm trying to execute dynamic expressions for the input data (Map) using ANTLR and using the answer of @Bart Kiers from the stackoverflow's post I was able to do it. I tried to add IN, STARTSWITH, ...
User1512's user avatar
0 votes
0 answers
51 views

Evaluating Logical Operations AND, OR, NOT dynamically in Java

I have a requirement to execute dynamic expressions for the input data (Map) using Java Code. For Example, Condition - EmployeeShift = 'General' AND (EmployeeType = 'CONTRACT' OR Designation IN 'ADMIN'...
User1512's user avatar
0 votes
1 answer
54 views

Overloading logical NOT operator to work as factorial [duplicate]

I've implemented an Integer class with overloaded NOT operator as the following: #ifndef INTEGER_H #define INTEGET_H template <typename T> T factorial(T t) { if (t == 1) return 1; ...
gfxmoda's user avatar
  • 21
0 votes
0 answers
44 views

(a>b)||(a<b) - or logical operator - what does it do?

I'm struggling to understand what the following command is checking. (a>b)||(a<b) I have defined a as 8 and b as 3. The returning result is TRUE. Is this checking whether a>b is true; or a ...
RStudent's user avatar
2 votes
1 answer
32 views

Why "if InputText == '0' || isempty(InputText)" in MATLAB is giving error?

if InputText == '0' || isempty(InputText) in MATLAB is giving error: Operands to the || and && operators must be convertible to logical scalar values. I'm looking for an explanation for it. ...
Hadi Salimi's user avatar
1 vote
1 answer
51 views

binary logical operations with long bit sequences

C++ Problem: The minimum number of 1's should be found in the result of the XOR operation between a randomly generated N Bit sequence (N up to 50) std::bitset<N> visit{0b01...110}; and a ...
Suslik's user avatar
  • 989
0 votes
1 answer
45 views

Disparate Logical returns working with datetimes created with as.POSIXct()

Rephrasing original question to add more clarity and reproducible code: The code below is what I am using to label various time segments of my hydrograph. When I run it no errors are returned. library(...
HydroSci's user avatar
2 votes
2 answers
62 views

using return code of grep as true false in a complex bash if statement

I want to have an if statement in bash that says if ((var1 greater than var2) and whole word var3 cannot be found in file path var4); then do this fi but I cannot seem to get the correct ...
Jimmy Chi Kin Chau's user avatar
0 votes
0 answers
25 views

Assign dynamic variable in loop in this PF calculation function

Hi i am trying to create a SPF calculator, here i need to calculate the interest for the months between joining date and retirement data i converted the period between those metrics as months. I ...
Selvakumar's user avatar
30 votes
2 answers
2k views

Logical vs. bitwise operators. Both are wrong?

When I use the following minimal code in an C++ console application in Visual Studio 2019, I get two warnings, which are completely opposite. int main() { unsigned char op1 = 0x1; unsigned ...
woelfchen42's user avatar
1 vote
2 answers
82 views

Use of AND & OR in the same LAMBDA function

I have been going through a tutorial on lambda functions and came across this line of code to evaluate if a number is odd or even. And I do not understand how the tow logic operators work in this ...
Manfred McLaren's user avatar
-1 votes
2 answers
64 views

My boolean expression is not evaluating correctly and need help finding the oversight in my code [duplicate]

Issue: After iterating through a cin password and saving instances of integers in the password to an integer variable(number). I use an if statement to search for conditions: if there are 5 or less ...
Eugene Irwin's user avatar
0 votes
0 answers
18 views

T-SQL SELECT logical operators in stored function not evaluating

I have a table tblLineItem representing line items for a set of products. The columns are: LineItemId int ProductId int IsActive bit IsInventory bit StockOnHand int LineItemId ProductId IsActive ...
PeterS's user avatar
  • 1
-1 votes
1 answer
42 views

How to add conditionally add a new key value pair to a json using jq?

I have a json file formatted as below [ { "foo" : "fooValue", "bar" : "barValue" }, { "foo" : null, "...
Jengels's user avatar
  • 440
13 votes
2 answers
1k views

difference between "&&" and "and" in kotlin

What's the difference between "&&" and "and" in kotlin? in my code, when first condition is false, i've noticed that the condition after "and" is still evaluated ...
AT Amrani's user avatar
  • 228
0 votes
1 answer
36 views

Express each of these statements in terms of C(x), D(x), F(x), quantifiers, and logical connectives

Let C(x) be the statement “x has a cat,” let D(x) be the statement “x has a dog,” let F(x) be the statement “x has a ferret.” Express each of these statements in terms of C(x), D(x), F(x), quantifiers,...
سہیل احمد's user avatar
0 votes
0 answers
11 views

Loop Over Multiple Columns with String Data & Create New Variable

I'm working in Rmarkdown. I have 11 columns in a dataframe that all have correct and incorrect answers as strings. I would like to loop over the 11 columns and score correct answers as 1 and incorrect ...
JimStir's user avatar
0 votes
3 answers
66 views

How to check for a condition within a while loop java

String valChecker = "SELECT * FROM `committee_memba` where (Rank= 'Chairperson' or Rank='Vice-Chair') and committee_name='" + jComboBox1.getSelectedItem().toString() + "'"; System....
janet's user avatar
  • 1
3 votes
1 answer
66 views

and and bitand in situations where & and && mean ref

Consider the following code. To me, the use of and and bitand is clearly a violation of semantics. #include <iostream> class C { public: void f() and // meaning && { ...
Thomas Weller's user avatar
0 votes
0 answers
26 views

Draw Logic Circuits using python's schemdraw

I want to draw this equation with schemdraw '(PB01) and (not LT02)' I Get something like this. here's my code : import schemdraw import schemdraw.logic as logic # Create a new drawing d = schemdraw....
karl97100's user avatar
-1 votes
2 answers
74 views

How to check if a variable is equal to multiple variables

I am currently taking the "CS50 Introduction To Computer Science" course, and I'm still quite new to programming in C. I'm working on a simple agreement project that involves using if ...
KORABIMERI 's user avatar
3 votes
6 answers
159 views

Applying function rowwise efficiently

I have a dataframe with multiple columns containing information on one diagnosis. The entries are TRUE, FALSE or NA. I create a vector which summarizes those columns as follows: If a patient was ...
LulY's user avatar
  • 972
0 votes
1 answer
38 views

How can I join multiple strings with logical operators to create a search term with for loop in python

I want to create a search term, depending on the input given. For example, when the user provides the phone number "69420" and name "Karen", the following code: getbools = [f"{...
Coder's user avatar
  • 75
1 vote
1 answer
48 views

Problems with comparisons in ANTLR4 grammar

I've build a small parser for writing filters in my application and most of it works fine. But now I noticed something weird. I have comparisons like '==', '!=', '>=' etc and they also work fine. ...
UglyBob's user avatar
  • 247
0 votes
0 answers
17 views

Given list of logical expressions, find all expressions which is true with inputs

I have many logial expressions (only and, or, not) without nested: (A or B or C) and (D or E) not (F or G) (A or G) and (B or E) not (D or C) (B) and (F) and (E) (A) not (F) (A or B or C) not (D or E) ...
Dinh Tien Loc's user avatar
2 votes
1 answer
79 views

Resolve Java Interface ambiguity in method parameters

I have a tree of boolean operations from a boolean expression that I have to run in Java. The tree would be something like this: And I would need to run it in Java iteratively so that it returns me a ...
simondx's user avatar
  • 73
2 votes
2 answers
41 views

I need help finding mathematical expressions of logic gates

My problem is super niche, but I need help finding ways to express logic gates with simple mathematical expressions. I already have Not, And, & Xor, but I can't figure out Or. And is y=a*b, Not is ...
RipMoney's user avatar
-1 votes
2 answers
74 views

How do I identify the Boolean Expression of this logic circuit?

As the title says, what can be the possible boolean expression of the logic circuit given? The Truth table is also included.Logic Circuit I have tried to solve my own Boolean Expression and coded it ...
Ragna Alt's user avatar
1 vote
1 answer
33 views

setdiff among 2 vectors 1st vector vs each element of 2nd vector

I have 2 vectors let us say A=[1 2 3 4] and B=[1 2 4]. Using a for loop I can compute setdiff of A with each element of B. Giving the following vectors C1=[2 3 4], C2=[1 3 4], C3=[1 2 3]. Is there a ...
Jared Lo's user avatar
  • 229
0 votes
2 answers
25 views

Using additional checks with the logical AND operator to render data without crashing on page refresh

When I refreshed the page my app crashes. This was due to my page loading in faster than my data. I think... So I added additional checks using the logical AND (&&) operator. Is this best ...
c0Ln's user avatar
  • 1
1 vote
2 answers
37 views

Why does the and && operator in awk end up changing values in my input file?

Quick question, I am trying to check for certain patterns in my comma-delimited CSV files/data and I need the and operator &&. I choose to work with AWK. Commands tried: 1: cat file | awk -F &...
visse226's user avatar
  • 139
3 votes
6 answers
90 views

Are there built-in "parallel" functions for boolean operations?

I'm looking for a function similar to pmax and pmin but for boolean operations. For example: parallel_and( c(TRUE, TRUE, TRUE, TRUE), c(TRUE, TRUE, TRUE, FALSE), c(TRUE, TRUE, FALSE, TRUE), c(...
Santiago's user avatar
  • 641
1 vote
1 answer
73 views

Logical Operations not as expected in C

Can someone explain how the following code functions #include <stdio.h> void main() { int a = 2, b = -1, c = 0, d; d = a-- || b++ && c++; printf("%d%d%d%d", a, b, ...
Aevo's user avatar
  • 68
-6 votes
1 answer
64 views

How to create an algorithm that takes as input a propositional logic expression without parentheses and encloses the same in parentheses in Python

I'd like to create an algorithm that takes as input a propositional logic expression without parentheses and outputs the same expression enclosed in parentheses in all possible ways depending on the ...
Mark's user avatar
  • 13
1 vote
0 answers
27 views

Talend application scenarios: is it correct to have logical operators in the first term of GAV mapping?

I'm working on a data integration project that makes use of Talend through a first logical formalization step of the global schema. I choose to exploit the GAV mapping properties to connect my source ...
Francesca Restante's user avatar
0 votes
1 answer
68 views

Why does the following expression in Javascript with logical AND operator is giving syntax Error?

While the expression is evaluating as expected for 1 && {} giving {} as the answer, however when I flip the operands to make it {} && 1 it gives syntax error. 452:1 Uncaught ...
Prakhar Tripathi's user avatar
2 votes
1 answer
37 views

NumPy all Function Across Third Dimension of ndarray

Consider the ndarray with the following dimensions (1200,2600,200) I am looking to assess whether all the values along the third dimension, or axis=2, at point [i,j] in this array are all the same ...
TornadoEric's user avatar
-1 votes
1 answer
28 views

Combining && with || in an if statement [duplicate]

I want to have a short if statement on one line that checks if condition A is met and then check if condition B is met, where both conditions are specific strings, but condition B has more than one ...
Anton E's user avatar
  • 75
3 votes
1 answer
62 views

How is logic operator short circuiting here?

#include <stdio.h> int main() { int x = -2; while (x++ || x==0) { printf("X"); } } The output is coming as XX Why? I am expecting this code to have gone into ...
FreeDragon's user avatar
2 votes
1 answer
125 views

CS50 Trie Week 5: check function not working

I have been trying to complete the trie practice problem from the CS50 course. The check function that I wrote must check whether the user input is found within the trie that has been created in the ...
thombellll's user avatar
0 votes
2 answers
48 views

LValue required in C [closed]

I am getting the error of left operand expected but I don't know what to do cause I got this error first time. I wrote this code: char answer1; char answer2; printf("Have you passed maths exam?(y ...
Sagar Salgar's user avatar
1 vote
3 answers
65 views

How to get logical mask of two lists if lists contain np.NaN

Logical OR and logical AND seems do not work when list have np.NaN. I produced simple example: If I will have ndarray filled with np.NaN, it do not work correctly: import numpy as np m =10 l1, l2 = np....
luki's user avatar
  • 197
0 votes
2 answers
28 views

How to simplify a logical expression with several FiniteSets

Using the Python package sympy (version 1.12) I have several FiniteSets and an expression I want to simplify/optimize. As an example says more than thousand words: from sympy import Symbol, FiniteSet, ...
Noxx's user avatar
  • 354
0 votes
0 answers
32 views

Google Sheets Formula to show a fee total within a range of dollar amounts

Current Portfolio Total 37250125 User 1 Fees 0- $5mm 0.65% 32500 $5mm -10mm 0.45% 0 $10mm-25mm 0.35% 0 $25mm-50mm 0.30% 55125.5625 $50mm+ 0.20% 0 User 1 Total Fees ...
Matt Pontes's user avatar

1
2 3 4 5
52