Questions tagged [logic]

Logic refers to the ultimate flow of your code and how you arrive your desired solution. Questions should relate to finding a coding solution (or improving existing coding logic) to a given problem. Please use with an appropriate language tag, a thorough description of your logic, and the relevant code you're working on. General logic questions are off-topic. If you simply need a code review, consider https://codereview.stackexchange.com

Note that the bulk of questions tagged concern the broad sense of program logic described in the excerpt above. Before using the tag, consider if a tag about a more specialised logic-related topic would be a better fit. Examples include:

Furthermore, if your question is about one of those specialised topics, consider whether it essentially involves programming in some way. If it doesn't, it will likely be more appropriately posted elsewhere in the network. Some sites in which such questions might be a good fit, depending on the circumstances of each concrete case, are Philosophy, Mathematics and Computer Science.

9357 questions
20
votes
7 answers

Incrementor logic

I'm trying to get deeper with post and pre incrementors but am a bit stuck with the following expression : public static void main(String[] args) { int i = 0; i = i+=(++i + (i+=2 + --i) - ++i); // i = 0 + (++i + (i+=2 + --i) - ++i); …
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
20
votes
6 answers

Dynamically evaluating simple boolean logic in Python

I've got some dynamically-generated boolean logic expressions, like: (A or B) and (C or D) A or (A and B) A empty - evaluates to True The placeholders get replaced with booleans. Should I, Convert this information to a Python expression like True…
a paid nerd
  • 30,702
  • 30
  • 134
  • 179
20
votes
6 answers

Hilbert System - Automate Proof

I'm trying to prove the statement ~(a->~b) => a in a Hilbert style system. Unfortunately it seems like it is impossible to come up with a general algorithm to find a proof, but I'm looking for a brute force type strategy. Any ideas on how to…
aramadia
  • 1,696
  • 3
  • 15
  • 24
20
votes
5 answers

Why are products called minterms and sums called maxterms?

Do they have a reason for doing so? I mean, in the sum of minterms, you look for the terms with the output 1; I don't get why they call it "minterms." Why not maxterms because 1 is well bigger than 0? Is there a reason behind this that I don't know?…
19
votes
6 answers

How to implement decision matrix in c#

I need to make a decision based on a rather large set of 8 co-dependent conditions. | A | B | C | D | E | F | G | H -----------+---+---+---+---+---+---+---+--- Decision01 | 0 | 1 | - | 1 | 0 | 1 | - | 1 Decision02 | 1 | 0 | - | 0 | 0 | -…
Aether McLoud
  • 732
  • 1
  • 7
  • 20
19
votes
6 answers

What can be the efficient approach to solve the 8 puzzle problem?

The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent…
Ravindra S
  • 6,302
  • 12
  • 70
  • 108
18
votes
18 answers

C# logic order and compiler behavior

In C#, (and feel free to answer for other languages), what order does the runtime evaluate a logic statement? Example: DataTable myDt = new DataTable(); if (myDt != null && myDt.Rows.Count > 0) { //do some stuff with myDt } Which statement does…
Seibar
  • 68,705
  • 38
  • 88
  • 99
18
votes
2 answers

When to use conjunction and when to use implication? (First Order Logic)

I'm learning First Order Logic at the moment. I'm looking at this example: Some dogs bark ∃x (dog(X) Λ bark(x)) All dogs have four legs ∀x (dog(x) -> have_four_legs(x)) My question is: is it possible for the second example to be: ∀x (dog(x) Λ…
ninjaneer
  • 6,951
  • 8
  • 60
  • 104
18
votes
3 answers

Error: The truth value of a Series is ambiguous - Python pandas

I know this question has been asked before, however, when I am trying to do an if statement and I am getting an error. I looked at this link , but did not help much in my case. My dfs is a list of DataFrames. I am trying the following, for i in…
i.n.n.m
  • 2,936
  • 7
  • 27
  • 51
18
votes
3 answers

Advanced Django Template Logic

I'm not sure if this is really easy and I just glanced over it in the documentation, or if this is a limitation of the Django template system, but I need to be able to do a little (not very) advanced logic in Django, and I'd rather not have to…
Daniel Rosenthal
  • 1,386
  • 4
  • 15
  • 32
17
votes
5 answers

Is there a way to realize a function of type ((a -> b) -> b) -> Either a b?

Propositions (P -> Q) -> Q and P \/ Q are equivalent. Is there a way to witness this equivalence in Haskell: from :: Either a b -> ((a -> b) -> b) from x = case x of Left a -> \f -> f a Right b -> \f -> b to :: ((a -> b) -> b) ->…
user12333506
17
votes
3 answers

Why does "true && () => {}" produce "Uncaught SyntaxError: Malformed arrow function parameter list"?

The following code, when executed, true && () => {} yields Uncaught SyntaxError: Malformed arrow function parameter list Why ? Edit: I know wrapping the function in parenthesis works, thanks everyone, but I'd like to understand why can't the…
João Pinto Jerónimo
  • 9,586
  • 15
  • 62
  • 86
17
votes
5 answers

Why doesn't the C# compiler throw for logical comparisons of null?

I was eating lunch with a friend yesterday and they were complaining about null in C#. He stated that null was illogical. I decided to test his claims, so I tested some simple logical propositions: Console.WriteLine(null == null);…
Pookchop
  • 211
  • 1
  • 4
17
votes
2 answers

Is it possible to use an AND operator in grepl()?

I want to search for anything that begins with 55 and anything that has the word Roof (case-sensitive, for those who are curious) in it. So far I have been unsuccessful, as I can only seem to use the OR operator: grepl("*^55|*Roof",…
Mus
  • 7,290
  • 24
  • 86
  • 130
17
votes
2 answers

What is the Objective-C way of getting a nullable bool?

How should I go about getting a bool value that I can assign true, false and nil to in Objective-C? What is the Objective-C way of doing this? Much like C#'s Nullable. I'm looking to be able to use the nil value to represent undefined.
Greg Sexton
  • 9,189
  • 7
  • 31
  • 37