Meng Xuan Xia

  • Home

  • Archives

  • Tutoring

  • Projects

  • About

  • Tags

Math 240 Discrete Mathematics - Primality Testing

Posted on 2012-10-17 | In Math 240 | Comments:
Symbols count in article: 1.2k | Reading time ≈ 1 mins.

Primality Testing - The Idea

To decide if a number $m$ is prime, check if $m \mid 2^{m-1}-1$

  • if yes, answer “$m$ is prime”
  • if no, answer “$m$ is not prime”

This test doesn’t always work

Example: $m=341=31\cdot11$ The test gets this wrong

Claim: $341\mid(2^{340} -1)$

Show that

  1. $31\mid (2^{240}-1)$

let $x=2^5$ then $31=x-1$ and $2^{340} - 1 = x^{68} -1 = (x-1)(1+x+x^2+\dots+x^{67}) = 31 \cdot (something)$

  1. $11\mid (2^{340}-1)$

By Fermat’s Little theorem: $ 11 \mid (2^{10}-1)$

and write $2^{340} - 1$ as a multiple of $2^{10}-1$ $2^{340} - 1 = (2^{10} -1 ) (1+2^{10} \cdot (2^{10})^2 + \dots +(2^{10})^{34})$ So $11 \mid (2^{340} -1 ) $

$\therefore 341 \mid (2^{340} -1 )$

If I had choosen $a=3$ instead, the test may work for 341 but would fail for some other number. We can’t just use 2 to test the number and we can’t always use 3. We have to test all possible number of $a$ to know whether number $m$ is prime.

Fact: A interger m is prime if and only if for any $1<a\leq m-1$ \[ m \mid (a^{m-1} -1) \]

Fermat Test

Refer to wikipedia for the concept and application of Fermat's primality test_

_Fermat's primality test:https://en.wikipedia.org/wiki/Fermat\_primality\_test

Guide: Optimize boot speed using e4rat on fedora 17

Posted on 2012-10-06 | In fedora | Comments:
Symbols count in article: 2.2k | Reading time ≈ 2 mins.

This post covers the installation and usage of e4rat on fedora 17.

Some Background

Tohie commented on Fedora 17 Boot Optimization(from 15 to 2.5 seconds). that using e4rat. may further increase booting speed. Most steps from Fedora 17 Boot Optimization aren’t useful for me mainly because I installed my system on LVM configuration. Those services Harald disabled are essential on my system.

Before installation

Make sure you have these dependencies installed.

$ sudo yum install groupinstall “Development Tools”

$ sudo yum install libstdc++-static bzip2-devel boost-devel boost-static boost-regex e2fsprogs-devel audit-libs-static audit-libs-devel

Download the source code and extract. Edit CMakeLists.txt found from the the extracted file. Find set(Boost_USE_STATIC_LIBS ON) and set it to set(Boost_USE_STATIC_LIBS OFF).This is necessary because the default static build of Boost does not contain boost-regex, which is required by e4rat.

Installation

In the e4rat source directory, run

$ cmake . -DCMAKE_BUILD_TYPE=release

$ make

$ sudo make install

Collecting log

e4rat-collect can not be started when auditd is started. So first, we need to disable auditd.

$ sudo systemctl disable auditd.service

Reboot your machine and when grub appears, hit e to edit the boot script. append init=/sbin/e4rat-collect to your kernel parameters. Then hit Control-X to boot. After fedora booted, login and start your normal routine. 2 minutes after booting, e4rat-collect terminated and generated file list is stored at /var/lib/e4rat/startup.log

Reallocate boot files

then run

$ sudo init 1

to get into single user mode

Reallocate boot files with

e4rat-realloc /var/lib/e4rat/startup.log

Setup preload

Edit your default kernel parameters in /etc/default/grub: Append init=/sbin/e4rat-preload to the line kernel parameters defined in GRUB_CMDLINE_LINUX. Then runL

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Enable previously disabled auditd

$ sudo systemctl enable auditd.service

Reboot fedora again and you should be able to benefit from e4rat.

.. _Fedora 17 Boot Optimization(from 15 to 2.5 seconds): http://www.harald-hoyer.de/personal/blog/fedora-17-boot-optimization-from-15-to-3-seconds .. _e4rat: http://e4rat.sourceforge.net/

Math 240 Discrete Mathematics - Overview

Posted on 2012-09-05 | In Math 240 | Comments:
Symbols count in article: 456 | Reading time ≈ 1 mins.

Overview

  1. How to think mathematically, particularily about finite systems

  2. How to write down mathematical arguments

Some topics

  • What does it mean to prove something?
  • What does it mean for a mathematical procedure (algorithm) to be efficient?
  • $ 168031584 = 2^5 \times 3^7 \times 7^4 $
  • Which is easier? Finding the left side given the right?
  • Which is easier? Finding the left side given the left?
  • Could we also have $2^3 \times 19 \times 15 \times 7321$ ?
1…1516

Meng Xuan Xia

Blog posts on math, computer science, software development and NLP.

78 posts
5 categories
82 tags
RSS
Github
© 2013 – 2022 Meng Xuan Xia | 225k | 3:25