From: Thomas Walker Lynch Date: Fri, 10 Jan 2025 05:18:23 +0000 (+0000) Subject: SRM->SRTM examples into their own directories X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.js?a=commitdiff_plain;h=5c89c6f55d62b22830ecba161bae089a816e1dd6;p=Ariadne SRM->SRTM examples into their own directories --- diff --git a/developer/example/CountingNumber$ASRM_Infinite.class b/developer/example/CountingNumber$ASRM_Infinite.class deleted file mode 100644 index 4ce6eae..0000000 Binary files a/developer/example/CountingNumber$ASRM_Infinite.class and /dev/null differ diff --git a/developer/example/CountingNumber$ASRM_Null.class b/developer/example/CountingNumber$ASRM_Null.class deleted file mode 100644 index 90190a8..0000000 Binary files a/developer/example/CountingNumber$ASRM_Null.class and /dev/null differ diff --git a/developer/example/CountingNumber$ASRM_Rightmost.class b/developer/example/CountingNumber$ASRM_Rightmost.class deleted file mode 100644 index 663d38b..0000000 Binary files a/developer/example/CountingNumber$ASRM_Rightmost.class and /dev/null differ diff --git a/developer/example/CountingNumber$ASRM_Segment.class b/developer/example/CountingNumber$ASRM_Segment.class deleted file mode 100644 index 91da239..0000000 Binary files a/developer/example/CountingNumber$ASRM_Segment.class and /dev/null differ diff --git a/developer/example/CountingNumber.class b/developer/example/CountingNumber.class deleted file mode 100644 index 7e2f76b..0000000 Binary files a/developer/example/CountingNumber.class and /dev/null differ diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java deleted file mode 100644 index cbfc6b9..0000000 --- a/developer/example/CountingNumber.java +++ /dev/null @@ -1,140 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import java.math.BigInteger; - -public class CountingNumber extends Ariadne_SRM{ - - public static CountingNumber make(BigInteger maximum){ - return new CountingNumber(maximum); - } - - public static CountingNumber make(){ - return new CountingNumber(); - } - - private BigInteger i; - private BigInteger maximum; - - private final TopoIface state_null = new ASRM_Null(); - private final TopoIface state_segment = new ASRM_Segment(); - private final TopoIface state_rightmost = new ASRM_Rightmost(); - private final TopoIface state_infinite = new ASRM_Infinite(); - - public CountingNumber(){ - this.i = BigInteger.ONE; - this.maximum = maximum; - set_topology(state_infinite); - } - - public CountingNumber(BigInteger maximum){ - this.i = BigInteger.ONE; - this.maximum = maximum; - - if( maximum.compareTo(BigInteger.ZERO) <= 0 ){ - set_topology( state_null ); - return; - } - - if( maximum.equals(BigInteger.ONE) ){ - set_topology(state_rightmost); - return; - } - - set_topology(state_segment); - } - - - private class ASRM_Null implements TopoIface{ - @Override - public boolean can_read(){ - return false; - } - @Override - public BigInteger read(){ - return i; - } - @Override - public boolean can_step(){ - return false; - } - @Override - public void step(){ - throw new UnsupportedOperationException( "Cannot step from NULL state." ); - } - @Override - public Topology topology(){ - return Topology.NULL; - } - } - - private class ASRM_Segment implements TopoIface{ - @Override - public boolean can_read(){ - return true; - } - @Override - public BigInteger read(){ - return i; - } - @Override - public boolean can_step(){ - return true; - } - @Override - public void step(){ - i = i.add( BigInteger.ONE ); - if( i.equals( maximum ) ){ - set_topology( state_rightmost ); - } - } - @Override - public Topology topology(){ - return Topology.SEGMENT; - } - } - - private class ASRM_Rightmost implements TopoIface{ - @Override - public boolean can_read(){ - return true; - } - @Override - public BigInteger read(){ - return i; - } - @Override - public boolean can_step(){ - return false; - } - @Override - public void step(){ - throw new UnsupportedOperationException( "Cannot step from RIGHTMOST." ); - } - @Override - public Topology topology(){ - return Topology.RIGHTMOST; - } - } - - private class ASRM_Infinite implements TopoIface{ - @Override - public boolean can_read(){ - return true; - } - @Override - public BigInteger read(){ - return i; - } - @Override - public boolean can_step(){ - return true; - } - @Override - public void step(){ - i = i.add( BigInteger.ONE ); - } - @Override - public Topology topology(){ - return Topology.INFINITE; - } - } -} diff --git a/developer/example/CountingNumber/CountingNumber.java b/developer/example/CountingNumber/CountingNumber.java new file mode 100644 index 0000000..11ce61c --- /dev/null +++ b/developer/example/CountingNumber/CountingNumber.java @@ -0,0 +1,140 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import java.math.BigInteger; + +public class CountingNumber extends Ariadne_SRMT{ + + public static CountingNumber make(BigInteger maximum){ + return new CountingNumber(maximum); + } + + public static CountingNumber make(){ + return new CountingNumber(); + } + + private BigInteger i; + private BigInteger maximum; + + private final TopoIface state_null = new ASRMT_Null(); + private final TopoIface state_segment = new ASRMT_Segment(); + private final TopoIface state_rightmost = new ASRMT_Rightmost(); + private final TopoIface state_infinite = new ASRMT_Infinite(); + + public CountingNumber(){ + this.i = BigInteger.ONE; + this.maximum = maximum; + set_topology(state_infinite); + } + + public CountingNumber(BigInteger maximum){ + this.i = BigInteger.ONE; + this.maximum = maximum; + + if( maximum.compareTo(BigInteger.ZERO) <= 0 ){ + set_topology( state_null ); + return; + } + + if( maximum.equals(BigInteger.ONE) ){ + set_topology(state_rightmost); + return; + } + + set_topology(state_segment); + } + + + private class ASRMT_Null implements TopoIface{ + @Override + public boolean can_read(){ + return false; + } + @Override + public BigInteger read(){ + return i; + } + @Override + public boolean can_step(){ + return false; + } + @Override + public void step(){ + throw new UnsupportedOperationException( "Cannot step from NULL state." ); + } + @Override + public Topology topology(){ + return Topology.NULL; + } + } + + private class ASRMT_Segment implements TopoIface{ + @Override + public boolean can_read(){ + return true; + } + @Override + public BigInteger read(){ + return i; + } + @Override + public boolean can_step(){ + return true; + } + @Override + public void step(){ + i = i.add( BigInteger.ONE ); + if( i.equals( maximum ) ){ + set_topology( state_rightmost ); + } + } + @Override + public Topology topology(){ + return Topology.SEGMENT; + } + } + + private class ASRMT_Rightmost implements TopoIface{ + @Override + public boolean can_read(){ + return true; + } + @Override + public BigInteger read(){ + return i; + } + @Override + public boolean can_step(){ + return false; + } + @Override + public void step(){ + throw new UnsupportedOperationException( "Cannot step from RIGHTMOST." ); + } + @Override + public Topology topology(){ + return Topology.RIGHTMOST; + } + } + + private class ASRMT_Infinite implements TopoIface{ + @Override + public boolean can_read(){ + return true; + } + @Override + public BigInteger read(){ + return i; + } + @Override + public boolean can_step(){ + return true; + } + @Override + public void step(){ + i = i.add( BigInteger.ONE ); + } + @Override + public Topology topology(){ + return Topology.INFINITE; + } + } +} diff --git a/developer/example/CountingNumber/Example_CountingNumber_0.java b/developer/example/CountingNumber/Example_CountingNumber_0.java new file mode 100644 index 0000000..48ec99b --- /dev/null +++ b/developer/example/CountingNumber/Example_CountingNumber_0.java @@ -0,0 +1,37 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import java.math.BigInteger; + +public class Example_CountingNumber_0{ + + protected static void print_ten(CountingNumber n){ + System.out.println("Iterating through Counting Numbers:"); + + if( !n.can_read() ) return; + + if( n.topology() == Ariadne_SRMT.Topology.SEGMENT ){ + do{ + System.out.println("Current Number: " + n.read()); + if( !n.can_step() ) break; + n.step(); + }while( true ); + + }else if( n.topology() == Ariadne_SRMT.Topology.INFINITE ){ + int count = 0; + do{ + System.out.println("Current Number: " + n.read()); + if( count == 9 ) break; + n.step(); + count++; + }while( true ); + + }else{ + System.out.println("Unrecognized or invalid tape state."); + } + } + + public static void main(String[] args){ + print_ten( CountingNumber.make(BigInteger.TEN) ); // Finite segment up to 10 + print_ten( CountingNumber.make() ); // Infinite tape, stopping after 10 steps + } + +} diff --git a/developer/example/Example_CountingNumber_0.java b/developer/example/Example_CountingNumber_0.java deleted file mode 100644 index 0dab204..0000000 --- a/developer/example/Example_CountingNumber_0.java +++ /dev/null @@ -1,37 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import java.math.BigInteger; - -public class Example_CountingNumber_0{ - - protected static void print_ten(CountingNumber n){ - System.out.println("Iterating through Counting Numbers:"); - - if( !n.can_read() ) return; - - if( n.topology() == Ariadne_SRM.Topology.SEGMENT ){ - do{ - System.out.println("Current Number: " + n.read()); - if( !n.can_step() ) break; - n.step(); - }while( true ); - - }else if( n.topology() == Ariadne_SRM.Topology.INFINITE ){ - int count = 0; - do{ - System.out.println("Current Number: " + n.read()); - if( count == 9 ) break; - n.step(); - count++; - }while( true ); - - }else{ - System.out.println("Unrecognized or invalid tape state."); - } - } - - public static void main(String[] args){ - print_ten( CountingNumber.make(BigInteger.TEN) ); // Finite segment up to 10 - print_ten( CountingNumber.make() ); // Infinite tape, stopping after 10 steps - } - -} diff --git a/developer/example/Example_IndexTree_4x4.java b/developer/example/Example_IndexTree_4x4.java deleted file mode 100644 index 5f766bd..0000000 --- a/developer/example/Example_IndexTree_4x4.java +++ /dev/null @@ -1,46 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; -import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Child_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Graph; -import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; - -public class Example_IndexTree_4x4{ - - public static void main(String[] args){ - - System.out.println("Example_IndexTree_4x4"); - - // Initialize graph and start at root - Ariadne_IndexTree_Graph graph = Ariadne_IndexTree_Graph.make(); - Ariadne_IndexTree_Child_SRM root = graph.start(); - - System.out.println("root: " + root.read().toString()); - - // Variables for traversal - Ariadne_IndexTree_Label label = root.read(); - Ariadne_IndexTree_Node node; - Ariadne_SRM child_srm; - - // Descend 3 more levels - int i = 1; - do{ - node = graph.lookup(label); - child_srm = node.neighbor(); - label = child_srm.read(); - System.out.println("Descend: " + label.toString()); - if(i == 3) break; - i++; - }while(true); - - // Move across three more nodes - i = 1; - do{ - child_srm.step(); - label = child_srm.read(); - System.out.println("Across: " + label.toString()); - if(i == 3) break; - i++; - }while(true); - - } -} diff --git a/developer/example/Example_IndexTree_Diagonal_SRM.java b/developer/example/Example_IndexTree_Diagonal_SRM.java deleted file mode 100644 index 746735a..0000000 --- a/developer/example/Example_IndexTree_Diagonal_SRM.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.math.BigInteger; -import java.util.Queue; - -public class Example_IndexTree_Diagonal_SRM { - - public static void main(String[] args){ - System.out.println("Starting IndexTree SRM Example"); - - // Instantiate the IndexTree Diagonal SRM - IndexTree_Diagonal_SRM srm = IndexTree_Diagonal_SRM.make(); - - int step_count = 0; - do{ - System.out.println("Step " + (step_count + 1) + ":"); - /* - Queue read_list = srm.read(); - if(!read_list.isEmpty()){ - for(BigInteger[] label : read_list){ - System.out.println(" Node Label: " + format_label(label)); - } - } - */ - if(step_count == 3) break; // Mid-loop test for inclusive bounds - step_count++; - srm.step(); - }while(true); - } - - private static String format_label(BigInteger[] label){ - if(label.length == 0) return "[]"; - StringBuilder formatted = new StringBuilder("["); - for(int i = 0; i < label.length; i++){ - formatted.append(label[i].toString()); - if(i < label.length - 1) formatted.append(" ,"); - } - formatted.append("]"); - return formatted.toString(); - } -} diff --git a/developer/example/Example_SRMI_Array.java b/developer/example/Example_SRMI_Array.java deleted file mode 100644 index d630176..0000000 --- a/developer/example/Example_SRMI_Array.java +++ /dev/null @@ -1,23 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_SRMI_Array; - -import java.util.Arrays; -import java.util.List; - -public class Example_SRMI_Array { - public static void main( String[] args ){ - // Create an Array - List label_array = Arrays.asList( "A", "B", "C", "D" ); - - // Attach SRMI to the array - Ariadne_SRMI_Array srm = Ariadne_SRMI_Array.make( label_array ); - if( srm.can_read() ){ - do{ - System.out.println( "Reading: " + srm.read() ); - System.out.println( "Topology: " + srm.topology() ); - if( !srm.can_step() ) break; - srm.step(); - }while(true); - } - } -} diff --git a/developer/example/Example_SRM_List.java b/developer/example/Example_SRM_List.java deleted file mode 100644 index 197c1bf..0000000 --- a/developer/example/Example_SRM_List.java +++ /dev/null @@ -1,25 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; - -import java.util.LinkedList; - -public class Example_SRM_List { - public static void main( String[] args ){ - // Create a linked list - LinkedList label_list = new LinkedList<>(); - label_list.add( "A" ); - label_list.add( "B" ); - label_list.add( "C" ); - - // Attach SRM to the linked list and traverse - Ariadne_SRM_List srm = Ariadne_SRM_List.make(label_list); - if( srm.can_read() ){ - do{ - System.out.println( "Reading: " + srm.read() ); - System.out.println( "Topology: " + srm.topology() ); - if( !srm.can_step() ) break; - srm.step(); - }while(true); - } - } -} diff --git a/developer/example/IndexTree/Example_IndexTree_4x4.java b/developer/example/IndexTree/Example_IndexTree_4x4.java new file mode 100644 index 0000000..9e1b008 --- /dev/null +++ b/developer/example/IndexTree/Example_IndexTree_4x4.java @@ -0,0 +1,46 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT_List; +import com.ReasoningTechnology.Ariadne.IndexTree_SRMT_Child; +import com.ReasoningTechnology.Ariadne.IndexTree_Graph; +import com.ReasoningTechnology.Ariadne.IndexTree_Node; + +public class Example_IndexTree_4x4{ + + public static void main(String[] args){ + + System.out.println("Example_IndexTree_4x4"); + + // Initialize graph and start at root + IndexTree_Graph graph = IndexTree_Graph.make(); + IndexTree_SRMT_Child root = graph.start(); + + System.out.println("root: " + root.read().toString()); + + // Variables for traversal + IndexTree_Label label = root.read(); + IndexTree_Node node; + Ariadne_SRMT child_srm; + + // Descend 3 more levels + int i = 1; + do{ + node = graph.lookup(label); + child_srm = node.neighbor(); + label = child_srm.read(); + System.out.println("Descend: " + label.toString()); + if(i == 3) break; + i++; + }while(true); + + // Move across three more nodes + i = 1; + do{ + child_srm.step(); + label = child_srm.read(); + System.out.println("Across: " + label.toString()); + if(i == 3) break; + i++; + }while(true); + + } +} diff --git a/developer/example/IndexTree/Example_IndexTree_Diagonal_SRM.java b/developer/example/IndexTree/Example_IndexTree_Diagonal_SRM.java new file mode 100644 index 0000000..84c4400 --- /dev/null +++ b/developer/example/IndexTree/Example_IndexTree_Diagonal_SRM.java @@ -0,0 +1,39 @@ +import java.math.BigInteger; +import java.util.Queue; + +public class Example_IndexTree_Diagonal_SRMT { + + public static void main(String[] args){ + System.out.println("Starting IndexTree SRMT Example"); + + // Instantiate the IndexTree Diagonal SRMT + IndexTree_Diagonal_SRMT srm = IndexTree_Diagonal_SRMT.make(); + + int step_count = 0; + do{ + System.out.println("Step " + (step_count + 1) + ":"); + /* + Queue read_list = srm.read(); + if(!read_list.isEmpty()){ + for(BigInteger[] label : read_list){ + System.out.println(" Node Label: " + format_label(label)); + } + } + */ + if(step_count == 3) break; // Mid-loop test for inclusive bounds + step_count++; + srm.step(); + }while(true); + } + + private static String format_label(BigInteger[] label){ + if(label.length == 0) return "[]"; + StringBuilder formatted = new StringBuilder("["); + for(int i = 0; i < label.length; i++){ + formatted.append(label[i].toString()); + if(i < label.length - 1) formatted.append(" ,"); + } + formatted.append("]"); + return formatted.toString(); + } +} diff --git a/developer/example/IndexTree/IndexTree_Graph.java b/developer/example/IndexTree/IndexTree_Graph.java new file mode 100644 index 0000000..6b4f873 --- /dev/null +++ b/developer/example/IndexTree/IndexTree_Graph.java @@ -0,0 +1,21 @@ +package com.ReasoningTechnology.Ariadne; + +public class IndexTree_Graph{ + + public static IndexTree_Graph make(){ + return new IndexTree_Graph(); + } + protected IndexTree_Graph(){ + } + + public IndexTree_SRMT_Child start(){ + IndexTree_Label root_label = IndexTree_Label.root(); + return IndexTree_SRMT_Child.make(root_label); + } + + IndexTree_Node lookup(IndexTree_Label label){ + return IndexTree_Node.make(label); + } + +} + diff --git a/developer/example/IndexTree/IndexTree_Label.java b/developer/example/IndexTree/IndexTree_Label.java new file mode 100644 index 0000000..d416e71 --- /dev/null +++ b/developer/example/IndexTree/IndexTree_Label.java @@ -0,0 +1,81 @@ +/* + Implementation of Ariadne_Label for BigInteger array-based labels. +*/ + +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; +import java.util.Arrays; + +public class IndexTree_Label implements Ariadne_Label{ + + // Owned by class + // + + public static IndexTree_Label make(BigInteger[] array){ + return new IndexTree_Label(array); + } + + public static IndexTree_Label root(){ + return new IndexTree_Label(new BigInteger[0]); + } + + // Instance data + // + + private BigInteger[] value; + + // Constructor + // + + private IndexTree_Label(BigInteger[] array){ + this.value = array.clone(); + } + + // Instance interface implementation + // + + @Override public boolean isEmpty(){ + return value == null; + } + + @Override public String toString(){ + return Arrays.toString(value); + } + + @Override public IndexTree_Label copy(){ + return new IndexTree_Label(value); + } + + // Increment last element by one, modifying in place + public void inc_across(){ + if(value == null || value.length == 0){ + throw new UnsupportedOperationException("Cannot increment across an empty array."); + } + value[value.length - 1] = value[value.length - 1].add(BigInteger.ONE); + } + + // Append a zero element, modifying in place + public void inc_down(){ + if(value == null){ + throw new UnsupportedOperationException("Cannot append to a null array."); + } + BigInteger[] newValue = Arrays.copyOf(value, value.length + 1); + newValue[newValue.length - 1] = BigInteger.ZERO; + value = newValue; + } + + // Good object citizenship + // + + @Override public boolean equals(Object o){ + if(this == o) return true; + if( o == null || getClass() != o.getClass() ) return false; + IndexTree_Label that = (IndexTree_Label) o; + return Arrays.equals(value, that.value); + } + + @Override public int hashCode(){ + return Arrays.hashCode(value); + } +} diff --git a/developer/example/IndexTree/IndexTree_Node.java b/developer/example/IndexTree/IndexTree_Node.java new file mode 100644 index 0000000..bf1f7cd --- /dev/null +++ b/developer/example/IndexTree/IndexTree_Node.java @@ -0,0 +1,23 @@ +package com.ReasoningTechnology.Ariadne; +import java.util.Arrays; + +public class IndexTree_Node extends Ariadne_Node{ + + public static IndexTree_Node make(IndexTree_Label label){ + return new IndexTree_Node(label); + } + + private final IndexTree_Label first_child_label; + + public IndexTree_Node(IndexTree_Label label){ + super(label); + first_child_label = label.copy(); + first_child_label.inc_down(); + } + + // public IndexTree_SRMT_Child neighbor(){ + public IndexTree_SRMT_Child neighbor(){ + return IndexTree_SRMT_Child.make(first_child_label); + } + +} diff --git a/developer/example/IndexTree/IndexTree_SRTM_Child.java b/developer/example/IndexTree/IndexTree_SRTM_Child.java new file mode 100644 index 0000000..7b84ac2 --- /dev/null +++ b/developer/example/IndexTree/IndexTree_SRTM_Child.java @@ -0,0 +1,81 @@ +package com.ReasoningTechnology.Ariadne; + +public class IndexTree_SRMT_Child extends Ariadne_SRMT_Label { + + public static IndexTree_SRMT_Child make( IndexTree_Label first_child_label ){ + return new IndexTree_SRMT_Child( first_child_label ); + } + + private final IndexTree_Label label; + + protected IndexTree_SRMT_Child( IndexTree_Label first_child_label ){ + this.label = first_child_label.copy(); + + if( label == null ){ + set_topology( topo_null ); + return; + } + + if( label.isEmpty() ){ + set_topology( topo_rightmost ); + return; + } + + set_topology( topo_infinite_right ); + } + + private final TopoIface topo_null = new TopoIface(){ + @Override public boolean can_read(){ + return false; + } + @Override public Object read(){ + throw new UnsupportedOperationException( "Cannot read from NULL topology." ); + } + @Override public boolean can_step(){ + return false; + } + @Override public void step(){ + throw new UnsupportedOperationException( "Cannot step from NULL topology." ); + } + @Override public Topology topology(){ + return Topology.NULL; + } + }; + + private final TopoIface topo_infinite_right = new TopoIface(){ + @Override public boolean can_read(){ + return true; + } + @Override public Object read(){ + return label; + } + @Override public boolean can_step(){ + return true; + } + @Override public void step(){ + label.inc_across(); + } + @Override public Topology topology(){ + return Topology.INFINITE; + } + }; + + private final TopoIface topo_rightmost = new TopoIface(){ + @Override public boolean can_read(){ + return true; + } + @Override public Object read(){ + return label; + } + @Override public boolean can_step(){ + return false; + } + @Override public void step(){ + throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topology." ); + } + @Override public Topology topology(){ + return Topology.RIGHTMOST; + } + }; + +} diff --git a/developer/example/IndexTree/IndexTree_SRTM_Diagonal.java b/developer/example/IndexTree/IndexTree_SRTM_Diagonal.java new file mode 100644 index 0000000..5e39c93 --- /dev/null +++ b/developer/example/IndexTree/IndexTree_SRTM_Diagonal.java @@ -0,0 +1,118 @@ +/* +An index Tree is infinite. + +A tree diagonal consists of +a) a node descending from each child discovered thus far +b> a node extending each child list discovered thus far. + +Hence, each diagonal extends the tree down one, and over one. + +*/ + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import com.ReasoningTechnology.Ariadne.Ariadne_Test; +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; + +public class IndexTree_Diagonal_SRMT extends Ariadne_SRMT_Label>{ + + // Static + // + + public static IndexTree_Diagonal_SRMT make(){ + return new IndexTree_Diagonal_SRMT(); + } + + //Instance data + // + + private final List list_of__unopened_node; + // each node has a child list, this is a list of child lists + private final List list_of__opened_incomplete_child_list; + // Each diagonal is a list of nodes, referenced by their label + private final List read_list; + + // Constructor(s) + // + + protected IndexTree_Diagonal_SRMT(){ + list_of__unopened_node = new ArrayList<>(); + list_of__opened_incomplete_child_list = new ArrayList<>(); + read_list = new ArrayList<>(); + enqueue_root(); + } + + // Implementation of instance interface. + // + + private void enqueue_root(){ + Ariadne_IndexTree_Label root_label = Ariadne_IndexTree_Label.root(); + read_list.add(root_label); + + Ariadne_IndexTree_Node root_node = lookup(root_label); + if( !fetch_child_labels(root_node).isEmpty() ){ + list_of__unopened_node.add(root_label); + } + } + + // lol! This can not be done on an infinite list! + private List fetch_child_labels(Ariadne_IndexTree_Node node){ + List child_labels = new ArrayList<>(); + if(node != null){ + IndexTree_Diagonal_SRMT child_srm = node.neighbor(); + if( child_srm.can_read() ){ + do{ + child_labels.add(child_srm.read()); + if( !srm.can_step ) break; + child_srm.step(); + }while(true); + } + } + return child_labels; + } + + @Override public List read(){ + return read_list; + } + + @Override public void step(){ + read_list.clear(); + + // Process unopened nodes + while( !list_of__unopened_node.isEmpty() ){ + BigInteger[] label = list_of__unopened_node.remove(0); + + // Retrieve the node using lookup + Ariadne_IndexTree_Node node = lookup(label); + + // Descend by getting neighbors + List child_labels = fetch_child_labels(node); + if( !child_labels.isEmpty() ){ + list_of__opened_incomplete_child_list.add(child_labels); + } + } + + // Process incomplete child lists + while( !list_of__opened_incomplete_child_list.isEmpty() ){ + List child_labels = list_of__opened_incomplete_child_list.remove(0); + if( !child_labels.isEmpty() ){ + BigInteger[] label = child_labels.remove(0); + read_list.add(label); + + // Retrieve node and check its neighbors + Ariadne_IndexTree_Node node = lookup(label); + if( !fetch_child_labels(node).isEmpty() ){ + list_of__unopened_node.add(label); + } + } + } + } + + private Ariadne_IndexTree_Node lookup(BigInteger[] label){ + // Perform a lookup to retrieve the node corresponding to the label + return Ariadne_IndexTree_Node.make(label); + } + +} diff --git a/developer/example/IndexTree_Diagonal_SRM.class b/developer/example/IndexTree_Diagonal_SRM.class deleted file mode 100644 index a9bf2ed..0000000 Binary files a/developer/example/IndexTree_Diagonal_SRM.class and /dev/null differ diff --git a/developer/example/IndexTree_Diagonal_SRM.java b/developer/example/IndexTree_Diagonal_SRM.java deleted file mode 100644 index 4daa8b3..0000000 --- a/developer/example/IndexTree_Diagonal_SRM.java +++ /dev/null @@ -1,118 +0,0 @@ -/* -An index Tree is infinite. - -A tree diagonal consists of -a) a node descending from each child discovered thus far -b> a node extending each child list discovered thus far. - -Hence, each diagonal extends the tree down one, and over one. - -*/ - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import com.ReasoningTechnology.Ariadne.Ariadne_Test; -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; - -public class IndexTree_Diagonal_SRM extends Ariadne_SRM_Label>{ - - // Static - // - - public static IndexTree_Diagonal_SRM make(){ - return new IndexTree_Diagonal_SRM(); - } - - //Instance data - // - - private final List list_of__unopened_node; - // each node has a child list, this is a list of child lists - private final List> list_of__opened_incomplete_child_list; - // Each diagonal is a list of nodes, referenced by their label - private final List read_list; - - // Constructor(s) - // - - protected IndexTree_Diagonal_SRM(){ - list_of__unopened_node = new ArrayList<>(); - list_of__opened_incomplete_child_list = new ArrayList<>(); - read_list = new ArrayList<>(); - enqueue_root(); - } - - // Implementation of instance interface. - // - - private void enqueue_root(){ - Ariadne_IndexTree_Label root_label = Ariadne_IndexTree_Label.root(); - read_list.add(root_label); - - Ariadne_IndexTree_Node root_node = lookup(root_label); - if( !fetch_child_labels(root_node).isEmpty() ){ - list_of__unopened_node.add(root_label); - } - } - - // lol! This can not be done on an infinite list! - private List fetch_child_labels(Ariadne_IndexTree_Node node){ - List child_labels = new ArrayList<>(); - if(node != null){ - IndexTree_Diagonal_SRM child_srm = node.neighbor(); - if( child_srm.can_read() ){ - do{ - child_labels.add(child_srm.read()); - if( !srm.can_step ) break; - child_srm.step(); - }while(true); - } - } - return child_labels; - } - - @Override public List read(){ - return read_list; - } - - @Override public void step(){ - read_list.clear(); - - // Process unopened nodes - while( !list_of__unopened_node.isEmpty() ){ - BigInteger[] label = list_of__unopened_node.remove(0); - - // Retrieve the node using lookup - Ariadne_IndexTree_Node node = lookup(label); - - // Descend by getting neighbors - List child_labels = fetch_child_labels(node); - if( !child_labels.isEmpty() ){ - list_of__opened_incomplete_child_list.add(child_labels); - } - } - - // Process incomplete child lists - while( !list_of__opened_incomplete_child_list.isEmpty() ){ - List child_labels = list_of__opened_incomplete_child_list.remove(0); - if( !child_labels.isEmpty() ){ - BigInteger[] label = child_labels.remove(0); - read_list.add(label); - - // Retrieve node and check its neighbors - Ariadne_IndexTree_Node node = lookup(label); - if( !fetch_child_labels(node).isEmpty() ){ - list_of__unopened_node.add(label); - } - } - } - } - - private Ariadne_IndexTree_Node lookup(BigInteger[] label){ - // Perform a lookup to retrieve the node corresponding to the label - return Ariadne_IndexTree_Node.make(label); - } - -} diff --git a/developer/example/SRTM/Example_SRTMI_Array.java b/developer/example/SRTM/Example_SRTMI_Array.java new file mode 100644 index 0000000..7283167 --- /dev/null +++ b/developer/example/SRTM/Example_SRTMI_Array.java @@ -0,0 +1,23 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import com.ReasoningTechnology.Ariadne.Ariadne_SRMTI_Array; + +import java.util.Arrays; +import java.util.List; + +public class Example_SRMTI_Array { + public static void main( String[] args ){ + // Create an Array + List label_array = Arrays.asList( "A", "B", "C", "D" ); + + // Attach SRMTI to the array + Ariadne_SRMTI_Array srm = Ariadne_SRMTI_Array.make( label_array ); + if( srm.can_read() ){ + do{ + System.out.println( "Reading: " + srm.read() ); + System.out.println( "Topology: " + srm.topology() ); + if( !srm.can_step() ) break; + srm.step(); + }while(true); + } + } +} diff --git a/developer/example/SRTM/Example_SRTM_List.java b/developer/example/SRTM/Example_SRTM_List.java new file mode 100644 index 0000000..6d35ead --- /dev/null +++ b/developer/example/SRTM/Example_SRTM_List.java @@ -0,0 +1,25 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT_List; + +import java.util.LinkedList; + +public class Example_SRMT_List { + public static void main( String[] args ){ + // Create a linked list + LinkedList label_list = new LinkedList<>(); + label_list.add( "A" ); + label_list.add( "B" ); + label_list.add( "C" ); + + // Attach SRMT to the linked list and traverse + Ariadne_SRMT_List srm = Ariadne_SRMT_List.make(label_list); + if( srm.can_read() ){ + do{ + System.out.println( "Reading: " + srm.read() ); + System.out.println( "Topology: " + srm.topology() ); + if( !srm.can_step() ) break; + srm.step(); + }while(true); + } + } +} diff --git a/developer/example/temp.java b/developer/example/temp.java new file mode 100644 index 0000000..2f09bb4 --- /dev/null +++ b/developer/example/temp.java @@ -0,0 +1,108 @@ +/* + IndexTree_SRMT_Diagonal + + An index tree is infinite. + + A tree diagonal consists of: + a) a node descending from each child discovered thus far + b) a node extending each child list discovered thus far. + + Hence, each diagonal extends the tree down one and over one. +*/ + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import com.ReasoningTechnology.Ariadne.Ariadne_SRMT; +import com.ReasoningTechnology.Ariadne.IndexTree_Node; + +public class IndexTree_SRMT_Diagonal extends Ariadne_SRMT_Label { + + // Static + + public static IndexTree_SRMT_Diagonal make(){ + return new IndexTree_SRMT_Diagonal(); + } + + // Instance Data + + private final List list_of__unopened_node; + private final List> list_of__opened_incomplete_child_list; + private final List read_list; + private final Ariadne_SRMT_Label breadth_srm; + + // Constructor + + protected IndexTree_SRMT_Diagonal(){ + list_of__unopened_node = new ArrayList<>(); + list_of__opened_incomplete_child_list = new ArrayList<>(); + read_list = new ArrayList<>(); + breadth_srm = Ariadne_SRMT_Label.make(); + enqueue_root(); + } + + // Instance Methods + + private void enqueue_root(){ + IndexTree_Label root_label = IndexTree_Label.root(); + read_list.add( root_label ); + + IndexTree_Node root_node = lookup( root_label ); + breadth_srm.mount( root_node.neighbor() ); + + if( breadth_srm.can_read() ){ + list_of__unopened_node.add( root_label ); + } + } + + private IndexTree_Node lookup( Ariadne_Label label ){ + return IndexTree_Node.make( (IndexTree_Label)label ); + } + + @Override + public List read(){ + return read_list; + } + + @Override + public void step(){ + read_list.clear(); + + // Process unopened nodes + while( !list_of__unopened_node.isEmpty() ){ + Ariadne_Label label = list_of__unopened_node.remove( 0 ); + + // Retrieve the node using lookup + IndexTree_Node node = lookup( label ); + + // Mount a new breadth-first SRMT for children + breadth_srm.mount( node.neighbor() ); + + if( breadth_srm.can_read() ){ + do{ + Ariadne_Label child_label = breadth_srm.read(); + list_of__unopened_node.add( child_label ); + list_of__opened_incomplete_child_list.add( new ArrayList<>( List.of( child_label ) ) ); + + breadth_srm.step(); + }while( breadth_srm.can_step() ); + } + } + + // Process incomplete child lists + while( !list_of__opened_incomplete_child_list.isEmpty() ){ + List child_list = list_of__opened_incomplete_child_list.remove( 0 ); + if( !child_list.isEmpty() ){ + Ariadne_Label label = child_list.remove( 0 ); + read_list.add( label ); + + IndexTree_Node node = lookup( label ); + breadth_srm.mount( node.neighbor() ); + + if( breadth_srm.can_read() ){ + list_of__unopened_node.add( label ); + } + } + } + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_Graph.java" index 769eeda..6739911 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Graph.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Graph.java" @@ -12,7 +12,7 @@ package com.ReasoningTechnology.Ariadne; public interface Ariadne_Graph { - Ariadne_SRM start(); + Ariadne_SRMT start(); Ariadne_Node lookup(Ariadne_Label label); diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" deleted file mode 100644 index bbe68e8..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Child_SRM.java" +++ /dev/null @@ -1,81 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_IndexTree_Child_SRM extends Ariadne_SRM_Label { - - public static Ariadne_IndexTree_Child_SRM make( Ariadne_IndexTree_Label first_child_label ){ - return new Ariadne_IndexTree_Child_SRM( first_child_label ); - } - - private final Ariadne_IndexTree_Label label; - - protected Ariadne_IndexTree_Child_SRM( Ariadne_IndexTree_Label first_child_label ){ - this.label = first_child_label.copy(); - - if( label == null ){ - set_topology( topo_null ); - return; - } - - if( label.isEmpty() ){ - set_topology( topo_rightmost ); - return; - } - - set_topology( topo_infinite_right ); - } - - private final TopoIface topo_null = new TopoIface(){ - @Override public boolean can_read(){ - return false; - } - @Override public Object read(){ - throw new UnsupportedOperationException( "Cannot read from NULL topology." ); - } - @Override public boolean can_step(){ - return false; - } - @Override public void step(){ - throw new UnsupportedOperationException( "Cannot step from NULL topology." ); - } - @Override public Topology topology(){ - return Topology.NULL; - } - }; - - private final TopoIface topo_infinite_right = new TopoIface(){ - @Override public boolean can_read(){ - return true; - } - @Override public Object read(){ - return label; - } - @Override public boolean can_step(){ - return true; - } - @Override public void step(){ - label.inc_across(); - } - @Override public Topology topology(){ - return Topology.INFINITE; - } - }; - - private final TopoIface topo_rightmost = new TopoIface(){ - @Override public boolean can_read(){ - return true; - } - @Override public Object read(){ - return label; - } - @Override public boolean can_step(){ - return false; - } - @Override public void step(){ - throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topology." ); - } - @Override public Topology topology(){ - return Topology.RIGHTMOST; - } - }; - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" deleted file mode 100644 index 034d604..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" +++ /dev/null @@ -1,21 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_IndexTree_Graph{ - - public static Ariadne_IndexTree_Graph make(){ - return new Ariadne_IndexTree_Graph(); - } - protected Ariadne_IndexTree_Graph(){ - } - - public Ariadne_IndexTree_Child_SRM start(){ - Ariadne_IndexTree_Label root_label = Ariadne_IndexTree_Label.root(); - return Ariadne_IndexTree_Child_SRM.make(root_label); - } - - Ariadne_IndexTree_Node lookup(Ariadne_IndexTree_Label label){ - return Ariadne_IndexTree_Node.make(label); - } - -} - diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Label.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Label.java" deleted file mode 100644 index 8abb146..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Label.java" +++ /dev/null @@ -1,81 +0,0 @@ -/* - Implementation of Ariadne_Label for BigInteger array-based labels. -*/ - -package com.ReasoningTechnology.Ariadne; - -import java.math.BigInteger; -import java.util.Arrays; - -public class Ariadne_IndexTree_Label implements Ariadne_Label{ - - // Owned by class - // - - public static Ariadne_IndexTree_Label make(BigInteger[] array){ - return new Ariadne_IndexTree_Label(array); - } - - public static Ariadne_IndexTree_Label root(){ - return new Ariadne_IndexTree_Label(new BigInteger[0]); - } - - // Instance data - // - - private BigInteger[] value; - - // Constructor - // - - private Ariadne_IndexTree_Label(BigInteger[] array){ - this.value = array.clone(); - } - - // Instance interface implementation - // - - @Override public boolean isEmpty(){ - return value == null; - } - - @Override public String toString(){ - return Arrays.toString(value); - } - - @Override public Ariadne_IndexTree_Label copy(){ - return new Ariadne_IndexTree_Label(value); - } - - // Increment last element by one, modifying in place - public void inc_across(){ - if(value == null || value.length == 0){ - throw new UnsupportedOperationException("Cannot increment across an empty array."); - } - value[value.length - 1] = value[value.length - 1].add(BigInteger.ONE); - } - - // Append a zero element, modifying in place - public void inc_down(){ - if(value == null){ - throw new UnsupportedOperationException("Cannot append to a null array."); - } - BigInteger[] newValue = Arrays.copyOf(value, value.length + 1); - newValue[newValue.length - 1] = BigInteger.ZERO; - value = newValue; - } - - // Good object citizenship - // - - @Override public boolean equals(Object o){ - if(this == o) return true; - if( o == null || getClass() != o.getClass() ) return false; - Ariadne_IndexTree_Label that = (Ariadne_IndexTree_Label) o; - return Arrays.equals(value, that.value); - } - - @Override public int hashCode(){ - return Arrays.hashCode(value); - } -} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" deleted file mode 100644 index 314ab6b..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" +++ /dev/null @@ -1,23 +0,0 @@ -package com.ReasoningTechnology.Ariadne; -import java.util.Arrays; - -public class Ariadne_IndexTree_Node extends Ariadne_Node{ - - public static Ariadne_IndexTree_Node make(Ariadne_IndexTree_Label label){ - return new Ariadne_IndexTree_Node(label); - } - - private final Ariadne_IndexTree_Label first_child_label; - - public Ariadne_IndexTree_Node(Ariadne_IndexTree_Label label){ - super(label); - first_child_label = label.copy(); - first_child_label.inc_down(); - } - - // public Ariadne_IndexTree_Child_SRM neighbor(){ - public Ariadne_IndexTree_Child_SRM neighbor(){ - return Ariadne_IndexTree_Child_SRM.make(first_child_label); - } - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_Node.java" "b/developer/javac\360\237\226\211/Ariadne_Node.java" index 732b0a7..89f50ad 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Node.java" @@ -54,7 +54,7 @@ public class Ariadne_Node extends HashMap{ return this.label; } - public Ariadne_SRM_Label neighbor(){ + public Ariadne_SRMT_Label neighbor(){ throw new UnsupportedOperationException("Ariadne_Node::neighbor not implemented in the base class."); } @@ -88,7 +88,7 @@ public class Ariadne_Node extends HashMap{ // Marks representation if( !mark_set.isEmpty() ){ - Ariadne_SRM_Set srm = Ariadne_SRM_Set.make(mark_set); + Ariadne_SRMT_Set srm = Ariadne_SRMT_Set.make(mark_set); output.append( " Mark(" ); do{ diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" deleted file mode 100644 index 462c9df..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ /dev/null @@ -1,102 +0,0 @@ -/* - Step Right Machine - - This is a mostly abstract base class. - - This is for single-threaded execution. The multi-threaded model - uses `mount` and `dismount` to lock the resources being iterated on. -*/ -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_SRM{ - - // static - // - - public enum Topology{ - NULL - ,CYCLIC - ,SEGMENT - ,RIGHTMOST - ,INFINITE - } - - public static make(){ - return new Ariadne_SRM - } - - // instance data - // - - protected TopoIface current_topology; - public final TopoIface not_mounted = new NotMounted(); - - // constructor(s) - // - - protected Ariadne_SRM(){ - set_topology( not_mounted ); - } - - public boolean is_mounted(){ - return - current_topology != null - && current_topology != not_mounted; - } - - // Implementation of instance interface. - - protected interface TopoIface{ - boolean can_read(); - Object read(); - boolean can_step(); - void step(); - Topology topology(); - } - - // Initially, the tape has not been mounted. - protected class NotMounted implements TopoIface{ - @Override public boolean can_read(){ - return false; - } - @Override public Object read(){ - throw new UnsupportedOperationException("Ariadne_SRM::NotMounted::read."); - } - @Override public boolean can_step(){ - return false; - } - @Override public void step(){ - throw new UnsupportedOperationException("Ariadne_SRM::NotMounted::step."); - } - @Override public Topology topology(){ - throw new UnsupportedOperationException("Ariadne_SRM::NotMounted::topology."); - } - } - - // Sets the tape access methods to be used. - protected void set_topology(TopoIface new_topology){ - current_topology = new_topology; - } - - public boolean can_read(){ - return current_topology.can_read(); - } - - public Object read(){ - return current_topology.read(); - } - - public boolean can_step(){ - return current_topology.can_step(); - } - - public void step(){ - current_topology.step(); - } - - public Topology topology(){ - return current_topology.topology(); - } - -} - diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" deleted file mode 100644 index 4bb120a..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" +++ /dev/null @@ -1,24 +0,0 @@ -/* -Ariadne_SRM with index - -*/ - -package com.ReasoningTechnology.Ariadne; -import java.math.BigInteger; - -public abstract class Ariadne_SRMI extends Ariadne_SRM{ - - private BigInteger current_index; - - public Ariadne_SRMI(){ - this.current_index = BigInteger.ZERO; - } - - public BigInteger index(){ - return current_index; - } - - public void increment(){ - current_index = current_index.add(BigInteger.ONE); - } -} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" deleted file mode 100644 index 9027594..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" +++ /dev/null @@ -1,111 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -import java.math.BigInteger; -import java.util.List; - -public class Ariadne_SRMI_Array extends Ariadne_SRMI{ - - // Static methods - public static Ariadne_SRMI_Array make(List array){ - return new Ariadne_SRMI_Array( array ); - } - - // Instance data - private final List array; - - private final TopoIface topo_null = new TopoNull(); - private final TopoIface topo_segment = new TopoSegment(); - private final TopoIface topo_rightmost = new TopoRightmost(); - - // Constructor - protected Ariadne_SRMI_Array(List array){ - super(); - this.array = array; - - if( array == null || array.isEmpty() ){ - set_topology( topo_null ); - return; - } - - if( array.size() == 1 ){ - set_topology( topo_rightmost ); - return; - } - - set_topology( topo_segment ); - } - - // TopoNull - private class TopoNull implements TopoIface{ - @Override - public boolean can_read(){ - return false; - } - @Override - public Object read(){ - throw new UnsupportedOperationException( "Cannot read from NULL topo." ); - } - @Override - public boolean can_step(){ - return false; - } - @Override - public void step(){ - throw new UnsupportedOperationException( "Cannot step from NULL topo." ); - } - @Override - public Topology topology(){ - return Topology.NULL; - } - } - - // TopoSegment - private class TopoSegment implements TopoIface{ - @Override - public boolean can_read(){ - return true; - } - @Override - public Object read(){ - return array.get( index().intValueExact() ); - } - @Override - public boolean can_step(){ - return true; - } - @Override - public void step(){ - increment(); - if( index().compareTo(BigInteger.valueOf(array.size() - 1)) == 0 ) - set_topology(topo_rightmost); - } - @Override - public Topology topology(){ - return Topology.SEGMENT; - } - } - - // TopoRightmost - private class TopoRightmost implements TopoIface{ - @Override - public boolean can_read(){ - return true; - } - @Override - public Object read(){ - return array.get( index().intValueExact() ); - } - @Override - public boolean can_step(){ - return false; - } - @Override - public void step(){ - throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." ); - } - @Override - public Topology topology(){ - return Topology.RIGHTMOST; - } - } -} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_Label.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_Label.java" deleted file mode 100644 index b69e3e1..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_Label.java" +++ /dev/null @@ -1,13 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_SRM_Label extends Ariadne_SRM { - - public static Ariadne_SRM_Label make(){ - return new Ariadne_SRM_Label(); - } - - @Override public Ariadne_Label read(){ - return (Ariadne_Label)super.read(); - } - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" deleted file mode 100644 index 2974af5..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" +++ /dev/null @@ -1,102 +0,0 @@ -/* - The Ariadne_SRM_List class provides a Step Right Machine (SRM) for linked lists. - This implementation uses Java's ListIterator, which lacks a direct method - to read the current element without advancing the iterator. - -*/ -package com.ReasoningTechnology.Ariadne; -import java.util.List; -import java.util.ListIterator; - -public class Ariadne_SRM_List extends Ariadne_SRM{ - - // Static methods - public static Ariadne_SRM_List make(List list){ - return new Ariadne_SRM_List(list); - } - - private List list; // The attached linked list - private ListIterator iterator; // Iterator for traversal - private Object read_value; // Stores the current cell value - - private final TopoIface topo_null = new TopoNull(); - private final TopoIface topo_segment = new TopoSegment(); - private final TopoIface topo_rightmost = new TopoRightmost(); - - protected Ariadne_SRM_List(List list){ - this.list = list; - - if( list == null || list.isEmpty() ){ - this.iterator = null; - set_topology(topo_null); - return; - } - - this.iterator = list.listIterator(); - read_value = iterator.next(); - - if( list.size() == 1 ){ - set_topology(topo_rightmost); - return; - } - - set_topology(topo_segment); - } - - private class TopoNull implements TopoIface{ - @Override public boolean can_read(){ - return false; - } - @Override public Object read(){ - throw new UnsupportedOperationException( "Cannot read from NULL topo." ); - } - @Override public boolean can_step(){ - return false; - } - @Override public void step(){ - throw new UnsupportedOperationException( "Cannot step over NULL topo." ); - } - @Override public Topology topology(){ - return Topology.NULL; - } - } - - private class TopoSegment implements TopoIface{ - @Override public boolean can_read(){ - return true; - } - @Override public Object read(){ - return read_value; - } - @Override public boolean can_step(){ - return true; - } - @Override public void step(){ - read_value = iterator.next(); - if( !iterator.hasNext() ) set_topology(topo_rightmost); - } - @Override public Topology topology(){ - return Topology.SEGMENT; - } - } - - private class TopoRightmost implements TopoIface{ - @Override public boolean can_read(){ - return true; - } - @Override public Object read(){ - return read_value; - } - @Override public boolean can_step(){ - return false; - } - @Override public void step(){ - throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." ); - } - @Override public Topology topology(){ - return Topology.RIGHTMOST; - } - } -} - - diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_Set.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_Set.java" deleted file mode 100644 index 8ec5ad0..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_Set.java" +++ /dev/null @@ -1,18 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -import java.util.ArrayList; -import java.util.Set; - -public class Ariadne_SRM_Set extends Ariadne_SRMI_Array{ - - // Static factory method - public static Ariadne_SRM_Set make(Set set){ - return new Ariadne_SRM_Set( set ); - } - - // Constructor - protected Ariadne_SRM_Set(Set set){ - super( new ArrayList(set) ); - } - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTM.java" "b/developer/javac\360\237\226\211/Ariadne_SRTM.java" new file mode 100644 index 0000000..ba15c04 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTM.java" @@ -0,0 +1,102 @@ +/* + Step Right Machine + + This is a mostly abstract base class. + + This is for single-threaded execution. The multi-threaded model + uses `mount` and `dismount` to lock the resources being iterated on. +*/ +package com.ReasoningTechnology.Ariadne; + +public class Ariadne_SRMT{ + + // static + // + + public enum Topology{ + NULL + ,CYCLIC + ,SEGMENT + ,RIGHTMOST + ,INFINITE + } + + public static Ariadne_SRMT make(){ + return new Ariadne_SRMT(); + } + + // instance data + // + + protected TopoIface current_topology; + public final TopoIface not_mounted = new NotMounted(); + + // constructor(s) + // + + protected Ariadne_SRMT(){ + set_topology( not_mounted ); + } + + public boolean is_mounted(){ + return + current_topology != null + && current_topology != not_mounted; + } + + // Implementation of instance interface. + + protected interface TopoIface{ + boolean can_read(); + Object read(); + boolean can_step(); + void step(); + Topology topology(); + } + + // Initially, the tape has not been mounted. + protected class NotMounted implements TopoIface{ + @Override public boolean can_read(){ + return false; + } + @Override public Object read(){ + throw new UnsupportedOperationException("Ariadne_SRMT::NotMounted::read."); + } + @Override public boolean can_step(){ + return false; + } + @Override public void step(){ + throw new UnsupportedOperationException("Ariadne_SRMT::NotMounted::step."); + } + @Override public Topology topology(){ + throw new UnsupportedOperationException("Ariadne_SRMT::NotMounted::topology."); + } + } + + // Sets the tape access methods to be used. + protected void set_topology(TopoIface new_topology){ + current_topology = new_topology; + } + + public boolean can_read(){ + return current_topology.can_read(); + } + + public Object read(){ + return current_topology.read(); + } + + public boolean can_step(){ + return current_topology.can_step(); + } + + public void step(){ + current_topology.step(); + } + + public Topology topology(){ + return current_topology.topology(); + } + +} + diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRTMI.java" new file mode 100644 index 0000000..4bdd585 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTMI.java" @@ -0,0 +1,24 @@ +/* +Ariadne_SRMT with index + +*/ + +package com.ReasoningTechnology.Ariadne; +import java.math.BigInteger; + +public abstract class Ariadne_SRMTI extends Ariadne_SRMT{ + + private BigInteger current_index; + + public Ariadne_SRMTI(){ + this.current_index = BigInteger.ZERO; + } + + public BigInteger index(){ + return current_index; + } + + public void increment(){ + current_index = current_index.add(BigInteger.ONE); + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRTMI_Array.java" new file mode 100644 index 0000000..c63fe73 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTMI_Array.java" @@ -0,0 +1,111 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; +import java.util.List; + +public class Ariadne_SRMTI_Array extends Ariadne_SRMTI{ + + // Static methods + public static Ariadne_SRMTI_Array make(List array){ + return new Ariadne_SRMTI_Array( array ); + } + + // Instance data + private final List array; + + private final TopoIface topo_null = new TopoNull(); + private final TopoIface topo_segment = new TopoSegment(); + private final TopoIface topo_rightmost = new TopoRightmost(); + + // Constructor + protected Ariadne_SRMTI_Array(List array){ + super(); + this.array = array; + + if( array == null || array.isEmpty() ){ + set_topology( topo_null ); + return; + } + + if( array.size() == 1 ){ + set_topology( topo_rightmost ); + return; + } + + set_topology( topo_segment ); + } + + // TopoNull + private class TopoNull implements TopoIface{ + @Override + public boolean can_read(){ + return false; + } + @Override + public Object read(){ + throw new UnsupportedOperationException( "Cannot read from NULL topo." ); + } + @Override + public boolean can_step(){ + return false; + } + @Override + public void step(){ + throw new UnsupportedOperationException( "Cannot step from NULL topo." ); + } + @Override + public Topology topology(){ + return Topology.NULL; + } + } + + // TopoSegment + private class TopoSegment implements TopoIface{ + @Override + public boolean can_read(){ + return true; + } + @Override + public Object read(){ + return array.get( index().intValueExact() ); + } + @Override + public boolean can_step(){ + return true; + } + @Override + public void step(){ + increment(); + if( index().compareTo(BigInteger.valueOf(array.size() - 1)) == 0 ) + set_topology(topo_rightmost); + } + @Override + public Topology topology(){ + return Topology.SEGMENT; + } + } + + // TopoRightmost + private class TopoRightmost implements TopoIface{ + @Override + public boolean can_read(){ + return true; + } + @Override + public Object read(){ + return array.get( index().intValueExact() ); + } + @Override + public boolean can_step(){ + return false; + } + @Override + public void step(){ + throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." ); + } + @Override + public Topology topology(){ + return Topology.RIGHTMOST; + } + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTM_Label.java" "b/developer/javac\360\237\226\211/Ariadne_SRTM_Label.java" new file mode 100644 index 0000000..1aa4824 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTM_Label.java" @@ -0,0 +1,13 @@ +package com.ReasoningTechnology.Ariadne; + +public class Ariadne_SRMT_Label extends Ariadne_SRMT { + + public static Ariadne_SRMT_Label make(){ + return new Ariadne_SRMT_Label(); + } + + @Override public Ariadne_Label read(){ + return (Ariadne_Label)super.read(); + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTM_List.java" "b/developer/javac\360\237\226\211/Ariadne_SRTM_List.java" new file mode 100644 index 0000000..233db1e --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTM_List.java" @@ -0,0 +1,102 @@ +/* + The Ariadne_SRMT_List class provides a Step Right Machine (SRMT) for linked lists. + This implementation uses Java's ListIterator, which lacks a direct method + to read the current element without advancing the iterator. + +*/ +package com.ReasoningTechnology.Ariadne; +import java.util.List; +import java.util.ListIterator; + +public class Ariadne_SRMT_List extends Ariadne_SRMT{ + + // Static methods + public static Ariadne_SRMT_List make(List list){ + return new Ariadne_SRMT_List(list); + } + + private List list; // The attached linked list + private ListIterator iterator; // Iterator for traversal + private Object read_value; // Stores the current cell value + + private final TopoIface topo_null = new TopoNull(); + private final TopoIface topo_segment = new TopoSegment(); + private final TopoIface topo_rightmost = new TopoRightmost(); + + protected Ariadne_SRMT_List(List list){ + this.list = list; + + if( list == null || list.isEmpty() ){ + this.iterator = null; + set_topology(topo_null); + return; + } + + this.iterator = list.listIterator(); + read_value = iterator.next(); + + if( list.size() == 1 ){ + set_topology(topo_rightmost); + return; + } + + set_topology(topo_segment); + } + + private class TopoNull implements TopoIface{ + @Override public boolean can_read(){ + return false; + } + @Override public Object read(){ + throw new UnsupportedOperationException( "Cannot read from NULL topo." ); + } + @Override public boolean can_step(){ + return false; + } + @Override public void step(){ + throw new UnsupportedOperationException( "Cannot step over NULL topo." ); + } + @Override public Topology topology(){ + return Topology.NULL; + } + } + + private class TopoSegment implements TopoIface{ + @Override public boolean can_read(){ + return true; + } + @Override public Object read(){ + return read_value; + } + @Override public boolean can_step(){ + return true; + } + @Override public void step(){ + read_value = iterator.next(); + if( !iterator.hasNext() ) set_topology(topo_rightmost); + } + @Override public Topology topology(){ + return Topology.SEGMENT; + } + } + + private class TopoRightmost implements TopoIface{ + @Override public boolean can_read(){ + return true; + } + @Override public Object read(){ + return read_value; + } + @Override public boolean can_step(){ + return false; + } + @Override public void step(){ + throw new UnsupportedOperationException( "Cannot step from RIGHTMOST topo." ); + } + @Override public Topology topology(){ + return Topology.RIGHTMOST; + } + } +} + + diff --git "a/developer/javac\360\237\226\211/Ariadne_SRTM_Set.java" "b/developer/javac\360\237\226\211/Ariadne_SRTM_Set.java" new file mode 100644 index 0000000..84bdaa1 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRTM_Set.java" @@ -0,0 +1,17 @@ +package com.ReasoningTechnology.Ariadne; + +import java.util.ArrayList; +import java.util.Set; + +public class Ariadne_SRMT_Set extends Ariadne_SRMTI_Array{ + + // Static factory method + public static Ariadne_SRMT_Set make(Set set){ + return new Ariadne_SRMT_Set( set ); + } + + protected Ariadne_SRMT_Set(Set set){ + super( new ArrayList(set) ); + } + +} diff --git "a/developer/tool\360\237\226\211/clean_example" "b/developer/tool\360\237\226\211/clean_example" index bd0670b..59496e3 100755 --- "a/developer/tool\360\237\226\211/clean_example" +++ "b/developer/tool\360\237\226\211/clean_example" @@ -9,16 +9,24 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") cd "$REPO_HOME"/developer || exit 1 source tool🖉/env_script -# remove example class files +# Check if the directory $1 exists +if [ ! -d "example/$1" ]; then + echo "Error: Directory 'example/$1' does not exist." + exit 1 +fi - cd example || exit 1 +cd "example/$1" || exit 1 + + +# remove wrappers and class files for file in Example_*.class; do echo "file: " $file - rm_na "$file" wrapper_name=$(basename "$file" .class) rm_na "$wrapper_name" done + rm_na *.class + echo "$(script_fn) done." diff --git "a/developer/tool\360\237\226\211/make_example" "b/developer/tool\360\237\226\211/make_example" index 6eaf0c9..1abd031 100755 --- "a/developer/tool\360\237\226\211/make_example" +++ "b/developer/tool\360\237\226\211/make_example" @@ -4,8 +4,13 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") cd "$REPO_HOME"/developer || exit 1 source tool🖉/env_script +# Check if the directory $1 exists +if [ ! -d "example/$1" ]; then + echo "Error: Directory 'example/$1' does not exist." + exit 1 +fi -cd example || exit 1 +cd "example/$1" || exit 1 echo "Compiling example .java files..." diff --git a/temp.java b/temp.java new file mode 100644 index 0000000..460b5b4 --- /dev/null +++ b/temp.java @@ -0,0 +1,121 @@ + + +/* +An index Tree is infinite. + +A tree diagonal consists of +a) a node descending from each child discovered thus far +b> a node extending each child list discovered thus far. + +Hence, each diagonal extends the tree down one, and over one. + +*/ + + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import com.ReasoningTechnology.Ariadne.Ariadne_Test; +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; + +public class IndexTree_Diagonal_SRM extends Ariadne_SRM_Label>{ + + // Static + // + + public static IndexTree_Diagonal_SRM make(){ + return new IndexTree_Diagonal_SRM(); + } + + //Instance data + // + + private final List list_of__unopened_node; + // each node has a child list, this is a list of child lists + private final List> list_of__opened_incomplete_child_list; + // Each diagonal is a list of nodes, referenced by their label + private final List read_list; + + // Constructor(s) + // + + protected IndexTree_Diagonal_SRM(){ + list_of__unopened_node = new ArrayList<>(); + list_of__opened_incomplete_child_list = new ArrayList<>(); + read_list = new ArrayList<>(); + enqueue_root(); + } + + // Implementation of instance interface. + // + + private void enqueue_root(){ + Ariadne_IndexTree_Label root_label = Ariadne_IndexTree_Label.root(); + read_list.add(root_label); + + Ariadne_IndexTree_Node root_node = lookup(root_label); + if( !fetch_child_labels(root_node).isEmpty() ){ + list_of__unopened_node.add(root_label); + } + } + + // lol! This can not be done on an infinite list! + private List fetch_child_labels(Ariadne_IndexTree_Node node){ + List child_labels = new ArrayList<>(); + if(node != null){ + IndexTree_Diagonal_SRM child_srm = node.neighbor(); + if( child_srm.can_read() ){ + do{ + child_labels.add(child_srm.read()); + if( !srm.can_step ) break; + child_srm.step(); + }while(true); + } + } + return child_labels; + } + + @Override public List read(){ + return read_list; + } + + @Override public void step(){ + read_list.clear(); + + // Process unopened nodes + while( !list_of__unopened_node.isEmpty() ){ + BigInteger[] label = list_of__unopened_node.remove(0); + + // Retrieve the node using lookup + Ariadne_IndexTree_Node node = lookup(label); + + // Descend by getting neighbors + List child_labels = fetch_child_labels(node); + if( !child_labels.isEmpty() ){ + list_of__opened_incomplete_child_list.add(child_labels); + } + } + + // Process incomplete child lists + while( !list_of__opened_incomplete_child_list.isEmpty() ){ + List child_labels = list_of__opened_incomplete_child_list.remove(0); + if( !child_labels.isEmpty() ){ + BigInteger[] label = child_labels.remove(0); + read_list.add(label); + + // Retrieve node and check its neighbors + Ariadne_IndexTree_Node node = lookup(label); + if( !fetch_child_labels(node).isEmpty() ){ + list_of__unopened_node.add(label); + } + } + } + } + + private Ariadne_IndexTree_Node lookup(BigInteger[] label){ + // Perform a lookup to retrieve the node corresponding to the label + return Ariadne_IndexTree_Node.make(label); + } + +}