Radical Language Modification

Hey all, I'm playing around with bignums again...

I just realized I could do something cool and make code that looks like this:

d = a + b (mod c);

...where only b (and, of course, d) need be a biginteger.

...and where it does just what it looks like it should. :O)

The only problem is that... I'd have to... #define mod

Yeah, there, I said it.

Reasonable for pretty vanities? Or am I just too tired to think straight?
closed account (Dy7SLyTq)
so is mod an operator then? and whats its role? does it perform the mod() function or is it like modulus?
closed account (Dy7SLyTq)
wow that is cool
I'm confused on 2 things.

The weird parenthesis placement is the main one. Are you modding b? Or (a+b)?

And secondly... why would mod have to be a macro? Why couldn't you do the same with d = (a + b) % c;?

bigint operator + (int, bigint)
bigint operator % (bigint, int)

Or am I missing something?
The standard mathematical notation is that

    a ≡ b (mod c)

and is read "a is congruent to b mod c".

This kind of stuff is actually useful, though it is most enjoyable when you play with Number Theory.

A common algorithm is to compute

    Y ≡ Gx (mod P)

for cryptographic uses.

Other basic uses include the Chinese Remainder Theorem, etc.

To answer your question, yes, I could write d = (a + b) % c. But with big numbers time is often a factor. There are often ways to compute the answer more quickly than the straightforward method.

By overloading a biginteger () operator to play nice, I can use those functions while allowing a natural (mathematically speaking) syntax.

There are all kinds of ways to apply the optimized algorithms over the standard ones:

d = a.add_mod( b, c );  // single function call

d = a.add( b ).mod( c );  // stack-based delayed eval

d = (a + b).mod( c );  // same

d = a + b (mod c);  // oooh! pretty! 

The whole trick, of course, is that the argument to b() is two lexemes... "mod" and "c", one of which must evaluate to more or less nothing. I know of no other way to do RLM without macros.

Your response is telling me that it is probably a bad idea...
¿So how is a + b(c) actually computing (a+b)(c)?
Stack-based-delayed evaluation. b(c) returns a temp object.

Yeah, I know it was a dumb idea... It sure looked pretty, though.

No matter what you know, the temptation to do something stupid will always come.
Last edited on
Topic archived. No new replies allowed.