logic

Compare DB row values efficiently

I want to loop through a database of documents and calculate a pairwise comparison score. A simplistic, naive method would nest a loop within another loop. This would result in the program comparing documents twice and also comparing each document to itself. Is there a name for the algorithm for doing this task efficiently? Is there ...

Why is Decimal('0') > 9999.0 True in Python?

This is somehow related to my question Why is ''>0 True in Python? In Python 2.6.4: >> Decimal('0') > 9999.0 True From the answer to my original question I understand that when comparing objects of different types in Python 2.x the types are ordered by their name. But in this case: >> type(Decimal('0')).__name__ > type(9999.0).__nam...

What are good/great books on Logic Design ?

I want a couple good books that cover the subject of logic design, making computer circuits. There seems to be a lot of expensive books on logic design but it is unclear which ones are good. ...

Help with a logic problem

I'm having a great deal of difficulty trying to figure out the logic behind this problem. I have developed everything else, but I really could use some help, any sort of help, on the part I'm stuck on. Back story: *A group of actors waits in a circle. They "count off" by various amounts. The last few to audition are thought to have the...

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 or (True or False) and eval it? Create a binary tree where a node is either a bool or ...

logic question about factorials

I have a problem and can't solve it alone. My teacher gives me one logic task today, and i'm sure you can help me. How can I count the number of zeroes at the end of factorial(41). (on paper) I understand that it has nothing to do with programing, but I'm sure programers can help me. Thanks in advance. ...

Is XML a good logic to load data??

Hi stack, i'm working on an app that loads some data from xml file from internet. Is this a good way to develop iPhone apps??...I think xml is more light than SQlite database... Basically my logic is: 1 - Parsing Xml file from internet to retrive the data 2 - Load data on device Security?..other stuff??.. Thanks Mat ...

fuzzy logic and neural networks

what is the use of activation function with any two activation function? ...

How can I manage a fork pool in Perl?

I'm setting something up to SSH out to several servers in 'batches'. I basically want to maintain 5 connections at a time, and when one finishes open up another (following an array of server IPs). I'm wondering for something like this should I be using fork()? If so, what logic can I use to ensure that the I maintain 5 children at a tim...

Handling Complex Rules in in GUI applciations (C++ or C#)

Im working on a dialog box in which several rules must be satisfied before the OK button is enabled. Currently any action on the page such as entering data or selecting an item from a drop down list (amongst other things) calls a single function called ProcessEvent() - this function handles all logic and either enables or disables the O...

Any ideas on How to search a 2D array quickly?

I jave a 2D array like this, just like a matrix: {{1, 2, 4, 5, 3, 6}, {8, 3, 4, 4, 5, 2}, {8, 3, 4, 2, 6, 2}, //code skips... ... } (The Array is not sorted) I want to get all the "4" position, instead of searching the array one by one, and return the position, how can I search it faster / more efficient? thz in advance. ...

Logic to skip repeating values in a variable

i have a loop where a variable value will change in each loop and display those values in each loop. i need to skip the display of the value if the same value repeats from second time ...

IndexOf method returns 0 when it should had return -1 in C# / Java

A friend of mine came to me with this strange behavior which i can't explain, any insight view would be appreciated. Im running VS 2005 (C# 2.0), the following code show the behavior int rr = "test".IndexOf(""); Console.WriteLine(rr.ToString()); the above code, print "0" which clearly show it should have return -1 This also happen i...

Templates, and C++ operator for logic: B contained by set A

In C++, I'm looking to implement an operator for selecting items in a list (of type B) based upon B being contained entirely within A. In the book "the logical design of digital computers" by Montgomery Phister jr (published 1958), p54, it says: F11 = A + ~B has two interesting and useful associations, neither of them having much to do...

Distribution of items from "x" sets of plants in "y" baskets equally.

I need ideas about algorithm for distribution of plants in groups. I have, say 5, sets of plants and each set depicts a certain property e.g., setA= {set of all plants that are green in color} setB = {set of all plants red in color} setC={ all the plants that are roots also} setD= {fruits} setE= [flowers} A plant can be a memb...

What efforts exist to use programming languages to model legal code?

Legalese can be considered an extremely inefficient language, and it certainly has ambiguities. What attempts exist out there to use programming languages (or any symbolic logic approaches, for that matter) to model legal code (such as laws and contracts)? ...

First order logic formula

R(x) is a red block B(x) is a blue block T(x,y) block x is on top of block y Question: Write a formula asserting that if no red block is on top of a red block then no red block is on top of itself. My answer: (Ax)(Ay)(R(x) and R(y) -> ~T(x,y))->(Ax)(R(x)-> ~T(x,x)) A = For all ~ = Not -> = implies ...

What is natural deduction used for outside of academia?

Hello, I am studying natural deduction as a part of my Formal Specification & Verification Computer Science course at University/College. I find it interesting, however I learn much better when I can find a practical use for things. Could anyone explain to me if and how natural deduction is used other than for formally verifying bits ...

What's wrong with my logic here?

In java they say don't concatenate Strings, instead you should make a stringbuffer and keep adding to that and then when you're all done, use toString() to get a String object out of it. Here's what I don't get. They say do this for performance reasons, because concatenating strings makes lots of temporary objects. But if the goal was pe...

Prolog - Finding the current directory, relative directory for 'tell' predicate

I'm having trouble trying to figure out how to get prolog to spit out a text file where I want it to. I'm currently doing a bunch of operations and then using tell('output.txt') to record the output. Now the problem is that when I do this, it creates this file in the SWI \bin\ folder. I was wondering if there's a way to make it create...