Re: Triggering on exception conditions
- To: mathgroup at smc.vnet.net
- Subject: [mg128367] Re: Triggering on exception conditions
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Wed, 10 Oct 2012 01:25:32 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20121009043747.A0201687A@smc.vnet.net>
data1 = With[{h = 20}, Module[{y}, Table[y = PowerMod[k, -1, h]; {Mod[k, h], If[FreeQ[y, PowerMod], y, 0]}, {k, 1, h - 1}]]] // Quiet {{1, 1}, {2, 0}, {3, 7}, {4, 0}, {5, 0}, {6, 0}, {7, 3}, {8, 0}, {9, 9}, {10, 0}, {11, 11}, {12, 0}, {13, 17}, {14, 0}, {15, 0}, {16, 0}, {17, 13}, {18, 0}, {19, 19}} data2 = With[{h = 20}, Module[{y}, Table[y = PowerMod[k, -1, h]; {Mod[k, h], y*Boole[FreeQ[y, PowerMod]]}, {k, 1, h - 1}]]] // Quiet; data3 = With[{h = 20}, Module[{y}, Table[y = PowerMod[k, -1, h]; {Mod[k, h], If[NumericQ[y], y, 0]}, {k, 1, h - 1}]]] // Quiet; data4 = With[{h = 20}, Module[{y}, Table[y = PowerMod[k, -1, h]; {Mod[k, h], y*Boole[NumericQ[y]]}, {k, 1, h - 1}]]] // Quiet; data1 == data2 == data3 == data4 True Bob Hanlon On Tue, Oct 9, 2012 at 12:37 AM, Lorenz <lorenz.mueller at bluewin.ch> wrote: > Assume I have a statement like > Table[ {Mod[k, h], PowerMod[k, -1, h]}, {k, 1, h - 1}] > How can I select the elements in the table which fullfill the condition > PowerMod::ninv: 2 is not invertible modulo xxx > > I would like a statement with a form like > If[PowerMod[2, -1, h] == ninv, 1, 0] > but this does not work. > > More general how to catch exceptions in calculation for each type of exception condition, eg in this case PowerMod::ninv >
- References:
- Triggering on exception conditions
- From: Lorenz <lorenz.mueller@bluewin.ch>
- Triggering on exception conditions