|
i guess one of the links worked
best regards.
|
|
|
|
|
Hello,
I have some facts like:
asdf(a,b).
asdf(b,c).
asdf(c,d).
etc.
I'd like to do some function
givemelettersinvolved(L) that instantiates in L a list that contains the constants involved in those facts
for example
asdf(a,b).
asdf(b,c).
givemelettersinvolved(L) would give L = [a, b, c]
How can I make this?
I was trying with
...(L) :- asdf(A,B), member(A,L), member(B,L).
But its not working
|
|
|
|
|
wtf are you talkin about
anyway the answer was to use findall(X, predicate(X), List)
|
|
|
|
|
hi there,
I'm looking for a code snippet for conjugate gradient and preconditioned conjugate gradient iterative solver for system of linear equations in C++ or C#.
|
|
|
|
|
if I were needing that, this[^] is one of the places that I would look at; it holds lots of links.
|
|
|
|
|
|
Anyone knows of any math software that has unlimited precision (i.e., 123^123,456,789 mod 987,654,321)? I'm looking into Mathematica Home Edition, but I'm not sure if it does that. I know Maple could calculate PI to as many digits as you want if you were willing to wait, but I'm not sure if that applied to all functions in general or just built-in ones.
|
|
|
|
|
Most, if not all, of the Mathematica/Maple/Mathcad type packages have an arbitrary precision integer and/or rational number capability. Check their online docco and/or user forums. If you're looking for a language to write your own code, Java has BigInteger built in, and there are free packages for other popular languages. (I have used a couple of the C++ ones - the quality does tend to vary a bit, but the good ones are good.)
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Thanks, forgot about MathCad which I used to love. Does the BigInteger support ridiculously large numbers (i.e., unlimitedly large)? You know any for C#? I downloaded VS2010 to check it out but that think sucks big time.
|
|
|
|
|
Java BigInteger (and any other reasonable implememntation) will grow until you run out of memory (or patience ). I don't play C#, but a quick google found C# BigInteger Class[^] right here on CP. Re VS2010: I've seen so much suckage reported here I'm not going anywhere near it!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
That article describes a private BigInteger attempt on an old .NET version (which did not come with a built-in one); since 4.0 .NET has its own, pretty good, BigInteger class, probably very comparable to the venerable Java one.
|
|
|
|
|
Since .NET 4.0 C# has BigInteger too.
|
|
|
|
|
Thanks, Luc. As I noted above, I don't inhabit those realms!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Great, now if only VS2010 would play nice.
|
|
|
|
|
Mathematica from Wolfram should do it.
|
|
|
|
|
You're a few months late.
Thanks, but I ended up using Visual C# Dot Net 4.0 BigInteger class.
|
|
|
|
|
here is a problem. I've got an array of records with 2 fields: ID and ParentID. This array represents a hierarchical tree, where each node can have multiple children.
What I need is to convert it to a more compact form, like this (code is in C#)
public class TreeBranch
{
int ID;
List<TreeBranch> Children;
.........................
}
................
List<TreeBranch> MainTree; // a collection that contains the whole tree
I've came up with a dizzy solution, but I don't like it since it is O (n^2).
Any ideas will be appreciated )
|
|
|
|
|
What was your solution?
Anyway, that way I might do this would be like this: while you are building the tree, also keep an array of your tree nodes, indexable by ID. Then when you want to add a node to its parent's Children, you can just index into that array to get the parent object.
edit: if the nodes are in pre-order you can build the array while you process the items, otherwise you'd need two passes: one to fill the array, and one to build the tree (that is, of course, still O(n) )
modified on Thursday, July 29, 2010 7:21 AM
|
|
|
|
|
Hi & thanks for reply&interest.
Nevermind my previous thought - that idea was not working )
What I need to do is to write a recursive method, so it will be able to work at any depth.
Not that great with recursion, but job needs to be done.
Once I'll finish that, I'll post an answer to share with others.
|
|
|
|
|
Why would you need recursion here? A simple loop over all items would do.. unless there's something you haven't told us yet?
|
|
|
|
|
Partly my fault:
original message has been parsed and it dropped the fact, that the field Children is a generic of type TreeBranch - it contains children of a certain node. Each of those children can have its own List of children, and so on. Anyways, it's all about converting an array of objects which have ID and ParentID into a tree hierarchy. Consider a case
an array: (ParentID;ID)
-,1
1,2
1,3
2,4
4,5
should look something like
1-
2-
3 4-
5
Because the depth of the tree is unknown, recursion is the only option - we have no idea about the nodes, that are inhereted from the current.
For some dumb security reasons of my job I can't post the code here, but I'll do that later, since the task is very real life
|
|
|
|
|
Your diagram is a bit confusing, what do you really mean?
Btw, the depth of the resulting tree has no relevance - in fact the algorithm I described works for directed graphs in general (trees or not) even if they have disjunct subgraphs or cycles or both (making the "depth" undefined).
|
|
|
|
|
|
Add each node to a HashTable using the ID as the key.
Loop through the nodes and yourHash[this.ParentID].AddNode(this);
I don't know O notation, but I think that would be 2n instead of n^2.
|
|
|
|
|
T M Gray wrote: I don't know O notation, but I think that would be 2n instead of n^2.
That's O(n) instead of O(n2)
(fyi, that's what I said, but with a HashTable instead of an array)
|
|
|
|
|