I'm using J notation as notation for basic modular arithmetic. The standard mathematical notation for congruence is three horizontal bars. (In the example here that character is between the first two integers.) An example assertion of congruence:
38 ≡ 14 (mod 12) The same example in J: 38 14 cgt 12 1 given: cgt =: [: =/ |~ NB. Items of x are congruent, modulo y if all values are integers, the left parameter is a pair of values, and the right parameter is scalar. My problem at the moment is actually a domain difficulty, not a coding problem. I want to also write a verb for modular equality. Doing so will allow the following contrast: 38 14 cgt 12 NB. items of x are congruent modulo y 1 38 14 meq 12 NB. items of x are non-equal modulo y 0 The falsity of the second statement can be understood from this: [begin quotation] Equality implies specifically the "common residue", the least non-negative member of an equivalence class. [end quotation] For the example at hand, that common residue is 2: 12 | 38 14 2 2 The quotation is from the Wikipedia article on modular arithmetic, in the section Remainders. http://en.wikipedia.org/wiki/Modular_arithmetic#Remainders If I may be allowed a non-J question, I'm looking for help determining what the left parameter must satisfy in order for verb meq to return true. I'm sure one of the pair must be the common residue, but I don't know whether order matters. The last sentence of the first paragraph in the section I quoted from may be flawed, but I'm not qualified to fix it. If there is no ordering requirement and I've not otherwise misappraised modular equality, it can be coded so: meq =: [ ((e.~ <./) * [:=/]) |~ -- Tracy B. Harms A good programming language is a conceptual universe for thinking about programming. Alan Perlis ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
