[Tutor] Actual code that illustrates problem

Kermit Rose kermit at polaris.net
Thu Aug 17 18:13:29 CEST 2006


>>>
 
From: Danny Yoo 
Date: 08/17/06 04:02:35 
To: Kermit Rose 
Cc: Tutor 
Subject: Re: [Tutor] Actual code that illustrates problem 
 
> # def strongfac(z,w): 
[function body cut] 
 
Ok, let's go through this step by step. 
 
* What is the intent of strongfac? 
 
*******
 
To try to find factors of z, using w.
 
>>>
 
* What are the inputs? What is 'z', and what is 'w'? 
 
******
 
z is the number to be factores.
 
w is a "witness", a number that may help find the factors of z.
 
>>>
 
* What are the outputs? What is the return value of strongfac? 
 
****
 
The output is the return value of strongfac.
 
fac = [ x, y, difficulty of factoring z using w]
 
or  
fac = [0,0,0] if strongfac could not factor z using w.
 
 
 
>>>
 
Same questions for fermat(). What are the inputs and outputs, and what's 
the intent? 
 
The input z is the number to be factored.
 
The other inputs are constants which may help in finding factors of z.
 
 
>>>
 
Get those out and documented, because although I think I can guess at it, 
I'd rather know that we are sharing the same understanding. 
 
****
 
????
 
How?
 
 
>>> 
 
There's a bit of code in strongfac() that's nonsensical from a purely 
technical sense. For example: 
 
> # face = [x,y,0] 
[some code cut] 
> # face[0] = x 
> # face[1] = y 
> # face[2] = 0 
 
The three assignments to face[0] through face[2] don't do anything 
effective and clutter the code. 
 
 ***
 
In fact, I knew that.  I inserted it in an attempt to overide the apparent
bug that I saw.
 
Sometimes it worked.
 
>>>
 
In fermat(), there are magic numbers: 
 
# for j in range(2,3): 
^^^^ 
 
# for k in range(100): 
^^^ 
 
These seem pretty arbitrary. Can you explain them? 
 
*****
 
Yes.  These are limits of ranges.  I had not yet evolved the module to
replace the range limits with parameters.
 
>>> 
 
The strongfac() function you have is a good case for writing smaller 
functions: I can not tell where the function really ends. I see that you 
have several sub-tests, which I'll categorize as: 
 
* P-1 
* square = square 
* ... 
 
and there's a few others that I can not categorize yet. But I bet you 
can. Have you considered breaking those out as independent helper 
functions? 
 
 
*****
 
I have considered it. 
 
>>>
 
Most of us don't have experience with number theory. What people here on 
the list have is experience with writing software. My experience informs 
me that the functions you're writing are way too large. They are 
monolithic and imposing enough that very few people will be able to (or 
want to!) understand their reasoning. They really cry out to be broken 
into smaller subtest functions that can be individually understood. 
 
********
 
Luke has promised to work with me to write my module as a class.
 
Perhaps this will automatically shorten the individual functions.
 
I don't expect that you would need to know much number theory to understand
what my program is doing, but I'll be glad to answer any question you may
have of it.
 
 
>>>  
 
You mentioned later that: 
 
> One of the numbers for which strongfac fails to return factors which it 
> correctly calculates is 100000000000037 
 
Two questions: 
 
* How do you know that it is being "correctly calculated?" 
 
****
 
Part of the process of finding  any factor is to divide it into z to get
remainder equal to zero.
 
Also when I noticed the problem, I printed it out in strong fac, and also in
fermat 
and then saw the strange behavior of having one value before return 
and another value after return.
 
>>>
 
* How do you know that your program is doing something wrong? 
 
That is, state explicitely to us what you expected the program to do. 
What is the expected result, in terms of return values, that your function 
failed to produce? What part of the program --- which particular subtest 
--- should have returned those values? Where are you looking at? 
 
 
****
I first noticed it when I had
 
Strong fac calculate the factors if possible.  If it found factors,
 
it printed out that it had found factors using w, and it printed the value
of w.
 
After I noticed that strongfac printed out that it had found factors, but
fermat
did not pick up those factors, I looked more closely.
 
After I had documented to myself that the return value had changed by the
time it got back
to fermat,  I emailed the Tutor list.
 
>>> 
 
Again, you have to assume that we don't know anything about number theory. 
Things that may seem "obvious" to you are not obvious to this audience. 
*grin* 
 
 
****
 
So noted.   I had not intended to ask any number theory questions here.
 
Kermit   <  kermit at polaris.net   >
 
 
 
 
 



More information about the Tutor mailing list