[jddaniels commit] r161 - in trunk/metamath: . src src/net src/net/ddaniels src/net/ddaniels/metamath src/net/ddanie...

2 views
Skip to first unread message

codesite...@google.com

unread,
Nov 29, 2007, 3:45:06 AM11/29/07
to jddaniels-commit...@googlegroups.com
Author: daniels.douglas
Date: Thu Nov 29 00:35:40 2007
New Revision: 161

Added:
trunk/metamath/.classpath
trunk/metamath/.project
trunk/metamath/src/
trunk/metamath/src/net/
trunk/metamath/src/net/ddaniels/
trunk/metamath/src/net/ddaniels/metamath/
trunk/metamath/src/net/ddaniels/metamath/ch02/
trunk/metamath/src/net/ddaniels/metamath/ch02/HarmonicSeriesSum.java
trunk/metamath/src/net/ddaniels/metamath/common/
trunk/metamath/src/net/ddaniels/metamath/common/Function.java

Log:
Initial import.

Added: trunk/metamath/.classpath
==============================================================================
--- (empty file)
+++ trunk/metamath/.classpath Thu Nov 29 00:35:40 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>

Added: trunk/metamath/.project
==============================================================================
--- (empty file)
+++ trunk/metamath/.project Thu Nov 29 00:35:40 2007
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>metamath</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>

Added: trunk/metamath/src/net/ddaniels/metamath/ch02/HarmonicSeriesSum.java
==============================================================================
--- (empty file)
+++
trunk/metamath/src/net/ddaniels/metamath/ch02/HarmonicSeriesSum.java
Thu Nov 29 00:35:40 2007
@@ -0,0 +1,88 @@
+package net.ddaniels.metamath.ch02;
+
+import net.ddaniels.metamath.common.Function;
+
+public class HarmonicSeriesSum {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ int[] a = new int[3];
+ Function<Integer, Double>[] functions = new Function[3];
+ functions[0] = new HarmonicSeriesFunction();
+ functions[1] = new OneEighthSeriesFunction();
+ functions[2] = new OneHalfSeriesFunction();
+
+ double[] sums = new double[3];
+ int NUM_TERMS = 1000;
+ for(int j=0; j<functions.length; j++) {
+ System.out.print("Series["+functions[j]+"]: ");
+ for (int i = 1; i <= NUM_TERMS; i++) {
+ double term = functions[j].eval(i);
+ System.out.print("1/"+(int)(1/term)+" + ");
+ sums[j] += term;
+ }
+ System.out.println("...");
+ }
+
+ for(int j=0; j<functions.length; j++) {
+ System.out.println("Sum of series ["+functions[j]+"] for
["+NUM_TERMS+"] number of terms == "+ sums[j]);
+ }
+
+ }
+
+}
+
+class HarmonicSeriesFunction implements Function<Integer, Double> {
+
+ @Override
+ public Double eval(Integer x) {
+
+ return 1.0d/x.doubleValue();
+ }
+
+}
+
+
+/**
+ * Generates the series:
+ * 1 + 1/2 + 1/4 + 1/4 + 1/8 + 1/8 + 1/8 + 1/8....
+ * @author ddaniels
+ *
+ */
+class OneEighthSeriesFunction implements Function<Integer, Double> {
+
+ @Override
+ public Double eval(Integer x) {
+ switch(x.intValue()) {
+ case 1:
+ return 1d;
+ default:
+ double log2ofX = Math.log10(x)/Math.log10(2);
+ //Ceiling the log to the nearest power of 2 rounded up
+ log2ofX = Math.ceil(log2ofX);
+ double pow2OfX = Math.pow(2, log2ofX);
+ return 1d/pow2OfX;
+
+ }
+
+ }
+
+}
+
+class OneHalfSeriesFunction implements Function<Integer, Double> {
+
+ @Override
+ public Double eval(Integer x) {
+ switch(x.intValue()) {
+ case 1:
+ return 1d;
+ default:
+ return 1d/2d;
+
+ }
+
+ }
+
+}
\ No newline at end of file

Added: trunk/metamath/src/net/ddaniels/metamath/common/Function.java
==============================================================================
--- (empty file)
+++ trunk/metamath/src/net/ddaniels/metamath/common/Function.java Thu
Nov 29 00:35:40 2007
@@ -0,0 +1,5 @@
+package net.ddaniels.metamath.common;
+
+public interface Function<From, To> {
+ public To eval(From x);
+}

Reply all
Reply to author
Forward
0 new messages