last day (14 days later) » 

6:08 AM
3
A: How can I reduce a number?

J. M.Ah, here we go: this one's the problem of enumerating the number of ways to make change. This problem has been discussed before on this site and in a nice textbook, but let's specialize to your problem. Consider a country, Lost-soulia, where the currency unit is the Lostie. The existing coins of...

 
Er, that's why you unpack and interpret the terms of the coefficient of the series expansion, @Tanner. To use $a^{10}+a^8 b+a^6 b^2+a^6 c+a^4 b^3+a^4 b c+a^2 b^4+a^2 b^2 c+a^2 c^2+b^5+b^3 c+b c^2$ as an example again, this says that you can have 10 Losties as 10 1-Lostie coins ($a^{10}$), 8 1-Lostie and 1 2-Lostie coins ($a^8 b$), 6 1-Lostie and 2 2-Lostie coins ($a^6 b^2$)... hopefully you've gotten the hang of it at this point.
Anyway, here's a Mathematica implementation of the idea: MakeChange[n_Integer?Positive, v_?VectorQ] := Module[{l = Length[v], x}, Exponent[#, Array[C, l]] & /@ Apply[List, Expand[SeriesCoefficient[1/Apply[Times, 1 - Array[C, l] x^v], {x, 0, n}]]]] /; VectorQ[v, (IntegerQ[#] && Positive[#]) &]. Try MakeChange[10, {1, 2, 4}] for instance.
 
I'm new to math so it'll take a few hours to understand this but Tanner is correct, I may not understand this fully but I am actually not trying to create the whole list but figuring out how to compute a table for each value so I can rejoin them quickly on other machines. I will study this and may have mistunderstood though.
 
Well, what I gave is the mathematical solution to your problem @Lostsoul. For a programmatic solution, there are efficient polynomial-time algorithms; I'll try to dig up references unless somebody beats me to it. If you have Mathematica on you, try the code I gave; if you have some other computing system, tell me and I'll see if I can translate to your favorite language.
 
Wow..amazing..You guys are so helpful. I code in python if that helps. When I started learning math I installed Mathematica but haven't used it, you're giving me a reason! I'll try to understand and try it. Thanks so much, JM.
 
@Lostsoul: You're very much welcome. I wrote that in version 8; if you're using an earlier version, quite a few modifications to MakeChange[] are needed.
 
6:08 AM
Sorry, I am trying to run it but keep getting '$RecursionLimit::reclim: Recursion depth of 256 exceeded.' Your code is somewhat similar to python, I'll just work on converting it and running in that environment. I'll let you know the result.
 
@Lostsoul: could you give the exact input you gave to Mathematica? What version are you using?
 
I just copied and pasted your code into mathematica 8
Hi J.M..thanks again for your help. I'm really greatful..
When your a newbi and learning, its great to have experts willing to give a helping hand to help you understand.
 
Okay, you're in Mathematica now?
 
I must admit though..I'm new to this kind of math..
in version 8
yes
I copied the code and hit shift-return
 
Okay, first, execute Remove[MakeChange]
then enter MakeChange[n_Integer?Positive, v_?VectorQ] := Module[{l = Length[v], x}, Exponent[#, Array[C, l]] & /@ Apply[List, Expand[SeriesCoefficient[1/Apply[Times, 1 - Array[C, l] x^v], {x, 0, n}]]]] /; VectorQ[v, (IntegerQ[#] && Positive[#]) &] in a new cell
 
6:10 AM
ok i think i might know where i made a mistake..one second
 
after that, then you execute MakeChange[10, {1, 2, 4}]
The key is to execute in separate cells.
 
when you say cells. is it suppose to look like a spreadsheet? I am using the notebook mode
i just tried rerunning with your Remove at the top..and got {{0, 0, 0}, {0, -[Infinity], 0}}
I sort of don't understand your description though..I know I can't break down recusions into different proceses.
I'm not sure if it'll be formated correctly but here's the code i have(python)
#sorts each element of seq and returns it
def orderedInnerLists(seq):
return map(sorted, seq)

#returns a copy of seq with duplicates removed
def removeDuplicates(seq):
ret = []
for value in seq:
if value not in ret:
ret.append(value)
return ret

memoizedResults = {}
def orderedPossibleSplits(value,validIncrements):
memoizeKey = (value, tuple(validIncrements))
if memoizeKey in memoizedResults:
return memoizedResults[memoizeKey]
ret = []
for increment in validIncrements:
if increment > value:
continue
running print orderedPossibleSplits(10, [1,2,4]) gives the list..
so what I do is, take the universe 4,2,1 and run it pass the ordered splits function..
so first run is orderedPossibleSplits(2, [1]) then orderedPossibleSplits(4, [2])..then orderedPossibleSplits(10, [4])
I then have the master table, and run a lookup for 4 + 4 + 2..to break this down..
This way..I can not only split the generation process over different cpu's..I can spread the combination of the final result over different machines as well..
The problem is, there's a major flaw in my logic(like i said, if there's a 3 in there..or something similar)
hello are you there?
 
6:31 AM
Sorry, phone call.
Anyway, just clear everything in the notebook
 
no problem..thanks...ok I deleted it..
 
Execute Exit[]
 
how do you execute..is it shirt-return?
 
Shift-Enter, yes
 
i tried that and enter and didn't seem to do anything..
okay maybe it worked....
 
6:34 AM
That's alright. Delete everything so that your notebook's blank.
 
ok done
 
You should be doing something like that. Each bracket is what's called a "cell" in Mathematica
The function definition is in one cell. The actual evaluation is in another.
Note that the second cell has an input cell and output cell.
 
wow..cool..i got it to work..
 
In your output cell, you have a list of lists.
 
i took it all before and copied and pasted it..
this time i took the fucntion..hit shift-return and then did it for the command itself and it worked
 
6:37 AM
That's the problem. You should do things in separate cells.
I assume you know how to interpret the output of MakeChange[]?
 
interesting...its very similar to python..so i was followed in operating the same way..sorry about that.
yes..same as my python script..
i understand the result..exact same..
except here's my problem, the function is one big recursion...
 
Okay. I have to leave now for a certain appointment. I'll see if I can get back to you later.
See you.
 
ok thank you..
good bye and thank you...
 

last day (14 days later) »