From: Thomas Walker Lynch Date: Mon, 30 Dec 2024 16:04:09 +0000 (+0000) Subject: adds SRMs and some examples X-Git-Url: https://git.reasoningtechnology.com/style/static/git-favicon.png?a=commitdiff_plain;h=282f4a5ac2b12f2a0ac7ac4ba6a65b41d5789831;p=Ariadne adds SRMs and some examples --- diff --git a/developer/deprecated/Ariadne_LabelList.java b/developer/deprecated/Ariadne_LabelList.java new file mode 100644 index 0000000..6b2c3e0 --- /dev/null +++ b/developer/deprecated/Ariadne_LabelList.java @@ -0,0 +1,67 @@ +/* +A list of Labels. +*/ + +package com.ReasoningTechnology.Ariadne; + +import java.util.List; +import java.util.ArrayList; + +public class Ariadne_LabelList extends ArrayList{ + + // owned by the class + // + public static Ariadne_LabelList make(Object...label_list){ + return new Ariadne_LabelList(label_list); + } + + // data owned by the instance + // + + // constructors + // + public Ariadne_LabelList(Object...label_list){ + super(); + if(label_list != null){ + this.add(List.of(label_list)); // Delegate work to the add method + } + } + + // instance interface + // + public boolean add(Object...obj_list){ + boolean modified = false; + if(obj_list != null) for(Object obj:obj_list) modified |= add_one(obj); + return modified; + } + + // Object interface + // + @Override + public String toString(){ + return super.toString(); + } + + // private helpers + // + private boolean add_one(Object obj){ + if(obj instanceof String){ + return add_one((String) obj); + }else if(obj instanceof Ariadne_Label){ + return add_one((Ariadne_Label) obj); + } + throw new IllegalArgumentException( + "Ariadne_LabelList::add_one, cannot make label from object of type: " + obj.getClass().getName() + ); + } + + private boolean add_one(String string){ + return super.add(Ariadne_Label.make(string)); + } + + private boolean add_one(Ariadne_Label label){ + return super.add(label); + } +} + + diff --git a/developer/deprecated/Ariadne_LabelList2.java b/developer/deprecated/Ariadne_LabelList2.java new file mode 100644 index 0000000..0c85cf6 --- /dev/null +++ b/developer/deprecated/Ariadne_LabelList2.java @@ -0,0 +1,128 @@ +/* + A 'tape' as a model for computation is a sequence of cells, where something can be written or read from each cell. We talk about the sequence as though written on paper, running from left to right. The elements in the sequence have neighbors, so the sequence of cells can be said to be mutually connected. This is to say that if cell B is to the right of cell A in the sequence, then cell A is to the left of cell B; Also if cell A is to the left of cell B, then cell B is to the right of cell A. + + One of the cells on the tape is specially marked as being the 'mounted cell'. This is the cell that can be written or read after the tape is mounted on a 'tape machine', and before any steps have been taken. + + Information from the `topology` method will remain valid for as long as the topology of + the tape is not modified. + + A finite tape will have a leftmost cell, which has no left neighbor, and a rightmost cell, which has no right neighbor. All other cells will have two neighbors. + + A tape can have an infinite number of cells to the left of the mount point, to the right of the mount point, or in both directions. Hence it is possible that two, one, or zero cells on a tape have only one neighbor, where the zero neighbor case is for finite tapes, and the latter cases are for infinite tapes. + + An algorithm running on a tape machine that has a left going tape can be translated into an algorithm for a right going tape simply by swapping `step_right` for `step_left`. Hence there is no utility to be had by keeping both models. + + Another isomorphism can be setup between a single ended tape and a double direction tape by replacing each step by two steps, and then placing odd cell into correspondence with the right going tape, and even cells with left going tape. Hence an algorithm implemented over the top of either can be mechanically transformed to an algorithm for the other. + + However, what we can not do without affecting the power of our computation machine is to + eliminate 'step-left', yet this is a common simplification in data structures. The Lisp language is based on single linked lists for example. + + This 'Step Right Machine' (SRM) defined here can only be stepped to the right. Thus whether cells are mutually connected, or not, becomes irrelevant. Also, saying 'leftmost' is a feature of the tape, becomes muddled, as the mount point cell will be the leftmost cell that is ever visited. + + A SRM can be defined using functions, or it can be used as an iterator for traversing through a container. + + The property methods defined here are kept general so that they can be used with other tape machines. +*/ + +package com.ReasoningTechnology.Ariadne; + +import java.util.ArrayList; +import java.util.List; + +public class Ariadne_SRM_LabelList extends Ariadne_SRM{ + + // owned by the class + public static Ariadne_LabelList make(){ + return new Ariadne_LabelList(); + } + + public static Ariadne_LabelList make( Object...label_list ){ + Ariadne_LabelList instance = new Ariadne_LabelList(); + instance.add( List.of( label_list ) ); + return instance; + } + + // data owned by the instance + private ArrayList list; + private int current_index; + + // constructors + protected Ariadne_LabelList(){ + super(); + this.list = new ArrayList<>(); + this.current_index = -1; // No label mounted initially + } + + // instance interface + @Override + public Topology topology(){ + return list.isEmpty() ? Topology.NO_CELLS : Topology.SEGMENT; + } + + @Override + public Status status(){ + if( list.isEmpty() ){ + return Status.TAPE_NOT_MOUNTED; + } + if( current_index == 0 ){ + return Status.LEFTMOST; + } + if( current_index == list.size() - 1 ){ + return Status.RIGHTMOST; + } + return Status.INTERIM; + } + + @Override + public Ariadne_Label read(){ + if( current_index < 0 || current_index >= list.size() ){ + throw new UnsupportedOperationException( "Ariadne_SRM::read, out of bounds or unmounted tape." ); + } + return list.get( current_index ); + } + + @Override + public boolean step(){ + if( current_index + 1 < list.size() ){ + current_index++; + return true; + } + return false; // Cannot step further + } + + public boolean add( List obj_list ){ + boolean modified = false; + if( obj_list != null ){ + for( Object obj : obj_list ){ + modified |= add_one( obj ); + } + } + return modified; + } + + @Override + public String toString(){ + return list.toString(); + } + + // private helpers + private boolean add_one( Object obj ){ + if( obj instanceof String ){ + return add_one( (String) obj ); + } else if( obj instanceof Ariadne_Label ){ + return add_one( (Ariadne_Label) obj ); + } + throw new IllegalArgumentException( + "Ariadne_LabelList::add_one, cannot make label from object of type: " + obj.getClass().getName() + ); + } + + private boolean add_one( String string ){ +// return list.add( Ariadne_Label.make( string ) ); + return false; + } + + private boolean add_one( Ariadne_Label label ){ + return list.add( label ); + } +} diff --git a/developer/example/Example_Ariadne_SRM.class b/developer/example/Example_Ariadne_SRM.class index ed6f5d6..942cb60 100644 Binary files a/developer/example/Example_Ariadne_SRM.class and b/developer/example/Example_Ariadne_SRM.class differ diff --git a/developer/example/Example_Ariadne_SRM.java b/developer/example/Example_Ariadne_SRM.java index e7a4e28..705a5ef 100644 --- a/developer/example/Example_Ariadne_SRM.java +++ b/developer/example/Example_Ariadne_SRM.java @@ -1,8 +1,11 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import com.ReasoningTechnology.Ariadne.Ariadne_Graph; + import java.math.BigInteger; -public class Example_Ariadne_SRM { +public class Example_Ariadne_SRM{ - public static void main(String[] args) { + public static void main(String[] args){ CountingNumber counting_number = CountingNumber.make(); System.out.println("Initial Status: " + counting_number.status()); @@ -18,3 +21,4 @@ public class Example_Ariadne_SRM { } } } + diff --git a/developer/example/Example_Ariadne_SRM_Array.java b/developer/example/Example_Ariadne_SRM_Array.java new file mode 100644 index 0000000..079ab1b --- /dev/null +++ b/developer/example/Example_Ariadne_SRM_Array.java @@ -0,0 +1,28 @@ +package com.ReasoningTechnology.Ariadne; + +import java.util.Arrays; +import java.util.List; + +public class Main { + public static void main( String[] args ) { + // Create a list + List labels = Arrays.asList( "A" ,"B" ,"C" ,"D" ); + + // Attach SRMI to the list + Ariadne_SRMI_Array srm = Ariadne_SRMI_Array.attach( labels ); + + // Use the SRMI + System.out.println( "Topology: " + srm.topology() ); + System.out.println( "Status: " + srm.status() ); + + // Traverse the list + while( srm.status() != Ariadne_SRM.Status.RIGHTMOST ) { + System.out.println( "Reading: " + srm.read() ); + srm.step(); + } + + // Final item + System.out.println( "Reading: " + srm.read() ); + System.out.println( "Status: " + srm.status() ); + } +} diff --git a/developer/example/Example_Ariadne_SRM_List.java b/developer/example/Example_Ariadne_SRM_List.java new file mode 100644 index 0000000..e95f2dd --- /dev/null +++ b/developer/example/Example_Ariadne_SRM_List.java @@ -0,0 +1,34 @@ +package com.ReasoningTechnology.Ariadne; + +import java.util.List; + +public class Main { + public static void main( String[] args ) { + // Create a linked list + List labels = new List<>(); + labels.add( "A" ); + labels.add( "B" ); + labels.add( "C" ); + + // Attach SRMI to the linked list + Ariadne_SRMI_List srm = Ariadne_SRMI_List.attach( labels ); + + // Use the SRMI + System.out.println( "Topology: " + srm.topology() ); + System.out.println( "Status: " + srm.status() ); + + // Traverse the list + while( srm.status() != Ariadne_SRM.Status.RIGHTMOST ) { + System.out.println( "Reading: " + srm.read() ); + srm.step(); + } + + // Final item + System.out.println( "Reading: " + srm.read() ); + System.out.println( "Status: " + srm.status() ); + + // Reset the SRM and traverse again + srm.reset(); + System.out.println( "After reset: " + srm.read() ); + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_DirectedGraph.xjava" "b/developer/javac\360\237\226\211/Ariadne_DirectedGraph.xjava" deleted file mode 100644 index 941d935..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_DirectedGraph.xjava" +++ /dev/null @@ -1,26 +0,0 @@ -package com.ReasoningTechnology.Ariadne; - -/* - To define a graph, extend this class and define `lookup`. - - For a wellformed graph, each start label will be a label for a node found in the graph. -*/ - - -import java.util.HashMap; -import java.util.Map; - -package com.ReasoningTechnology.Ariadne; - -public class Ariadne_Graph{ - - public static Ariadne_DirectedGraph make(Object...obj_list){ - return new Ariadne_DirectedGraph(); - } - - public Ariadne_StepRightMachine start(); - public Ariadne_StepRightMachine traverse(); - public Ariadne_Node lookup(String label); - - -} diff --git "a/developer/javac\360\237\226\211/Ariadne_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_Graph.java" index c91114d..a5953a3 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Graph.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Graph.java" @@ -1,18 +1,19 @@ -package com.ReasoningTechnology.Ariadne; - /* - To define a graph, extend this class and define `start` and `lookup`. + User defines a graph by implementing this interface. For the build tool, the defined + graph is dynamically loaded. - For a wellformed graph, each start label will be a label for a node found in the graph. + In a wellformed graph, the labels returned by `start()` will be in the graph. This + can be checked by calling `lookup`. */ -public interface Ariadne_Graph{ +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_Graph { - public static Ariadne_Graph make(Object...obj_list){ - return new Ariadne_Graph(); - } + // one or more nodes for starting graph traversals + Ariadne_SRM start(); - public Ariadne_SRM start(); - public Ariadne_Node lookup(String label); + // Method to look up a node by label + Ariadne_Node lookup( Ariadne_Label label ); } diff --git "a/developer/javac\360\237\226\211/Ariadne_LabelList.xjava" "b/developer/javac\360\237\226\211/Ariadne_LabelList.xjava" deleted file mode 100644 index 6b2c3e0..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_LabelList.xjava" +++ /dev/null @@ -1,67 +0,0 @@ -/* -A list of Labels. -*/ - -package com.ReasoningTechnology.Ariadne; - -import java.util.List; -import java.util.ArrayList; - -public class Ariadne_LabelList extends ArrayList{ - - // owned by the class - // - public static Ariadne_LabelList make(Object...label_list){ - return new Ariadne_LabelList(label_list); - } - - // data owned by the instance - // - - // constructors - // - public Ariadne_LabelList(Object...label_list){ - super(); - if(label_list != null){ - this.add(List.of(label_list)); // Delegate work to the add method - } - } - - // instance interface - // - public boolean add(Object...obj_list){ - boolean modified = false; - if(obj_list != null) for(Object obj:obj_list) modified |= add_one(obj); - return modified; - } - - // Object interface - // - @Override - public String toString(){ - return super.toString(); - } - - // private helpers - // - private boolean add_one(Object obj){ - if(obj instanceof String){ - return add_one((String) obj); - }else if(obj instanceof Ariadne_Label){ - return add_one((Ariadne_Label) obj); - } - throw new IllegalArgumentException( - "Ariadne_LabelList::add_one, cannot make label from object of type: " + obj.getClass().getName() - ); - } - - private boolean add_one(String string){ - return super.add(Ariadne_Label.make(string)); - } - - private boolean add_one(Ariadne_Label label){ - return super.add(label); - } -} - - diff --git "a/developer/javac\360\237\226\211/Ariadne_Node.java" "b/developer/javac\360\237\226\211/Ariadne_Node.java" index fac11d5..e2d46f7 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Node.java" @@ -1,35 +1,64 @@ +/* +A node extends a Map. This map is for use by the user to add properties to the node. +It is not used by the Ariadne code. The class itself is already a sort of map, so +node specific fields are expressed in the class itself. + +Node specific fields include the node label, and a set for Ariadne algorithms +to use when adding token marks to nodes. An extension will have to add +a function or data set to hold the labels of neighboring nodes. + +Currently node labels are strings. I should probably have made them a +generic type. + +A graph itself is a similar data structure to the Node. A graph is defined by its +lookup function, that makes it a map. Also there is a start function that returns +node labels, while a node has 'neighbor' which returns node labels. Here are the +differences: + + The graph type lookup implementation is not constrained to any type, and + could be a function. The node lookup comes from a HashMap, and thus is + guaranteed to have a finite number of entries. + + The graph type is defined by the user, where as the node type is defined + by the programmer who is creating a graph based application. + +We should take a closer look at the possibility of unifying these later. + +*/ + + package com.ReasoningTechnology.Ariadne; + import java.util.HashMap; import java.util.HashSet; -public class Ariadne_Node extends HashMap{ +public class Ariadne_Node extends HashMap{ // owned by the class - // public static Ariadne_Node make(Ariadne_Label label){ return new Ariadne_Node(label); } // data owned by the instance - // private Ariadne_Label label; - private HashSet mark_set; + private HashSet mark_set; + private static final String neighbor_property_name = "neighbor_property"; // constructors - // public Ariadne_Node(Ariadne_Label label){ super(); this.label = label; - this.market_set = new HashSet; + this.mark_set = new HashSet(); } // instance interface - // public Ariadne_Label label(){ return this.label; } - public Ariadne_StepRightMachine neighbor_set(); + public Ariadne_SRM neighbor(){ + return Ariadne_SRM.make(); + } public void mark(Ariadne_Token token){ mark_set.add(token); @@ -39,12 +68,17 @@ public class Ariadne_Node extends HashMap{ return mark_set.contains(token); } - public Ariadne_LabelList neighbor(){ - return(Ariadne_LabelList) this.get(neighbor_property_name); + public void mark_remove(Ariadne_Token token){ + mark_set.remove(token); } // Object interface - // - + @Override + public String toString(){ + return "Ariadne_Node{" + + "label=" + label + + " ,mark_set=" + mark_set + + "}"; + } } diff --git "a/developer/javac\360\237\226\211/Ariadne_NodeList.xjava" "b/developer/javac\360\237\226\211/Ariadne_NodeList.xjava" deleted file mode 100644 index 69e4284..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_NodeList.xjava" +++ /dev/null @@ -1,10 +0,0 @@ -// NodeList.java -package com.ReasoningTechnology.Ariadne; -import java.util.ArrayList; - -public class Ariadne_NodeList extends ArrayList { - // Constructor - public Ariadne_NodeList(){ - super(); - } -} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" index a2aee82..72e636f 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM.java" @@ -28,7 +28,7 @@ package com.ReasoningTechnology.Ariadne; public class Ariadne_SRM{ - // Enum for Tape Topology + // Tape Topology public enum Topology{ NO_CELLS ,SEGMENT @@ -41,12 +41,12 @@ public class Ariadne_SRM{ ; } - // Enum for Machine Status + // Machine Status public enum Status{ TAPE_NOT_MOUNTED - ,AT_LEFTMOST - ,AT_MIDWAY - ,AT_RIGHTMOST + ,LEFTMOST + ,INTERIM + ,RIGHTMOST ; } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" new file mode 100644 index 0000000..4e5aee4 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" @@ -0,0 +1,77 @@ +/* +Suitable for attaching to containers that have efficient random access. + +*/ + +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; +import java.util.List; + +public class Ariadne_SRMI_Array extends Ariadne_SRMI { + + private final List list; + + // Factory method to attach SRMI to a list + public static Ariadne_SRMI_List attach( List list ){ + return new Ariadne_SRMI_List<>( list ); + } + + // Private constructor + private Ariadne_SRMI_List( List list ){ + if( list == null ){ + throw new IllegalArgumentException( "Ariadne_SRMI_List::list cannot be null" ); + } + this.list = list; + } + + @Override + public Ariadne_SRM.Topology topology(){ + if( list.isEmpty() ){ + return Ariadne_SRM.Topology.NO_CELLS; + } + return Ariadne_SRM.Topology.SEGMENT; + } + + @Override + public Ariadne_SRM.Status status(){ + if( list.isEmpty() ){ + return Ariadne_SRM.Status.TAPE_NOT_MOUNTED; + } + if( index().equals( BigInteger.ZERO ) ){ + return Ariadne_SRM.Status.LEFTMOST; + } + if( index().equals( rightmost_index() ) ){ + return Ariadne_SRM.Status.RIGHTMOST; + } + return Ariadne_SRM.Status.INTERIM; + } + + @Override + public T read(){ + if( list.isEmpty() || index().compareTo( rightmost_index().add( BigInteger.ONE ) ) >= 0 ){ + throw new UnsupportedOperationException( "Ariadne_SRMI_List::read, out of bounds." ); + } + return list.get( index().intValue() ); + } + + @Override + public boolean step(){ + if( index().compareTo( rightmost_index() ) < 0 ){ + BigInteger new_index = index().add( BigInteger.ONE ); + set_index( new_index ); + return true; + } + return false; // Reached the end of the list + } + + @Override + public BigInteger rightmost_index(){ + return BigInteger.valueOf( list.size() - 1 ); + } + + // Optional: Provide access to the underlying list for inspection + public List getList(){ + return list; + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" new file mode 100644 index 0000000..dbaa949 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" @@ -0,0 +1,81 @@ +/* +Suitable for attaching to a linked list structure. Something that +does not have fast random access ability. + +*/ + + +package com.ReasoningTechnology.Ariadne; + +import java.util.List; +import java.util.ListIterator; + +public class Ariadne_SRMI_List extends Ariadne_SRM { + + private final List list; // The attached linked list + private ListIterator iterator; // Iterator for traversal + private T currentElement; // Tracks the current element + + // Factory method to attach SRM to a linked list + public static Ariadne_SRMI_List attach( List list ){ + return new Ariadne_SRMI_List<>( list ); + } + + // Private constructor to enforce factory usage + private Ariadne_SRMI_List( List list ){ + if( list == null ){ + throw new IllegalArgumentException( "Ariadne_SRMI_List::list cannot be null" ); + } + this.list = list; + this.iterator = list.listIterator(); + this.currentElement = iterator.hasNext() ? iterator.next() : null; + } + + @Override + public Topology topology(){ + return list.isEmpty() ? Topology.NO_CELLS : Topology.SEGMENT; + } + + @Override + public Status status(){ + if( list.isEmpty() ){ + return Status.TAPE_NOT_MOUNTED; + } + if( !iterator.hasPrevious() ){ + return Status.LEFTMOST; + } + if( !iterator.hasNext() ){ + return Status.RIGHTMOST; + } + return Status.INTERIM; + } + + @Override + public T read(){ + if( currentElement == null ){ + throw new UnsupportedOperationException( "Ariadne_SRMI_List::read, no current element." ); + } + return currentElement; + } + + @Override + public boolean step(){ + if( iterator.hasNext() ){ + currentElement = iterator.next(); + return true; + } + currentElement = null; // Reached the end + return false; + } + + // Optional: Reset to the beginning of the list + public void reset(){ + this.iterator = list.listIterator(); + this.currentElement = iterator.hasNext() ? iterator.next() : null; + } + + // Optional: Get the underlying linked list + public List getList(){ + return list; + } +} diff --git "a/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" "b/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" new file mode 100644 index 0000000..941d935 --- /dev/null +++ "b/developer/javac\360\237\226\211/hold/Ariadne_DirectedGraph.java" @@ -0,0 +1,26 @@ +package com.ReasoningTechnology.Ariadne; + +/* + To define a graph, extend this class and define `lookup`. + + For a wellformed graph, each start label will be a label for a node found in the graph. +*/ + + +import java.util.HashMap; +import java.util.Map; + +package com.ReasoningTechnology.Ariadne; + +public class Ariadne_Graph{ + + public static Ariadne_DirectedGraph make(Object...obj_list){ + return new Ariadne_DirectedGraph(); + } + + public Ariadne_StepRightMachine start(); + public Ariadne_StepRightMachine traverse(); + public Ariadne_Node lookup(String label); + + +} diff --git "a/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" "b/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" new file mode 100644 index 0000000..69e4284 --- /dev/null +++ "b/developer/javac\360\237\226\211/hold/Ariadne_NodeList.xjava" @@ -0,0 +1,10 @@ +// NodeList.java +package com.ReasoningTechnology.Ariadne; +import java.util.ArrayList; + +public class Ariadne_NodeList extends ArrayList { + // Constructor + public Ariadne_NodeList(){ + super(); + } +}