String around my finger

This post is in case I forget how to convert Sage’s list comprehension in the if loop to Magma, and also a potential tool for other noobs out there who shuttle between programming in Sage and programming in Magma. One common check used in the industry to verify that your code works is to program it in one language, and then reprogram it in another language to get the same output. Pretty much the same as Combinatorics – counting things one way, and then counting them another way to make sure that both counts arrive at the same value and that your count is correct.

So Sage has really awesome list comprehension (much more advanced than most other languages) in that you can include a for loop in your if condition, i.e. you can do something like this:
if (i > 199 for i in [201 .. 300]):
    print "Success!"

For about an hour today I was trawling the web looking for how to do the exact same thing in Magma and most of my usual google keywords returned zilch. Such as, “list comprehension Magma”, or “Magma if for”, or “Magma for loop in if condition”, or “Magma if (for i in [“, After scanning through this helpful manual for a few minutes I stumbled upon Existential and Universal Quantifiers (pg 127) – which shows that the correct conversion for the above Sage expression to Magma would thus be
if forall{i : i in [201 .. 300] | i gt 199} then
    "Success!";
end if;

Note that the forall is a conditional statement, which returns 0 or 1 in Magma. Conditional statements in Sage return True or False (NOT integers!), and can be converted to 0 or 1 by using int(Conditional(arg1,arg2,...))

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...