ESP

# Usage of Blockly in integer factorization calculator

by Dario Alejandro Alpern

## Transcription

Hello everybody. Today I will show you the second part of the tutorial of the integer factorization calculator.

You can see that big numbers are shown in groups of 6 digits. This can be changed by pressing the Config button.

We have to change the number 6 by 10 in the Digits per group input box. Then we press the Save button.

The next time we press the Factor button we will see the big numbers in groups of 10 digits. If you need the numbers not to be grouped, just enter zero in the input box.

The Pretty print checkbox in the configuration window allow us to view the output like a textbook.

When pretty print is enabled, the multiplication sign is like an x letter and for exponentiation, the exponent is smaller and placed higher than the base.

When pretty print is disabled, the multiplication sign is an asterisk, and the exponentiation sign is a caret. This is useful to copy the output to other math programs.

Verbose mode shows how the factor was found: by the Elliptic Curve Method, by the Self-Initializing Quadratic Sieve, by division, or other methods.

When the hexadecimal output checkbox in the configuration window, all output is presented in hexadecimal, even the number of divisors. In our example there are 32 divisors, so the output is 20, which is 32 in hexadecimal.

The numbers in hexadecimal are represented in monospaced font.

We can see the divisors in hexadecimal by pressing the button Show divisors.

When the use Cunningham tables in server checkbox is enabled, the calculator uses a table located in the Web server of more than 2 million different numbers of the form a to the b plus or minus 1 with the factorization already done. If the numbers are too big, only partial factorization in prime numbers is done.

In this example, we will factor the 91-digit number 2 to the 301 minus 1. We can see all 128 divisors. Since they are very large, they require two lines to be completely shown.

Now we will see how to use the Wizard to find Smith numbers.

Smith numbers are composite numbers such that the sum of digits of n equals the sum of digits of prime factors of n, counting multiplicity.

There are two functions included in the calculator: sumdigits, which calculates the sum of digits of the argument, and concatfact, which generates a number composed by the prime factors of the argument. When the first argument is 2, it repeats the factors when they are multiple. For example, if the second factor is 36 which equals 2 squared times 3 squared, we get the number 2233.

Now we will review the expression marked in red.

It says that the sum of digits of x equals the sum of digits of the repeated factors of x. Then it says that the number must not be prime.

Now we will use the Wizard by pressing its button. using a series of dialogs, it will generate the code needed to show Smith numbers up to 10000.

You will see that below the area where we type the numbers, the calculator shows all operators and functions supported.

Now we will select Process several expressions in a loop. The loop uses a variable x that will hold in this case the number to be tested.

The initial value of x will be 1, the next will be 2 and so on, up to 10000. So, we will enter 1 as the initial value.

The second screen asks us how to compute the next value of x from the previous one. Since we will test all natural numbers, we will enter x plus 1.

The end loop condition instructs the calculator when the loop must continue. In our case it will continue when x is less than 10000. So, we will enter that in the input box.

The expression to factor will be x. Notice that if later we press the Only evaluate button, just the Smith numbers would appear on screen.

When the process expression condition evaluates as true, the expression typed in the previous dialog will be shown or factored, depending on the button pressed. So now we will enter the expression found when we talked about the Smith numbers.

After the Wizard finishes, the loop expression appears in the input box. Note that the loop expression has four or five expressions separated by semicolons. If there are four of them, the last expression, the expression to factor is always executed. But we have five expressions, so the fourth expression is only executed when the last expression is true.

After pressing the Only evaluate button, we will see the Smith numbers less than 10000.

You can process many expressions at a time by using the button From file.

Here we can see the contents of the file to be processed. There is a number, an expression or a loop expression per line.

After selecting the file to open, you will need to press one of the three buttons Only evaluate, Prime or Factor. After pressing one of them, a button will appear below that allow us to save the results in a file.

The name of the file is the same as the input file, but the data will be saved in the directory where the Web browser saves downloaded files.

Here we can see at the left the original file and at the right the file generated by the calculator.

I am highlighting both input and output.

This is the end of the second part of the tutorial. I hope this is useful for you.