Anonymous avatar Anonymous committed 97eb14d

Add the sources of the Graham-Function presentation to the build system.

This is the first Spork presentation that we are building.

Comments (0)

Files changed (3)

 
 DOCS_COMMON_DEPS = template.wml lib/MyNavData.pm
 
-all: make-dirs docbook_targets fortunes-target latemp_targets sitemap_targets copy_fortunes site-source-install presentations_targets lc_pres_targets art_slogans_targets
+all: make-dirs docbook_targets fortunes-target latemp_targets sitemap_targets copy_fortunes site-source-install presentations_targets lc_pres_targets art_slogans_targets graham_func_pres_targets
 
 include lib/make/gmsl/gmsl
 
 # Uses text-vimcolor from http://search.cpan.org/dist/Text-VimColor/
 $(LC_PRES_DEST_HTMLS): $(T2_DEST)/%.scm.html: t2/%.scm
 	text-vimcolor --format html --full-page $< --output $@
+
+GFUNC_PRES_BASE = lib/presentations/spork/Perl/Graham-Function
+GFUNC_PRES_DEST = $(T2_DEST)/lecture/Perl/Graham-Function
+GFUNC_PRES_BASE_START = $(GFUNC_PRES_BASE)/slides/start.html
+GFUNC_PRES_DEST_START = $(GFUNC_PRES_DEST)/slides/start.html
+
+graham_func_pres_targets: $(GFUNC_PRES_DEST_START)
+
+$(GFUNC_PRES_DEST_START): $(GFUNC_PRES_BASE_START)
+	rsync -a $(GFUNC_PRES_BASE)/slides/ $(GFUNC_PRES_DEST)/slides
+
+$(GFUNC_PRES_BASE_START): $(GFUNC_PRES_BASE)/Spork.slides $(GFUNC_PRES_BASE)/config.yaml
+	(cd $(GFUNC_PRES_BASE) ; \
+		shspork -make ; \
+		(cd slides/ && (for I in *.html ; do tidy -asxhtml -o "$$I".new "$$I" ; mv -f "$$I".new "$$I" ; done)) \
+	)
+

lib/presentations/spork/Perl/Graham-Function/Spork.slides

+----
+presentation_topic: Graham's Function
+presentation_title: Finding Graham's Function Using Perl
+presentation_place: Ramat Gan, Israel
+presentation_date: FILL IN
+----
+
+== The Challenge
+
+    Date: Wed, 11 Dec 2002 15:07:25 -0500
+    From: Mark Jason Dominus
+    Reply-To: perl-qotw-discuss@plover.com
+    To: perl-qotw@plover.com
+    Subject: Perl 'Expert' Quiz-of-the-Week #8
+
+
+    Graham's function (named for Ronald L. Graham, director of research at
+    AT&T Bell Labs) of a positive integer n is computed as follows: Find
+    an increasing sequence of integers a0, a1, ..., a_k such that
+
+            1. a0 = n
+            2. The product of the integers is a perfect square
+            3. a_k is as small as possible.
+
+    Then G(n) = a_k.
+
+    ...
+
+    Write a function, 'Graham', which, given a positive integer n, returns G(n)
+
+----
+== Naive Approach to Solution
+
+* Brute Force
+* Check all the possible series that end with n+1, then those that end with n+2 , then those that end with n+3.
+* Very inefficient. (exponential complexity)
+----
+== Some Analysis
+
+* In a perfect square, all the factors are raised to an even exponent.
+* Thus, when multiplying integers to form a perfect square, what matters is their uneven-exponented factors.
+* Thus, an integer can be represented (as far as we're concerned) as a vector of its squaring factors:
+** 120 = 2^3 * 3^1 * 5^1
+** 120[sq] = 2 * 3 * 5
+* When multiplying two squaring vectors, their components cancel each other. So if p existed in both vectors, it won't exist in the product.
+----
+== Some Linear Algebra Concepts
+
+* By using the Gauss Elimination, we can form a base of the vectors we encountered so far.
+* Using this base we can span every product possible from our group of numbers.
+* If from n+1..m we can span n, it means that m is a valid candidate for the Graham function.
+----
+== My Algorithm
+
+* Keep a base of controlling vectors for each prime number.
+* Keep $n_vec - the vector starting with n[sq] that has to be composed out of the base.
+* As we encounter the next integer $i - 
+00 Get its squaring factors
+00 Check if it's not square or prime (which are useless for us)
+00 Stair-shape it, by multiplying it with the controlling vectors of its factors
+00 Possibly assign it as the controlling vector of the minimal (ID-wise) prime in its stair shape version, and canonize the rest of the base accordingly.
+00 Try to canonize $n_vec.
+* Once $n_vec becomes 0, we stop and return.
+----
+== Optimizations
+* Memoizing the get_squaring_factors() function. 
+* The Memoize.pm module proved to be too heavy, so I used my own memoization code.
+----
+== Largest Factor Optimization
+* Check if between n and n+largest_factor we can fit a square times get_squaring_factors{n*(n+largest_factor)}. If so, return n+largest_factor.
+* If n+largest_factor is factored to largest_factor with an even power, use n+2*largest_factor.
+----
+== Returning the Constructing Series
+* We can keep for each squaring factors vector a vector of its constructing integers.
+* When multiplying the vectors, we can multiply the constructing integers vector in the same way.
+

lib/presentations/spork/Perl/Graham-Function/config.yaml

+################################################################################
+# Spork Configuration File.
+# 
+# Please read this file over and set the values to your own.
+#
+# If you want global settings for all your slideshows, copy this file to
+# ~/.sporkrc/config.yaml. Any settings in this local file will override
+# the global value of that setting.
+# 
+# See C<perldoc Spork::Config> for details on settings.
+################################################################################
+author_name: Shlomi Fish
+author_email: shlomif@iglu.org.il
+author_webpage: http://www.shlomifish.org/
+copyright_string: Copyright &copy; 2005 Shlomi Fish
+
+banner_bgcolor: #FFEED3
+show_controls: 1
+mouse_controls: 0
+image_width: 350
+auto_scrolldown: 1
+logo_image: logo.png
+file_base: /lecture/Perl/Too-Many-Ways/
+
+slides_file: Spork.slides
+template_directory: template/tt2
+template_path: 
+- ./template/tt2
+slides_directory: slides
+download_method: wget
+character_encoding: utf-8
+link_previous: &larr; Previous
+link_next: Next &rarr;
+link_index: Index
+
+start_command: kfmclient openURL slides/start.html
+
+# Change core classes here:
+# formatter_class: Spork::Formatter::Kwid
+
+# Set plugin classes here:
+# plugin_classes:
+# - Spork::S5
+# - Spork::S5Theme
+# - Spork::S5ThemeFlower
+# - Spork::S5ThemeBlackday
+# - Kwiki::PerlBlocks
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.