Re: Wrong-but-not-incorrect code
From: Richard Harter (cri_at_tiac.net)
Date: 03/21/05
- Next message: s.subbarayan: "Re: Dynamic memory allocation and memory leak..."
- Previous message: Walter Roberson: "Re: Dynamic function generation"
- In reply to: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Next in thread: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Reply: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Mar 2005 04:43:55 GMT
On Sun, 20 Mar 2005 22:36:50 +0000, Chris Croughton
<chris@keristor.net> wrote:
>On 20 Mar 2005 18:11:55 GMT, Michael Wojcik
> <mwojcik@newsguy.com> wrote:
>
>>
>> In article <423d513a.298652081@news.sbtc.net>, cri@tiac.net (Richard Harter) writes:
>>>
>>> more simply 10a+b=0%7 => 10a-20b%7 => a-2b=0%7
>>
>> Thanks, Richard - that's a lot simpler than my version (though you
>> accidentally left out the "=0" in the second step). Still, I'm happy
>> to have puzzled it out on my own.
>
>I understood yours!
>
>> If anyone doesn't understand the second step, note that -20 is
>> congruent to 1 mod 7. (-20 plus 21 = 1.) That means multiplying by
>> -20 is the same as multiplying by 1, as far as congruence modulo 7
>> goes, so we can freely multiply b by -20. And we choose -20 because
>> it's the closest multiple of 10 that's 1 mod 7, so that we can divide
>> out the common factor 10 and simplify the LHS of the equation.
>
>Ah, thanks, I wondered where the 20 came from. I'm not happy about
>factoring out the 10 in the last step, though, is that valid in modulo
>arithmetic? 14 % 7 == 0, but 1.4 % 7 == 1.4, no?
Good question. In this instance, yes. 10 and 7 are relatively prime,
so 10 has an inverse modulo 7. (The inverse is 5) We can multiply
both sides by the inverse, which is equivalent to dividing both sides
by 10.
For an example where you can't cancel, take
2x = 0 %6
Cancelling gives us x=0, but x=3 is also a valid solution.
1.4 isn't an integer. The rules for modular arithmetic don't all
apply to non integers.
>
>> (Clearly I should have started with the modular algebra and not with
>> drawing up tables of congruences, then working backward from those...)
>
>Doing it multiple ways confirms the correctness...
>
>Chris C
Richard Harter, cri@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
All my life I wanted to be someone;
I guess I should have been more specific.
- Next message: s.subbarayan: "Re: Dynamic memory allocation and memory leak..."
- Previous message: Walter Roberson: "Re: Dynamic function generation"
- In reply to: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Next in thread: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Reply: Chris Croughton: "Re: Wrong-but-not-incorrect code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|