theory

Retrieve maximal / minimal record

夙愿已清 提交于 2019-12-07 08:39:09
问题 A rather complicated SQL query I was working on got me thinking about a limitation of (ANSI) SQL: Is there a way to retrieve a record that is maximal or minimal with respect to an arbitrary ordering? In other words: Given a query like this: SELECT * FROM mytable WHERE <various conditions> ORDER BY <order clause> is it possible to write a query that returns only the first row (possibly by transforming the order clause into something else)? I know you can do this using LIMIT (MySQL) / ROWNUM

Proving correctness of multithread algorithms

这一生的挚爱 提交于 2019-12-06 19:15:23
问题 Multithread algorithms are notably hard to design/debug/prove. Dekker's algorithm is a prime example of how hard it can be to design a correct synchronized algorithm. Tanenbaum's Modern operating systems is filled with examples in its IPC section. Does anyone have a good reference (books, articles) for this? Thanks! 回答1: It is impossible to prove anything without building upon guarentees, so the first thing you want to do is to get familiar with the memory model of your target platform; Java

how to prove 2 sql statements are equivalent

让人想犯罪 __ 提交于 2019-12-06 15:23:55
I set out to rewrite a complex SQL statement with joins and sub-statements and obtained a more simple looking statement. I tested it by running both on the same data set and getting the same result set. In general, how can I (conceptually) prove that the 2 statements are the same in any given data set? I would suggest studying relational algebra (as pointed out by Mchl). It is the most essential concept you need if you want to get serious about optimizing queries and designing databases properly. However I will suggest an ugly brute force approach that helps you to ensure correct results if

Color Remapping - Matching target palette using a 3D grid?

不羁的心 提交于 2019-12-06 13:24:15
Let's say I have color 'FOO', and it is stored in RGB format. I need to recolor 'FOO' so it matches the closest color in a list of colors. Doing this on the fly, couldn't I view the RGB values from each color as points on a 3D grid (r=x, g=y, b=z) and compute the distance between point 'FOO' vs the points from each color in the list? The closest point to 'FOO' would be the replacement color? In theory, yes. In reality, computing the closest color is non-trivial if you want to do it well. Just for example, people's eyes are much more sensitive to changes in brightness than color shifts,

Recursive Sets vs Recursive Functions

偶尔善良 提交于 2019-12-06 09:49:20
问题 What s the difference between a recursive set and recursive function? 回答1: Recursive functions and recursive sets are terms used in computability theory. Wikipedia defines them as follows: A set of natural numbers is said to be a computable set (also called a decidable, recursive, or Turing computable set) if there is a Turing machine that, given a number n, halts with output 1 if n is in the set and halts with output 0 if n is not in the set. A function f from the natural numbers to

Encrypted database query

假装没事ソ 提交于 2019-12-06 09:46:53
问题 I've just found out about Stack Overflow and I'm just checking if there are ideas for a constraint I'm having with some friends in a project, though this is more of a theoretical question to which I've been trying to find an answer for some time. I'm not much given into cryptography but if I'm not clear enough I'll try to edit/comment to clarify any questions. Trying to be brief, the environment is something like this: An application where the front-end as access to encrypt/decrypt keys and

Better intuition for information theory

倖福魔咒の 提交于 2019-12-06 07:01:47
Better intuition for information theory 2019-12-01 21:21:33 Source : https://www.blackhc.net/blog/2019/better-intuition-for-information-theory/ The following blog post is based on Yeung’s beautiful paper “ A new outlook on Shannon’s information measures ”: it shows how we can use concepts from set theory, like unions, intersections and differences, to capture information-theoretic expressions in an intuitive form that is also correct. The paper shows one can indeed construct a signed measure that consistently maps the sets we intuitively construct to their information-theoretic counterparts.

Thread.Abort and alternatives

吃可爱长大的小学妹 提交于 2019-12-06 04:07:55
问题 This is more out of personal curiosity/interest than a specific problem I'm trying to solve. Suppose you have a program that is performing some operation on user-supplied information (such as a search string) that changes as the user types it. Suppose that you want to show the user the most relevant information for what they've typed at any given time. If threads were really abortable, we could simply have one thread running based on the last-changed search string, and cancel any previous

Are tag (or “marker”) interfaces obsolete?

吃可爱长大的小学妹 提交于 2019-12-06 02:56:40
问题 I'm trying to help a coworker come to terms with OO, and I'm finding that for some cases, it's hard to find solid real-world examples for the concept of a tag (or marker ) interface. (An interface that contains no methods; it is used as a tag or marker or label only). While it really shouldn't matter for the sakes of our discussions, we're using PHP as the platform behind the discussions (because it's a common language between us). I'm probably not the best person to teach OO since most of my

Can you encode to less bits when you don't need to preserve order?

南笙酒味 提交于 2019-12-06 00:53:29
Say you have a List of 32-bit Integers and the same collection of 32-bit Integers in a Multiset (a set that allows duplicate members) Since Sets don't preserve order but List do, does this mean we can encode a Multiset in less bits than the List? If so how would you encode the Multiset? If this is true what other examples are there where not needing to preserve order saves bits? Note, I just used 32-bit Integers as an example. Does the data type matter in the encoding? Does the data type need to be fixed length and comparable for you to get the savings? EDIT Any solution should work well for