logic

First-order logic formula

If I want to express in first-order logic that 'the element(s) in the set with the smallest radius has the value 0', would the following be right? e1 S.   e2 S.   Radius e1 Radius e2     Value e1 = 0? Are the variables correctly quantified? Thanks ...

Is there any better way for comparing a string with multiple strings?

Hello, I want to compare a string with multiple string.For ex if([var isEqualToString:@"Box"]||[var isEqualToString:@"Ball"]|[varisEqualToString:@"Bat"]) { some function }else{ some fuction } In my case i have to compare with 15 string, so i have to check for 15 times.Is there any other better way to compare it.Is there any small sim...

ADT properties in Mercury

I wander why Mercury (10.04) can't infer determinism of next snippet: :- pred load_freqs(int::in, io.res(list(float))::out, io::di, io::uo) is det. load_freqs(CPU, ResFreqs, !IO):- open_input(cpu_fn(CPU, "available_frequencies"), ResStream, !IO), (ResStream = io.ok(Stream) -> ResFreqs = io.ok([]) ;ResStream = io.erro...

Complex if else logic

Friends How do I implement following complex logic? flag1 can be "N" or "A" or "I" flag2 can be "N" or "A" or "I" flag3 can be "N" or "A" or "I" function (string flag1, string flag2, string flag3) begin The function needs to return: return "None" if flag1, flag2 and flag3 are "N" else return "Active" if flag1, flag2 and flag3 are ...

PHP - Does try/catch have a higher overhead than if/then?

Working in some legacy code, I've run across a ton of Try/Catch statements. Try/Catch isn't something that they taught in my Zend certification classes, and in 10 years I've not worked with another PHP developer who's used it. Does Try/Catch have extra overhead compared to doing if statements? What would make it more or less desirable...

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 be able to use the nil value to represent undefined. ...

XOR of three values

What is the simplest way to do a three-way exclusive OR? In other words, I have three values, and I want a statement that evaluates to true IFF only one of the three values is true. So far, this is what I've come up with: ((a ^ b) && (a ^ c) && !(b && c)) || ((b ^ a) && (b ^ c) && !(a && c)) || ((c ^ a) && (c ^ b) && !(a && b)) Is th...

How to check if a list have any different value

Hello, I have a table like the following: (date1, date2, date3, date4, date5) and I want to check if ANY of these dates is different than any other. The trivial solution is: WHERE date1 <> date2 OR date1 <> date3 OR date1 <> date4 OR date1 <> date5 OR date2 <> date3 OR date2 <> date4 OR date2 <> date5 OR date3 <>...

Reverse lookup in Prolog? (how do I find everything that is true about X?)

So, let's say I have the following in a Prolog database: person(john). person(mary). happy(john). It is clear to that if I want to list all people, I can type: person(X). But, what if I want to find all the things that are true about john? I cannot do: X(john). But the effect I would like is to be able to put in "john" and get ...

Nested Callback Handlers?

I am getting a set of data from the database where the query produces a repetition of data with a different "Special" value. For example the user "A" can be repeated twice, having three different "Special" values under the "Special Column". I am using a callback handler to retrieve the data and put it into a list, now additionally I wan...

Float value evaluation completely incorrect

Hey internets. I am having a VERY strange issue in C. I am deriving a float value, and then checking to see if it is greater than 0. However, the comparison is always evaluating to true, even if the value is less than zero. Here is the code: if (sVel > 0.0f) { sVel += 1.0f; sVel -= 1.0f; NSLog(@"SEP VEL: %1.6f", sVel); ...

generate a truth table given an input ?

Hello , Is there a smart algorithm that takes a number of probabilities and generates the corresponding truth table inside a multi-dimensional array or container Ex : n = 3 N : [0 0 0 0 0 1 0 1 0 ... 1 1 1] I can do it with for loops and Ifs , but I know my way will be slow and time consuming . So , I am askin...

End a simulation run when the system gets empty

hi, Can anybody help me to end a simulation when there is no one inside?? that is simulation could end when the syatm gets empty regards, nilani ...

A logical method of displaying post submit error messages using php

//deal with individual form section posts //-->Faction Name if(isset($_POST['factionname'])){ $unsani_faction_name = $_POST['faction']; $new_faction_name = str_replace(",", "", $unsani_faction_name); $faction_name = mysql_real_escape_string($new_faction_name); $faction_name = preg_replace('/\s\s+/', ' ', $faction_name);//...

given a set of conditions, algorithmically determine only one can be True

Given a set of two or more logical conditions, is it possible to algorithmically determine that exactly ONE of them will evaluate to TRUE? For example: # this should pass, since for every X, only one condition is taken cond 1: (X >= 1.0) cond 2: (X < 1.0) # this should fail cond 1: (X < 1.0) cond 2: (X > 2.0) # this should also fail,...

Transitivity relationship: What is x.equals(z) when x.equals(y) is false and y.equals(z) is true

Assuming equals() is transitive; I understand that if x and y, have a bilateral agreement of being equal, then one of them, say y, does not enter into an agreement with a third class z on its own. But if we have a situation where x.equals(y) = false (still transitive) then what should this bilateral agreement with z be? ...

Algorithm to balance variably-sized items into roughly-balanced sets

I'm seeking an algorithm to split a list of items of varying sizes into "N" number of similarly-sized groups. Specifically, I'm working on an ASP.NET site in C# where I have a (database-retrieved) list of strings. The strings are of varying lengths. I have a set of columns which need to display the strings. I need an algorithm that will...

Logical problem

Hi stackoverflow, I would like to know some solutions to such a problem. It is given a number lets say 16 and you have to arange a matrix this way 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 the language doesn't matter, (prefferably PHP); ...

Expressing 2x2 Logic Grid in Code Efficiently

In an event handler I'm responding to the change of a value. I have access to the old value and the new value and want to do certain things depending on what the change is. Each different outcome will do some combination of actions/functions X, Y, or Z. Z accepts a parameter between -1 and 1. Order of performing these is not important. ...

"None not in" vs "not None in"

Unless I'm crazy if None not in x and if not None in x are equivalent. Is there a preferred version? I guess None not in is more english-y and therefore more pythonic, but not None in is more like other language syntax. Is there a preferred version? ...