Using Set Theory with arrays in programming [closed] - programming-languages

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I was wondering if there are functions in any programming languages that allow you to test set theory. For example a library or series of decent algorithms that can perform Combinatorics on large sets.
I don't need basic push/pop I would like to know for what programming languages do libraries exist for functions like UNION CONCAT INTERSECTIONS and Compliments, and comparison of sub sets for 100k+ element sets.
I know this sounds like a math question... maybe not but I am more looking for a Programming language that is designed to handle large sets quickly, because I know my algorithms will be slow.

The standard Python set type provides these operations. No guarantees that the speed will be what you need, since you haven't stated your performance requirements.

LINQ
Functional languages
R
....

You can use Scala, it has great support of sets! For example:
val set1 = Set(1,2,3,4)
val set2 = Set(3,4,5,6)
set1 & set2 //gives intersection
set1 intersect set2 //also possible to write
set1 | set2 //or set1 union set2 gives union
set1 &~ set2 //or set1 diff set2 gives difference
Also different implementations that good for particular issues, they are SortedSet, BitSet, HashSet and etc.

Related

What are these ? ه҈҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
These "characters" seem interesting. What are they?I would like to know more technical information about them. Thanks!
ه҈҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉ ه҈҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉ ه҈҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉
It's just a mass of combining marks. That alone is like 170 Combining Marks. You can do all sorts of weird rendering effects just by using a ton of combining marks together. But in this case just U+0489 COMBINING CYRILLIC MILLIONS SIGN is used.
Combining marks are not stand alone characters by themselves, but modify the previous base letter. For example a, a combining diaeresis ¨ renders as ä instead of a¨. Put more combining marks in there, and they all have to somehow render with the base character a, causing interesting rendering effect.
Code in the jsfiddle (SO didn't allow me to post otherwise):
var l = 1000;
var str = ":"
while(l--) {
str += String.fromCharCode(0x300 + Math.floor((Math.random() * 0x20)))
}
document.write(str);
Those are unicode characters that belong to another character set/language (in this case, Cyrillic). This information can be seen (on Windows) by using the Character Map tool, which is found in the Programs -> Accessories folder of the Start Menu.

Matching a line to a rule in c++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a line and a set of rules (other lines). Line to match (line = rule) may be very long; set of rules may be large and each rule may be long. Shorter rules may be part of longer (need to choose longer).
Currently, I have about 70 rules, <30 characters long, organized in a long if-else-if chain.
Is there any way to predict at what point there will be decrease in performance?
Is there a faster way of matching that comparing line with each of the rules?
Edit: There are no text files. I have an encoded sequence of characters, I go through if-elses comparing to "rules", and then act accordingly.
If you want to just check whether the input line is equal to any of the lines rules, then use an std::set (or std::map, if you want different behavior per rule) to store them. That takes the matching complexity down to O(lg N) where N is the number of rules.
Better yet, use an unordered_set (C++11) for O(1) performance.
If the behavior does not depend on which rule matched, then you can also compile a regular expression from the rules (e.g. (niVVVd__xniVVd__)|(niVVVdxniVVd)) with a tool like RE2 to get worst-case O(n) behavior, where n is the length of the input string.
Since you're comparing for equality, you don't need to match the longest rule first.

Is there any case where you must use ++var? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
The question is whether there is a situation where you can not use var++ and must use ++var (or the other way around).
That is, as far as I know, the only reason to use ++var over var++ (or the other way around) is to save space.
The question is, can we just have only the var++ abillity and not lose anything in the language's power?
You have to use ++var if you're using the expression within a bigger expression, and you definitely want the value of the expression to be the incremented one. For example, in C#:
int foo = 0;
foreach (var x in someCollection)
{
Console.WriteLine("{0}: {1}", x, ++foo);
}
Of course you could change this to use foo++ in a separate statement, but that isn't always feasible:
int foo = 0;
Expression<Func<int>> expression = () => ++foo;
That will return 1 the first time you call it, and you can't convert statement lambdas to expression trees.

what is logic programming? and what is different from other [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
today i have talk with other friend ,he said he has logic programming skill , so I am very curious about that.
The wikipedia entry explains it well: while on the surface it seems a redundant terms since all programming uses logic, in practice it's term for a well-defined paradigm, like, say, "functional programming" and "object-oriented programming". Specifically,
logic programming, in the narrower
sense in which it is more commonly
understood, is the use of logic as
both a declarative and procedural
representation language. It is based
upon the fact that a backwards
reasoning theorem-prover applied to
declarative sentences in the form of
implications:
If B1 and … and Bn then H
treats the implications as
goal-reduction procedures:
to show/solve H, show/solve B1 and … and Bn.
The language Prolog (in some variant or other) is probably still the most popular logic programming language.
I'd usually understand it to mean using prolog. Prolog allows you to define predicates, and truth values. The prolog interpreter can then derive further "truths", using standard logic rules. For example, each of the following lines establish a father_child and mother_children relationship between the first and the second parameter (the people mentioned are from the Simpsons).
member(X, [X|_]).
member(X, [_|T]) :- member(X,T).
mother_children(marge, [bart, lisa, maggie]).
mother_children(mona, [homer, jay]).
mother_child(X, Y) :- mother_children(X, C), member(Y, C).
father_child(homer, bart).
father_child(homer, lisa).
father_child(homer, maggie).
father_child(abe, homer).
father_child(abe, herb).
father_child(abe, abbie).
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).
If you fire this program into a prolog interpreter, and then ask it sibling(X,Y), it will return to you all the pairs of siblings that exist. What's interesting is that we never explicit say that say, Bart is a sibling to Lisa. We just define father and mother relationships, but by defining further rules, prolog uses normal rules to derive what names fullfill the sibling rule.
Prolog was more popular in the 80s, in various AI systems and the like. It's a bit out of fashion these days (not that you'd know in universities, where it's still hot shit).
I would take that statement to mean, "I can program if/then/else statements". Or in other words, I would take that statement to mean, "I can't program with any real technology". I would not be impressed.

Realworld example of when struct can be used [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 13 years ago.
Can anyone provide a realworld example of when a struct can be used?
A struct can be used when you have a complex return type for a method. i.e. you have to return several values, and they don't really warrant a full class's overhead.
A struct is notion of a record, a datatype that aggregates a fixed set of labelled objects, possibly of different types, into a single object. Structs are often used to group and relate objects in some manner.
If you mean a C struct, a great example is fixed scalar types in compilers. For example:
struct myScalar {
void *payload;
size_t psz;
unsigned int refs;
enum {
S_STR,
S_INT,
S_FLOAT,
S_OBJECT_INSTANCE
}type;
};
Or a union could be used. Not a robust example, but you get the idea. You can then do
switch(aVar.type){ ... }
Structs are great for helping you parse data that has been compressed to bits for sending over "The wire". You might have a bunch of bitfields to fill out a single byte, and a struct is a way to lay a template over this scrambled pile of variables and, without any real effort, change it into a collection of usable, easily referenced variables.

Resources