From: Thomas Walker Lynch Date: Thu, 2 Jan 2025 04:26:35 +0000 (+0000) Subject: check point before reconsidering the lock management feature of the SRM X-Git-Url: https://git.reasoningtechnology.com/home/twl/Documents/subuser/test_env.py?a=commitdiff_plain;h=43724fa99a3324720764b7933b199ae9e5162ae5;p=Ariadne check point before reconsidering the lock management feature of the SRM --- diff --git "a/developer/document\360\237\226\211/Step_Right_Machine.txt" "b/developer/document\360\237\226\211/Step_Right_Machine.txt" new file mode 100644 index 0000000..cee6bef --- /dev/null +++ "b/developer/document\360\237\226\211/Step_Right_Machine.txt" @@ -0,0 +1,50 @@ + 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. + + +----- + +public void lenient_mount() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Ensure the current tape is dismounted first + } + mount(); // Proceed to mount the new tape +} + +public void lenient_dismount() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Only dismount if a tape is currently mounted + } +} +Why This Works Without synchronized: +Thread Safety via LockManagerDelegate: + +LockManagerDelegate manages locks and ensures that only one thread can operate on the tape at a time. +When relinquish or request is called, the delegate ensures proper locking/unlocking. +No Shared State Changes in SRM Methods: + +The SRM methods (mount, dismount, lenient_mount, lenient_dismount) simply delegate to LockManagerDelegate and update internal state like Status. There’s no risk of race conditions if the delegate properly handles concurrent access. +Relinquishing Locks Last: + +By ensuring that relinquish is the last step in dismount and other relevant methods, we prevent premature lock release before operations are complete. diff --git "a/developer/document\360\237\226\211/bugs.txt" "b/developer/document\360\237\226\211/bugs.txt" new file mode 100644 index 0000000..54e96f2 --- /dev/null +++ "b/developer/document\360\237\226\211/bugs.txt" @@ -0,0 +1,5 @@ + + +2024-12-31T01:47:53Z + +The pencil on file names has been working well .. until yesterday. The jvm doesn't like the `example🖉` directory and refuses to run code in it, so I had to change it to `example`. diff --git a/developer/example/CountingNumber.class b/developer/example/CountingNumber.class index a4fa5c6..cce86a0 100644 Binary files a/developer/example/CountingNumber.class and b/developer/example/CountingNumber.class differ diff --git a/developer/example/CountingNumber.java b/developer/example/CountingNumber.java index 579049e..7cd8a37 100644 --- a/developer/example/CountingNumber.java +++ b/developer/example/CountingNumber.java @@ -25,8 +25,8 @@ public class CountingNumber extends Ariadne_SRM{ @Override public Status status(){ - if( i.equals(BigInteger.ZERO) ) return Status.AT_LEFTMOST; - else return Status.AT_MIDWAY; + if( i.equals(BigInteger.ZERO) ) return Status.LEFTMOST; + else return Status.INTERIM; } @Override diff --git a/developer/example/Example_Ariadne_SRM b/developer/example/Example_Ariadne_SRM deleted file mode 100755 index dadbafc..0000000 --- a/developer/example/Example_Ariadne_SRM +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java Example_Ariadne_SRM diff --git a/developer/example/Example_Ariadne_SRM.class b/developer/example/Example_Ariadne_SRM.class deleted file mode 100644 index 942cb60..0000000 Binary files a/developer/example/Example_Ariadne_SRM.class and /dev/null differ diff --git a/developer/example/Example_Ariadne_SRM.java b/developer/example/Example_Ariadne_SRM.java deleted file mode 100644 index 705a5ef..0000000 --- a/developer/example/Example_Ariadne_SRM.java +++ /dev/null @@ -1,24 +0,0 @@ -import com.ReasoningTechnology.Ariadne.Ariadne_SRM; -import com.ReasoningTechnology.Ariadne.Ariadne_Graph; - -import java.math.BigInteger; - -public class Example_Ariadne_SRM{ - - public static void main(String[] args){ - CountingNumber counting_number = CountingNumber.make(); - - System.out.println("Initial Status: " + counting_number.status()); - System.out.println("Initial Read Value: " + counting_number.read()); - - for( int step_index = 0 ;step_index < 10 ;step_index++ ){ - counting_number.step(); - System.out.println( - "Step: " + step_index - +", Status: " + counting_number.status() - +", Read Value: " + counting_number.read() - ); - } - } -} - diff --git a/developer/example/Example_Ariadne_SRM_Array.java b/developer/example/Example_Ariadne_SRM_Array.java deleted file mode 100644 index 079ab1b..0000000 --- a/developer/example/Example_Ariadne_SRM_Array.java +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index e95f2dd..0000000 --- a/developer/example/Example_Ariadne_SRM_List.java +++ /dev/null @@ -1,34 +0,0 @@ -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/example/Example_IdentityManager_0.java b/developer/example/Example_IdentityManager_0.java new file mode 100644 index 0000000..15bf9f6 --- /dev/null +++ b/developer/example/Example_IdentityManager_0.java @@ -0,0 +1,50 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_IdentityManager; + + +// Example Resource Class +class ExampleResource{ + + private final String name; + + public ExampleResource( String name ){ + this.name = name; + } + + public String get_name(){ + return name; + } + + @Override + public String toString(){ + return "ExampleResource{name='" + name + "'}"; + } + +} + +class Example_IdentityManager_0 { + + public static void main( String[] args ){ + IdentityManager manager = new IdentityManager<>( "ResourceNamespace" ); + + // Create resources and register them + String name1 = manager.generate_name(); + ExampleResource resource1 = new ExampleResource( name1 ); + manager.register( name1 ,resource1 ); + + String name2 = manager.generate_name(); + ExampleResource resource2 = new ExampleResource( name2 ); + manager.register( name2 ,resource2 ); + + // Access resources + System.out.println( "Resource 1: " + manager.get_resource( name1 ) ); + System.out.println( "Resource 2: " + manager.get_resource( name2 ) ); + + // Print all registered resources + System.out.println( manager ); + + // Unregister a resource + manager.unregister( name1 ); + System.out.println( "After unregistration: " + manager ); + } + +} diff --git a/developer/example/Example_IndexTree_0.java b/developer/example/Example_IndexTree_0.java new file mode 100644 index 0000000..306e475 --- /dev/null +++ b/developer/example/Example_IndexTree_0.java @@ -0,0 +1,36 @@ +import java.math.BigInteger; +import java.util.List; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Graph; +import com.ReasoningTechnology.Ariadne.Ariadne_IndexTree_Node; +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; + +public class Example_IndexTree_0 { + + public static void main(String[] args){ + // Create the IndexTree graph + Ariadne_IndexTree_Graph graph = new Ariadne_IndexTree_Graph(); + Ariadne_SRM srm = graph.start(); + + System.out.println("Starting Depth-First Traversal:"); + // Depth-First Traversal: Visit the leftmost child at each level + for (int i = 0; i < 4; i++){ + System.out.println("Step " + i + ": " + srm.read()); + srm = srm.neighbor(); // Move to the leftmost child + } + + System.out.println("\nStarting Breadth-First Traversal:"); + // Breadth-First Traversal: Visit all siblings before descending + for (int i = 0; i < 4; i++){ + System.out.println("Step " + i + ": " + srm.read()); + srm.step_right(); // Move to the next sibling + } + + System.out.println("\nStarting Diagonal Walk:"); + // Diagonal Walk: Alternate between descending and stepping right + for (int i = 0; i < 4; i++){ + System.out.println("Step " + i + ": " + srm.read()); + srm = srm.neighbor(); // Move to the first child + srm.step_right(); // Step to the sibling + } + } +} diff --git a/developer/example/Example_SRMI_Array.java b/developer/example/Example_SRMI_Array.java new file mode 100644 index 0000000..93a96c4 --- /dev/null +++ b/developer/example/Example_SRMI_Array.java @@ -0,0 +1,29 @@ +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 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_SRM_0.java b/developer/example/Example_SRM_0.java new file mode 100644 index 0000000..bd8a9b3 --- /dev/null +++ b/developer/example/Example_SRM_0.java @@ -0,0 +1,23 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; + +import java.math.BigInteger; + +public class Example_SRM_0{ + + public static void main(String[] args){ + CountingNumber counting_number = CountingNumber.make(); + + System.out.println("Initial Status: " + counting_number.status()); + System.out.println("Initial Read Value: " + counting_number.read()); + + for( int step_index = 0 ;step_index < 10 ;step_index++ ){ + counting_number.step(); + System.out.println( + "Step: " + step_index + +", Status: " + counting_number.status() + +", Read Value: " + counting_number.read() + ); + } + } +} + diff --git a/developer/example/Example_SRM_1.java b/developer/example/Example_SRM_1.java new file mode 100644 index 0000000..213b567 --- /dev/null +++ b/developer/example/Example_SRM_1.java @@ -0,0 +1,55 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; + +import java.util.Arrays; +import java.util.List; + +public class Example_Ariadne_SRM_1{ + + public static class SimpleLockManagerDelegate implements Ariadne_LockManagerDelegate{ + + @Override + public void request(Object srm){ + System.out.println("LockManagerDelegate: Lock acquired for " + srm); + } + + @Override + public void relinquish(Object srm){ + System.out.println("LockManagerDelegate: Lock released for " + srm); + } + } + + public static void main(String[] args){ + // Create a LockManagerDelegate + Ariadne_LockManagerDelegate delegate = new SimpleLockManagerDelegate(); + + // Create an SRM instance with the delegate + Ariadne_SRM srm = Ariadne_SRM.make(delegate); + + // Define a list to iterate over + List list = Arrays.asList(10 ,20 ,30 ,40 ,50); + + // Mount the list on the SRM + try{ + srm.mount(); + System.out.println("Mounted SRM. Status: " + srm.status()); + + // Iterate through the list + for(Integer value : list){ + System.out.println("Read value: " + value); + } + + // Dismount the SRM + srm.dismount(); + System.out.println("Dismounted SRM. Status: " + srm.status()); + }catch(IllegalStateException e){ + System.err.println("Error: " + e.getMessage()); + } + + // Demonstrate lenient methods + System.out.println("\nUsing lenient methods:"); + srm.lenient_mount(); + System.out.println("Lenient mount complete. Status: " + srm.status()); + srm.lenient_dismount(); + System.out.println("Lenient dismount complete. Status: " + srm.status()); + } +} diff --git a/developer/example/Example_SRM_List.java b/developer/example/Example_SRM_List.java new file mode 100644 index 0000000..772afde --- /dev/null +++ b/developer/example/Example_SRM_List.java @@ -0,0 +1,35 @@ +import com.ReasoningTechnology.Ariadne.Ariadne_SRM; +import com.ReasoningTechnology.Ariadne.Ariadne_SRM_List; + +import java.util.List; + +public class Example_SRM_List { + 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_OwnershipManager.java#" "b/developer/javac\360\237\226\211/#Ariadne_OwnershipManager.java#" new file mode 100644 index 0000000..06773c8 --- /dev/null +++ "b/developer/javac\360\237\226\211/#Ariadne_OwnershipManager.java#" @@ -0,0 +1,12 @@ +/* + + +*/ + + +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_OwnershipServer{ + Ariadne_LockManagerDelegate single_thread(Object resource); + Ariadne_LockManagerDelegate multiple_thread(Object resource); +} diff --git "a/developer/javac\360\237\226\211/Ariadne_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_Graph.java" index a5953a3..5c95392 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Graph.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Graph.java" @@ -8,12 +8,12 @@ package com.ReasoningTechnology.Ariadne; -public interface Ariadne_Graph { +public interface Ariadne_Graph { - // one or more nodes for starting graph traversals - Ariadne_SRM start(); + // One or more nodes for starting graph traversals + Ariadne_SRM start(); // Method to look up a node by label - Ariadne_Node lookup( Ariadne_Label label ); + Ariadne_Node lookup(T label); } diff --git "a/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" "b/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" new file mode 100644 index 0000000..a956a9b --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_IdentityManager.java" @@ -0,0 +1,63 @@ +/* +General purpose identity manager. Gives names to things. + + +*/ +package com.ReasoningTechnology.Ariadne; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +// General-purpose Identity Manager +public class IdentityManager implements Ariadne_ResourceIdentity{ + + private final String namespace; + private final AtomicInteger counter; + private final ConcurrentHashMap registry; + + public IdentityManager( String namespace ){ + if( namespace == null || namespace.isEmpty() ){ + throw new IllegalArgumentException( "IdentityManager::namespace cannot be null or empty." ); + } + this.namespace = namespace; + this.counter = new AtomicInteger(0); + this.registry = new ConcurrentHashMap<>(); + } + + public synchronized String generate_name(){ + return namespace + "_" + counter.incrementAndGet(); + } + + public synchronized void register( ResourceIdentity resource ){ + if( resource == null ){ + throw new IllegalArgumentException( "IdentityManager::resource cannot be null." ); + } + + String name = resource.get_name(); + if( name == null ){ + name = generate_name(); + resource.set_name( name ); + } + resource.lock_name(); + + if( registry.containsKey( name ) ){ + throw new IllegalArgumentException( "IdentityManager::name already exists: " + name ); + } + + registry.put( name ,resource ); + } + + public synchronized ResourceIdentity get_resource( String name ){ + return registry.get( name ); + } + + public synchronized void unregister( String name ){ + registry.remove( name ); + } + + @Override + public String toString(){ + return "IdentityManager{namespace='" + namespace + "' ,registeredResources=" + registry.keySet() + "}"; + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" new file mode 100644 index 0000000..9dbcf60 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Graph.java" @@ -0,0 +1,17 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; + +public class Ariadne_IndexTree_Graph implements Ariadne_Graph{ + + @Override + public Ariadne_IndexTree_SRM start(){ + return Ariadne_IndexTree_SRM.make(new BigInteger[0]); + } + + @Override + public Ariadne_IndexTree_Node lookup(BigInteger[] label){ + return Ariadne_IndexTree_Node.make(label); + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" new file mode 100644 index 0000000..405ca2a --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_Node.java" @@ -0,0 +1,28 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; +import java.util.Arrays; + +public class Ariadne_IndexTree_Node extends Ariadne_Node { + + public static Ariadne_IndexTree_Node make(BigInteger[] label){ + return new Ariadne_IndexTree_Node(label); + } + + public Ariadne_IndexTree_Node(BigInteger[] label){ + super(label); + } + + @Override + public Ariadne_IndexTree_SRM neighbor(){ + return new Ariadne_IndexTree_SRM(label()); + } + + @Override + public String toString(){ + return + "<" + + String.join("," ,Arrays.stream(label()).map(BigInteger::toString).toArray(String[]::new)) + + ">"; + } +} diff --git "a/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" new file mode 100644 index 0000000..b70c8a5 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_IndexTree_SRM.java" @@ -0,0 +1,40 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; + +public class Ariadne_IndexTree_SRM extends Ariadne_SRM { + + private final BigInteger[] current_label; + + public static Ariadne_IndexTree_SRM make(BigInteger[] initial_label){ + return new Ariadne_IndexTree_SRM(initial_label); + } + + protected Ariadne_IndexTree_SRM(BigInteger[] initial_label){ + super(); + if (initial_label == null || initial_label.length == 0) { + throw new IllegalArgumentException("Initial label must not be null or empty."); + } + this.current_label = initial_label; + } + + @Override + public Topology topology(){ + return Topology.INFINITE_RIGHT; + } + + @Override + public BigInteger[] read(){ + // Return a reference to the current label + return current_label; + } + + @Override + public boolean step(){ + // Increment the last element of the label (child counter) + int lastIndex = current_label.length - 1; + current_label[lastIndex] = current_label[lastIndex].add(BigInteger.ONE); + return true; + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_Node.java" "b/developer/javac\360\237\226\211/Ariadne_Node.java" index bfb632d..e23e1a4 100644 --- "a/developer/javac\360\237\226\211/Ariadne_Node.java" +++ "b/developer/javac\360\237\226\211/Ariadne_Node.java" @@ -55,7 +55,7 @@ public class Ariadne_Node extends HashMap { return this.label ; } - public Ariadne_SRM neighbors() { + public Ariadne_SRM neighbor() { return Ariadne_SRM.make() ; } @@ -76,7 +76,7 @@ public class Ariadne_Node extends HashMap { public String toString() { return "Ariadne_Node{" + "label=" + label - + ", markSet=" + markSet + + " ,markSet=" + markSet + "}" ; } } diff --git "a/developer/javac\360\237\226\211/Ariadne_OwnershipManager.java" "b/developer/javac\360\237\226\211/Ariadne_OwnershipManager.java" new file mode 100644 index 0000000..06773c8 --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_OwnershipManager.java" @@ -0,0 +1,12 @@ +/* + + +*/ + + +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_OwnershipServer{ + Ariadne_LockManagerDelegate single_thread(Object resource); + Ariadne_LockManagerDelegate multiple_thread(Object resource); +} diff --git "a/developer/javac\360\237\226\211/Ariadne_OwnershipManagerDelegate.java" "b/developer/javac\360\237\226\211/Ariadne_OwnershipManagerDelegate.java" new file mode 100644 index 0000000..35cd60d --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_OwnershipManagerDelegate.java" @@ -0,0 +1,6 @@ +package com.ReasoningTechnology.Ariadne; + +public interface Ariadne_Arbiter{ + void request(); + void relinquish(); +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM.java" "b/developer/javac\360\237\226\211/Ariadne_SRM.java" index 72e636f..422718f 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM.java" @@ -1,34 +1,29 @@ /* - 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. +Step Right Machine - 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. +This is a mostly abstract base class. - Information from the `topology` method will remain valid for as long as the topology of - the tape is not modified. +The SRM is for a single traversal through a bound resources. - 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. +In Java it is possible to declare a variable of the SRM type long before it is used +for traversal. This complicates managing ownwership of the resource being traversed. - 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. +The SRM model is that of 'mount' and 'dismount'. When the resource is mounted, +the SRM requests ownership of it. When it is dismounted, the SRM relinquishes +ownership. - 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. +mount and unmount are used for handling shared memory scenarios. See +the Ariadne_Access class. For single threaded execution pass in an +Ariadne_Access_Single instance. - 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; public class Ariadne_SRM{ - // Tape Topology public enum Topology{ NO_CELLS ,SEGMENT @@ -41,7 +36,6 @@ public class Ariadne_SRM{ ; } - // Machine Status public enum Status{ TAPE_NOT_MOUNTED ,LEFTMOST @@ -50,24 +44,68 @@ public class Ariadne_SRM{ ; } - public static Ariadne_SRM make(){ - return new Ariadne_SRM<>(); + private final LockManagerDelegate delegate; + + public static Ariadne_SRM make(LockManagerDelegate delegate){ + if(delegate == null){ + throw new IllegalArgumentException("Ariadne_SRM::make delegate cannot be null."); + } + return new Ariadne_SRM<>(delegate); + } + + private Ariadne_SRM(LockManagerDelegate delegate){ + this.delegate = delegate; + } + + public synchronized void mount(){ + if(status() != Status.TAPE_NOT_MOUNTED){ + throw new IllegalStateException("Ariadne_SRM::mount already mounted."); + } + delegate.request(this); + } + public void mount_lenient() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Ensure the current tape is dismounted first + } + mount(); // Proceed to mount the new tape + } + + + public synchronized void dismount(){ + if(status() == Status.TAPE_NOT_MOUNTED){ + throw new IllegalStateException("Ariadne_SRM::dismount not mounted."); + } + delegate.relinquish(this); + } + public void dismount_lenient() { + if(status() != Status.TAPE_NOT_MOUNTED) { + dismount(); // Only dismount if a tape is currently mounted + } + } + + public synchronized Topology topology(){ + return Topology.UNDEFINED; + } + + public synchronized Status status(){ + throw new UnsupportedOperationException("Ariadne_SRM::status not implemented."); } - protected Ariadne_SRM(){} - public Topology topology(){ - return Topology.UNDEFINED; // Default topology + public synchronized boolean can_step(){ + return + status() == Status.LEFTMOST + || status() == Status.INTERIM; } - public Status status(){ - return Status.TAPE_NOT_MOUNTED; // Default status + public synchronized boolean can_read(){ + return status() != Status.TAPE_NOT_MOUNTED; } - public T read(){ - throw new UnsupportedOperationException("Ariadne_SRM::can't read unmounted tape."); + public synchronized T read(){ + throw new UnsupportedOperationException("Ariadne_SRM::read not implemented."); } - public boolean step(){ - throw new UnsupportedOperationException("Ariadne_SRM::can't step unmounted tape."); + public synchronized void step(){ + throw new UnsupportedOperationException("Ariadne_SRM::step not implemented."); } } diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" index 60ec791..3ec1b76 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRMI.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI.java" @@ -8,7 +8,7 @@ import java.math.BigInteger; public class Ariadne_SRMI extends Ariadne_SRM{ - private BigInteger index; + protected BigInteger index; public static Ariadne_SRMI make(){ return new Ariadne_SRMI(); diff --git "a/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" new file mode 100644 index 0000000..2dcefba --- /dev/null +++ "b/developer/javac\360\237\226\211/Ariadne_SRMI_Array.java" @@ -0,0 +1,94 @@ +package com.ReasoningTechnology.Ariadne; + +import java.math.BigInteger; +import java.util.List; +import java.util.concurrent.Semaphore; + +public class Ariadne_SRMI_Array extends Ariadne_SRMI{ + + private List list; + private Semaphore lock; + + public static Ariadne_SRMI_Array make(){ + return new Ariadne_SRMI_Array<>(); + } + + protected Ariadne_SRMI_Array(){ + super(); + } + + public void mount(List list ,Semaphore semaphore){ + if(this.list != null){ + throw new IllegalStateException("Ariadne_SRMI_Array::mount tape already mounted."); + } + if(list == null){ + throw new IllegalArgumentException("Ariadne_SRMI_Array::mount list cannot be null."); + } + this.list = list; + this.lock = semaphore; + if(lock != null){ + try{ + lock.acquire(); + } catch(InterruptedException e){ + Thread.currentThread().interrupt(); + throw new IllegalStateException("Ariadne_SRMI_Array::mount interrupted while acquiring lock."); + } + } + set_status(list.isEmpty() ? Status.TAPE_NOT_MOUNTED : Status.LEFTMOST); + } + + public void unmount(){ + if(this.list == null){ + throw new IllegalStateException("Ariadne_SRMI_Array::unmount no tape mounted."); + } + this.list = null; + set_status(Status.TAPE_NOT_MOUNTED); + if(lock != null){ + lock.release(); + lock = null; + } + } + + @Override + public Topology topology(){ + if(list == null || list.isEmpty()){ + return Topology.NO_CELLS; + } + return Topology.SEGMENT; + } + + @Override + public Status status(){ + return super.status(); + } + + @Override + public T read(){ + if(!can_read()){ + throw new UnsupportedOperationException("Ariadne_SRMI_Array::read tape not mounted or out of bounds."); + } + return list.get(index().intValue()); + } + + @Override + public void step(){ + if(!can_step()){ + throw new UnsupportedOperationException("Ariadne_SRMI_Array::step, cannot step further."); + } + if(index().compareTo(rightmost_index()) < 0){ + index = index.add(BigInteger.ONE); + set_status(index().equals(rightmost_index()) ? Status.RIGHTMOST : Status.INTERIM); + } else{ + throw new UnsupportedOperationException("Ariadne_SRMI_Array::step, no more cells."); + } + } + + @Override + public BigInteger rightmost_index(){ + if(list == null){ + throw new UnsupportedOperationException("Ariadne_SRMI_Array::rightmost_index no tape mounted."); + } + return BigInteger.valueOf(list.size() - 1); + } + +} diff --git "a/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" "b/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" deleted file mode 100644 index 4e5aee4..0000000 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_Array.java" +++ /dev/null @@ -1,77 +0,0 @@ -/* -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" index dbaa949..db8fd48 100644 --- "a/developer/javac\360\237\226\211/Ariadne_SRM_List.java" +++ "b/developer/javac\360\237\226\211/Ariadne_SRM_List.java" @@ -1,34 +1,36 @@ /* -Suitable for attaching to a linked list structure. Something that -does not have fast random access ability. + The Ariadne_SRM_List class provides a Step Right Machine (SRM) for linked lists. + This implementation relies on Java's ListIterator, which lacks a direct method + to read the current element without advancing the iterator. -*/ + To address this, the `read` method temporarily moves the iterator back to access + the current element, then restores its position. This approach, referred to as the + "wiggle" method, is safe under the assumption of single-threaded execution. + In multi-threaded environments, external synchronization would be required to + ensure the list remains consistent during the wiggle operation. +*/ package com.ReasoningTechnology.Ariadne; import java.util.List; import java.util.ListIterator; -public class Ariadne_SRMI_List extends Ariadne_SRM { +public class Ariadne_SRM_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 + private final List list; // The attached linked list + private ListIterator iterator; // Iterator for traversal - // Factory method to attach SRM to a linked list - public static Ariadne_SRMI_List attach( List list ){ - return new Ariadne_SRMI_List<>( list ); + public static Ariadne_SRM_List mount(List list){ + return new Ariadne_SRM_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" ); + protected Ariadne_SRM_List(List list){ + if (list == null){ + throw new IllegalArgumentException("Ariadne_SRM_List::list cannot be null"); } this.list = list; this.iterator = list.listIterator(); - this.currentElement = iterator.hasNext() ? iterator.next() : null; } @Override @@ -38,40 +40,46 @@ public class Ariadne_SRMI_List extends Ariadne_SRM { @Override public Status status(){ - if( list.isEmpty() ){ + if (list.isEmpty()){ return Status.TAPE_NOT_MOUNTED; } - if( !iterator.hasPrevious() ){ + if (!iterator.hasPrevious() && iterator.hasNext()){ return Status.LEFTMOST; } - if( !iterator.hasNext() ){ + if (!iterator.hasNext() && iterator.hasPrevious()){ return Status.RIGHTMOST; } - return Status.INTERIM; + if (iterator.hasNext() && iterator.hasPrevious()){ + return Status.INTERIM; + } + return Status.TAPE_NOT_MOUNTED; // Fallback, should not occur } @Override public T read(){ - if( currentElement == null ){ - throw new UnsupportedOperationException( "Ariadne_SRMI_List::read, no current element." ); + if (status() == Status.TAPE_NOT_MOUNTED){ + throw new UnsupportedOperationException("Ariadne_SRM_List::read, tape not mounted."); + } + if (!iterator.hasPrevious()){ + throw new UnsupportedOperationException("Ariadne_SRM_List::read, no cell to read at the leftmost position."); } - return currentElement; + // Wiggle: Move back to read the current element, then restore position + T previous = iterator.previous(); + iterator.next(); // Restore iterator to the current position + return previous; } @Override - public boolean step(){ - if( iterator.hasNext() ){ - currentElement = iterator.next(); - return true; + public void step(){ + if (!iterator.hasNext()){ + throw new UnsupportedOperationException("Ariadne_SRM_List::step, no next cell."); } - currentElement = null; // Reached the end - return false; + iterator.next(); } // 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 diff --git "a/developer/tool\360\237\226\211/clean" "b/developer/tool\360\237\226\211/clean" index a32578f..6e55aec 100755 --- "a/developer/tool\360\237\226\211/clean" +++ "b/developer/tool\360\237\226\211/clean" @@ -13,8 +13,10 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") exit 1 fi -# remove files - set -x +set -x + +# remove main build files + cd "$REPO_HOME"/developer # rm_na currently does not handle links correctly @@ -22,7 +24,13 @@ script_afp=$(realpath "${BASH_SOURCE[0]}") rm_na jvm/* rm_na bash/* - set +x + + +# remove example class files + + rm_na example/*.class + +set +x 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 5868b53..b766bd5 100755 --- "a/developer/tool\360\237\226\211/make_example" +++ "b/developer/tool\360\237\226\211/make_example" @@ -25,7 +25,7 @@ echo "Compiling example .java files..." echo "Creating bash wrappers..." # wrapper is a space separated list - wrapper=Example_Ariadne_SRM + wrapper=Example_*.class for file in $wrapper;do cat > $file << EOL #!/bin/bash