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
30
votes
4 answers

What does `true = false` mean in Coq?

[I am not sure this is appropriate for stack overflow, but there are many other Coq questions here so perhaps someone can help.] I am working through the following from http://www.cis.upenn.edu/~bcpierce/sf/Basics.html#lab28 (just below where Case…
andrew cooke
  • 45,717
  • 10
  • 93
  • 143
30
votes
5 answers

Predicate vs Functions in First order logic

I have been so confused lately regarding difference between predicate and function in first order logic. My understanding so far is, Predicate is to show a comparison or showing a relation between two objects such as, President(Obama,…
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
30
votes
11 answers

Elegant way of reading a child property of an object

Say you are trying to read this property var town = Staff.HomeAddress.Postcode.Town; Somewhere along the chain a null could exist. What would be the best way of reading Town? I have been experimenting with a couple of extension methods... public…
David
  • 8,340
  • 7
  • 49
  • 71
30
votes
4 answers

Ruby if .. elsIf .. else on a single line?

With the ruby ternary operator we can write the following logic for a simple if else construct: a = true ? 'a' : 'b' #=> "a" But what if I wanted to write this as if foo 'a' elsif bar 'b' else 'c'? I could write it as the following, but it's a…
Noz
  • 6,216
  • 3
  • 47
  • 82
29
votes
2 answers

Prolog "or" operator, query

I'm working on some prolog that I'm new to. I'm looking for an "or" operator registered(X, Y), Y=ct101, Y=ct102, Y=ct103. Here's my query. What I want to write is code that will: "return X, given that Y is equal to value Z OR value Q OR value…
Eogcloud
  • 1,335
  • 4
  • 19
  • 44
28
votes
10 answers

&& operator behaves like || operator

I am a beginner and I've been trying to run a program that prints all the numbers from 1 to N (user input) except for those that are divisible by 3 and 7 at the same time. What my code does instead, however, is that it prints the numbers from 1 to N…
Ornstein
  • 365
  • 3
  • 9
28
votes
1 answer

Predicate to declare descending/ascending coordinates using finite domains

I'd like to write a predicate, descendo, which declares that the first given coordinate [y, x] is descending to the second given coordinate (imagine the board with [0, 0] at the left upper corner). A very simple implementation in Prolog could look…
naeg
  • 3,944
  • 3
  • 24
  • 29
27
votes
7 answers

How to add column values in mysql

This is my table data Student And this is my query -- SELECT id, SUM( maths + chemistry + physics ) AS total, maths, chemistry, physics FROM `student` but it is throwing a single row -- id total maths chemistry physics 118 760 55 …
Trialcoder
  • 5,816
  • 9
  • 44
  • 66
26
votes
4 answers

I can't understand how this javascript function works

I was reading the function definition of bind, but I can't 100% understand the code as written: if (!Function.prototype.bind) { Function.prototype.bind = function(oThis) { if (typeof this !== "function") { // closest thing…
Davis Dimitriov
  • 4,159
  • 3
  • 31
  • 45
26
votes
6 answers

How to do while loops with multiple conditions

I have a while loop in python condition1=False condition1=False val = -1 while condition1==False and condition2==False and val==-1: val,something1,something2 = getstuff() if something1==10: condition1 = True if…
mikip
  • 1,677
  • 6
  • 25
  • 35
26
votes
1 answer

27 different Bool to Bool values in Haskell

Could someone explain why there is 27 different Bool->Bool values, from which 11 can be definied in Haskell?
Machiaweliczny
  • 463
  • 3
  • 10
26
votes
1 answer

Does Lua have OR comparisons?

I'm just starting out using Lua, and I was wondering (because I can't find it on the website) if Lua has a OR operator, like how in other languages there is ||: if (condition == true || othercondition == false) { somecode.somefunction(); } whereas…
Polyov
  • 2,281
  • 2
  • 26
  • 36
26
votes
4 answers

ASP.Net: Conditional Logic in a ListView's ItemTemplate

I want to show certain parts of an ItemTemplate based according to whether a bound field is null. Take for example the following code: (Code such as LayoutTemplate have been removed for brevity)
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
25
votes
3 answers

What happens when you logical not a float?

I assume this just returns an int. Is there anything else going on I should be aware of? C/C++ differences? float a = 2.5; !a; // What does this return? Int? Float?
Nathan Fig
  • 14,970
  • 9
  • 43
  • 57
25
votes
12 answers

Detecting sequence of at least 3 sequential numbers from a given list

I have a list of numbers e.g. 21,4,7,9,12,22,17,8,2,20,23 I want to be able to pick out sequences of sequential numbers (minimum 3 items in length), so from the example above it would be 7,8,9 and 20,21,22,23. I have played around with a few ugly…
David
  • 8,340
  • 7
  • 49
  • 71