Talk:Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

m
 
(11 intermediate revisions by 4 users not shown)
Line 15:
:::[[http://calculator.tutorvista.com/math/418/quotient-remainder-calculator.html]] says the Quotient is -2 and the Remainder is -74. So let's hope the students being tutored never have to divide negative rational numbers. I'd have to pay for tutoring to get an explanation, so I won't bother (though there is a money back guarantee if I'm not satisfied, and I can't see how I would be). [http://blogs.msdn.com/b/ericlippert/archive/2011/12/05/what-s-the-difference-remainder-vs-modulus.aspx what-s-the-difference-remainder-vs-modulus.aspx] gives a good explanation of the difference between remainer and modulus functions, (% in ruby is a modulus function). Quoting from [http://blogs.msdn.com/b/ericlippert/archive/2011/12/05/what-s-the-difference-remainder-vs-modulus.aspx what-s-the-difference-remainder-vs-modulus.aspx] "The net result here is that integer division rounds towards zero. That should make sense; we want 123/4 to be 30 with a remainder of 3, not 31 with a remainder of -1. Similarly, we want -123/4 to be -30, not -31! It would be bizarre to say that 4 goes into 123 30 times but goes into -123 -31 times! One expects that changing the sign of a term changes the sign of the result; it does not change the magnitude of the result." I think the other result comes from a linguistic extension of Euclid's algorithm with no consideration for the "bizarre" mathematical logic resulting. So my view remains:
::::151/77 is 1 remainder 74 and is [1;1,24,1,2]
::::-151/77 is -1 remainder -74 (not -2 remainder 3) and is [-1;-1,-24,-1,-2] or -[1;1,24,1,2] (not [-2;25,1,2])
:::the other definition works, but is it pretty or pretty bizzare?--[[User:Nigel Galloway|Nigel Galloway]] 13:27, 12 March 2013 (UTC)
 
:::: My point is that there is no guarantee that a sequence is actually unique. The fundamental issue is that there are two ways of solving the integer division problem when extending into producing negative results: one states that the sign is an indication of the sign of the inputs, and the other states that division is about partitioning the number line and indicating which partition. (Alternatively, one definition of integer division uses round-to-zero and the other uses round-down rules when converting from a non-integer intermediate result; I've never heard of a universally-accepted definition of which of those two is right.) As long as <math>a = b\times (a/b) + (a\%b)</math> is true, mathematical sanity is maintained. Different languages have different rounding rules. (BTW, [[C]] prior to C99 has implementation-defined rounding rules[http://stackoverflow.com/q/3602827/301832]. With [[C++]], I think C++11 is the first revision of the standard to define this clearly[http://stackoverflow.com/q/319880/301832].) –[[User:Dkf|Donal Fellows]] 15:24, 12 March 2013 (UTC)
 
::::: Is your point that you want the task defining so that it has a unique solution? I have shown that both are used in other places so it is dificult to say one is right. Interestingly that which [[User:Spoon!|Spoon!]] says above is true for Python2 but Python3 returns a floating point. So if I define Q/R as A remainder B where A=trunc(Q/R) and B=Q-A*R Python2 will produce your answer and Python3 will produce the better answer. How cool is that? UberKool or what? A killer reason to upgrade to Python3!!!--[[User:Nigel Galloway|Nigel Galloway]] 12:50, 13 March 2013 (UTC)
 
== Marking as draft ==
 
I am marking this task as draft for reasons similar to [[Talk:Continued_fraction/Arithmetic/G(matrix_NG,_Contined_Fraction_N)#Marking_as_.22draft.22]] --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 10:31, 9 July 2015 (UTC)
 
Also note that the code here (for example in the C++ implementation) is incomplete, as is the task description. To solve this, you need to know which rosettacode tasks contain the missing task description and how to adapt the code there to work here. (That may be simple - I do not know yet.)
 
Specifically, the task lacks a specific terminating condition. And the C++ implementation uses a .moreTerms() method which is not included in the implementation here. Meanwhile [[Continued_fraction/Arithmetic/G(matrix_NG,_Contined_Fraction_N)]] has an "I am done when" clause in the task description and code which won't compile without the NG_8 implementation here (unless you remove that reference) and an implementation of the .moreTerms() method. Also the c++ implementation there (and here) has a further [currently undocumented] dependency on code in the task [[Continued_fraction_r2cf(Rational_N)]].
 
This is a somewhat depressing state of affairs - implementations should not be this incomplete -- users should not have to puzzle out which other rosetta code tasks they need to extract code from to debug an implementation. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 11:44, 11 July 2015 (UTC)
 
: Have added some links to the C++ entry, since no-one else was ever going to. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 19:37, 17 August 2020 (UTC)
 
:The main thing is that G, NG, matrixNG, N1, N2, NG4, and NG8 are quite ridiculous names, it would actually be better or at least less misleading if they were changed to Galloway, NigelGalloway, matrixNigelGalloway, Nigel1, Nigel2, NigelGalloway4 and NigelGalloway8. (Ha-Bloody-Ha). And Yes, that would also include moving things to two new pages names of<br>
:Continued_fraction/Arithmetic/Galloway(matrix_NigelGalloway,_Contined_Fraction_Nigel), and<br>
:Continued_fraction/Arithmetic/Galloway(matrix_NigelGalloway,_Contined_Fraction_Nigel1,_Contined_Fraction_Nigel2)
 
:Hopefully my latest Phix entry will help clarify/suggest better names for things.
 
:As noted, the scatterbox over several (inadequately linked) pages issue also needs addressing. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 14:18, 18 August 2020 (UTC)
 
==Rename/rewrite Suggestion==
The above two tasks should be renamed as simply "Continued_fraction/Arithmetic/Unary" and "Continued_fraction/Arithmetic/Binary", and
read more like this (for "Binary"):
 
Perform arbitrary mathethatical operations on two continued fractions, such as +, -, *, and /.
 
The suggested approach is to write a function/class/method apply_full_matrix(ctrl,cf1,cf2) which takes a 2x4 control array and two continued fractions, and yields a continued fraction result. Assume ctrl is eight plain integers of the form
{{ a12, a1, a2, a },
{ b12, b1, b2, b }}
 
Then the result of apply_full_matrix(ctrl,cf1,cf2) would be
 
(a12*cf1*cf2 + a1*cf1 + a2*cf2 + a)
-----------------------------------
(b12*cf1*cf2 + b1*cf1 + b2*cf2 + b)
 
For instance:
{{ 0, 1, 1, 0}, calculates cf1 + cf2
{ 0, 0, 0, 1}} (divided by 1)
 
{{ 0, 1,-1, 0}, calculates cf1 - cf2
{ 0, 0, 0, 1}} (divided by 1)
 
{{ 1, 0, 0, 0}, calculates cf1 * cf2
{ 0, 0, 0, 1}} (divided by 1)
 
{{ 0, 1, 0, 0}, calculates cf1
{ 0, 0, 1, 0}} divided by cf2
 
If a12,a1,b12,b1 are all 0 then cf1 is not required/referenced and apply_fm() could accept some form of dummy/null value for it.<br>
If a12,a2,b12,b2 are all 0 then cf2 is not required/referenced and apply_fm() could accept some form of dummy/null value for it.<br>
Such cases are covered by a "baby" 2x2 control matrix in <nowiki>[["Continued_fraction/Arithmetic/Unary"]]</nowiki>
(currently named/located as [[Continued_fraction/Arithmetic/G(matrix_NG,_Contined_Fraction_N)]])
and it should (in theory) be perfectly possible to use this full form to replicate those results.
 
If b12,b1,b2,b are all zero we are done (presumably if that was initial state we end up with no terms, corresponding to undefined/error/divide by zero).<br>
If a12,a1,a2,a are initially all zero the result should be zero.<br>
If a12,a1,a2,b12,b1,b2 are all zero then neither cf1 nor cf2 are required and the result is the constant fraction a/b (but in
continued fraction format). In effect we define apply_fm() as operations on ctrl which (eventually) make a12..b2 zero so that we
can then simply read the (rest of the) result from a and b.
 
At that point I ran out of steam... Maybe this can be finished(/tweaked here) in small steps? --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 14:18, 18 August 2020 (UTC)
10,327

edits