Enumerate all valid orders of subset sums

Given an positive integer $ n$ , we define an order of subset sums to be a sequence of all subsets of $ \{1,\ldots,n\}$ . For example, when $ n=2$ , the sequence $ \emptyset,\{1\},\{2\},\{1,2\}$ is an order of subset sums.

We call an order of subset sums $ S_1,\ldots,S_{2^n}$ valid if there exist real numbers $ 0<x_1<\cdots<x_n$ such that $ \sum_{i\in S_1}x_i<\cdots<\sum_{i\in S_{2^n}}x_i$ . For example, when $ n=2$ , the sequence $ \emptyset,\{1\},\{2\},\{1,2\}$ is a valid order of subset sums, but the sequence $ \emptyset,\{1\},\{1,2\},\{1\}$ is not a valid order of subset sums because we cannot make $ x_1+x_2<x_1$ .

The question is, given $ n$ , how to enumerate all possible valid orders of subset sums. I know this problem cannot be solved in time polynomial in $ n$ , because there may be exponentially many valid orders of subset sums, so an algorithm with exponential time is welcome.

A trivial algorithm would be to iterate over all possible orders of subset sums, and check for each one if it is valid. But I cannot even find an (efficient) way to check if an order of subset sums is valid.

Enumerate all paths in a given series-parallel graph

Series parallel graph is well-known and widely used. It has a single source and a single destination. The graph can be formed by means of recursive serial or parallel composition.


I have a graph dataset that is of this type, and I have to enumerate all paths in the series-parallel graphs. Are there any existed algorithms? If so, what is the time complexity of it?

Enumerate all members and types with specific attributes

I have a use-case where I need to retrieve all members with specific attributes in the class and interface hierarchy – I usually need the first match and apply its rules to child members. The built-in GetCustomAttributes are too limited becuase they work only for a single member and don’t support interfaces.


To solve this I wrote my own extension that returns a collection of AttributeCollection<T> instances. Each one contains the member the attributes are applied to and the matched attributes.

There are couple of rules that this needs to follow in order for the results to be useful because attribute settings are then propagated to child members:

  • properties come before types
  • classes come before interfaces
  • skip duplicate results
public static class Extensions {     public static IEnumerable<AttributeCollection<T>> EnumerateCustomAttributes<T>(this MemberInfo member) where T : Attribute     {         if (member == null) throw new ArgumentNullException(nameof(member));          var queue = new Queue<MemberInfo>         {             member,         };          // Helps to suppress duplicate results when same member is seen multiple times.         var seenAttributeCollections = new HashSet<AttributeCollection<T>>();          while (queue.Any())         {             var current = queue.Dequeue();              if (current.GetCustomAttributes<T>() is var attributes && attributes.Any())             {                 var attributeCollection = new AttributeCollection<T>(current, attributes);                 if (seenAttributeCollections.Add(attributeCollection))                 {                     yield return attributeCollection;                 }             }              if (current is PropertyInfo property)             {                 queue.Enqueue(property.DeclaringType);             }              if (current is Type type)             {                 // The order matters so enqueue properties before their declaring types and base classes before interfaces.                  if (type.IsSubclass())                 {                     if (type.BaseType.GetProperty(member.Name) is PropertyInfo otherProperty)                     {                         queue.Enqueue(otherProperty);                     }                      queue.Enqueue(type.BaseType);                 }                  foreach (var interfaceType in type.GetInterfaces())                 {                     if (interfaceType.GetProperty(member.Name) is PropertyInfo otherProperty)                     {                         queue.Enqueue(otherProperty);                     }                      queue.Enqueue(interfaceType);                 }             }         }     }      public static bool IsSubclass(this Type type)     {         return type.IsClass && type.BaseType != typeof(object);     }    } 

This class helps handling equality and results:

public class AttributeCollection<T> : List<T>, IEquatable<AttributeCollection<T>> where T : Attribute {     private static readonly IEqualityComparer<AttributeCollection<T>> Comparer = EqualityComparerFactory<AttributeCollection<T>>.Create     (         // When either one is True then we consider both collections equal.         equals: (x, y) => (x.Member == y.Member) || x.SequenceEqual(y)     );      public AttributeCollection(MemberInfo member, IEnumerable<T> attributes) : base(attributes)     {         Member = member;     }      public MemberInfo Member { get; }      public bool Equals(AttributeCollection<T> other) => Comparer.Equals(this, other);      public override bool Equals(object obj) => obj is AttributeCollection<T> ac && Equals(ac);      public override int GetHashCode() => 0; // Always use 'equals'. } 


I used this code to test that extension:

void Main() {     typeof(T3).GetProperty(nameof(T3.P1)).EnumerateCustomAttributes<A0>().Dump(); // <-- 6 results     typeof(T3).GetProperty(nameof(T3.P1)).EnumerateCustomAttributes<A1>().Dump(); // <-- 5 results     typeof(T3).GetProperty(nameof(T3.P1)).EnumerateCustomAttributes<A2>().Dump(); // <-- 3 results }  [A1(V = "I1")] interface I1 {     [A1(V = "I1.P1")]     string P1 { get; set; } }  [A2(V = "T1")] class T1 : I1 {     [A1(V = "T1.P1")]     public virtual string P1 { get; set; } }  class T2 : T1 { }  [A1(V = "T3"), A2(V = "T3")] class T3 : T2 {     [A1(V = "T3.P1"), A2(V = "T3.P1")]     public override string P1 { get; set; } }  interface IA {     string V { get; set; } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] abstract class A0 : Attribute, IA { public abstract string V { get; set; } } class A1 : A0 { public override string V { get; set; } } class A2 : A0 { public override string V { get; set; } } 

In this example you’ll notice that I use both an interface and an abstract class overriding the V property. It turned out that I cannot use a single property on the base class because the Attribute.Equals method won’t see it and will not recognize two different attributes correctly. See this question.

If you’re going to try this demo in LINQPad then you’ll need this header as I’m using some of my helpers here:

<Query Kind="Program">   <NuGetReference>Reusable.Core</NuGetReference>   <Namespace>Reusable.Extensions</Namespace>   <Namespace>Reusable.Collections</Namespace> </Query> 

Real-world example

I’ll be using it for retrieving UseX attributes in a model like this one:

[UsePrefix("app"), UseNamespace, UseType, UseMember] [TrimStart("I")] public interface IDemo : INamespace {     [UseType, UseMember]     object Greeting { get; } // <-- will use its own attributes      [Tag("io")]     object ReadFile { get; } // <-- will use type's attributes } 


So, what do you think about this implementation? Am I missing anything important here? Is there anything you would improve?

Enumerate over all halting Turing Machines?

I understand that it is possible to enumerate over all Turing Machines. My understanding of how this works is by fixing an encoding of natural numbers to TM descriptions, and then enumerating the natural numbers and checking whether each number describes a syntactically well-defined TM.

I am wondering how it is possible to enumerate over all halting TMs. My intuition tells me that since the halting problem is undecidable, it should not be possible to filter an enumeration of all TM descriptions to only those TM descriptions which describe halting TMs.

Nevertheless, I recently came across a well-reputed paper that used an enumeration of all halting Turing Machines (see Proposition 1, pg. 2). I’d appreciate any help in understanding this.

Can we enumerate finite sequences which have no halting continuation?

Note: this question has been cross-posted to Math.SE, after about a week here.

I am trying to deepen my understanding of the relationship between the Halting Problem and Godel’s Completeness Theorem (not Incompleteness).

Specifically, as I understand it the Completeness Theorem guarantees a finite proof for any first-order logical statement which holds in all countable models of a first-order theory. (This is my restatement of Wikipedia’s “Every syntactically consistent, countable first-order theory has a finite or countable model.”)

Since the statement “Program $ P_n$ (encoded by integer $ n$ ) does not halt” can presumably be stated in first-order logic and cannot in general be proven, we need to understand why (for given $ n$ ) it does not hold in all countable models.

Intuitively, I expect that any countable model can be encoded as an infinite program for a Turing machine, eg by listing the countable set of first-order propositions. Likewise, I expect that any such “infinite Turing machine” can be identified with a countable first-order theory, by the Church-Turing thesis plus induction.

So, just as the Completeness Theorem fails to “solve” arithmetic because of non-standard models with infinite integers (which eg satisfy otherwise unsatisfiable Diophantine equations), I’m speculating that it fails for Turing machines because of non-standard models with “infinite programs”.

But by my understanding statements which are true in all models (including non-standard / infinite ones) should still be provable. So I expect that if some finite set of axioms, which “pins down” some finite set of digits of a potentially infinite program, is enough to prevent the possibility of halting, we should be able to prove it.

Or in other words, if a finite sequence does not have any continuation which encodes a halting program, that should be provable.

Does my logic hold? Or what am I misunderstanding?

The reason this is not trivially wrong by Rice’s Theorem is that it’s a property of the program itself, rather than the language recognized by that program, which is $ \emptyset$ for the programs I’m talking about.

dmesg unable to enumerate usb device on google nexus 7 2013 wifi version

I installed android file transfer and flashed the ROM of Google Nexus 2013 WIFI tablet by executing the flash-all script command on my macbook pro macOS Mojave. This tablet has issue with usb connection before and it will drop the USB connection after few minutes. I believe the usb connection disconnected while trying to write the firmware to the tablet. The dmesg shows the following now after the ROM flash failure

[44561.880936] usb 1-1-port2: Cannot enable. Maybe the USB cable is bad? [44562.790961] usb 1-1-port2: Cannot enable. Maybe the USB cable is bad? [44562.791046] usb 1-1-port2: unable to enumerate USB device

This is what i have tried so far

  1. Use different USB cables
  2. Create 51-android.rules file and then reboot

    pi@raspberrypi:~ $ cat /etc/udev/rules.d/51-android.rules SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e41″, MODE=”0666″, > OWNER=“pi” # MTP media (multimedia device) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e42″, MODE=”0666″, > OWNER=“pi” # MTP media with USB debug on(multimedia device) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e43″, MODE=”0666″, > OWNER=“pi” # PTP media (camera) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e44″, MODE=”0666″, > OWNER=“pi” # PTP media with USB debug on (camera) SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e40″, MODE=”0666″, > OWNER=“pi” # Bootloader SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”d001″, MODE=”0666″, > OWNER=“pi” # Recovery

  3. lsusb did not show the google nexus devices

  4. Hard reset and factory reset the tablet
  5. Added product id into adb_usb.ini pi@raspberrypi:~ $ cat ~/.android/adb_usb.ini 0x18d1
  6. Took out cover and then disconnect the battery connection and then reconnect

I have done all the above using raspberry pi with raspbian OS. However, the raspberry pi is still not able to recognize my tablet.

I did the following on the Windows computer as well. I plugged in the device and checked the device manager application. It says that the device is unknown. I downloaded the driver from the internet and then try to update it through the device manager. Computer tells me that there is no driver installed while simultaneously saying that the driver is up to date. I believe I have enabled the USB debugging method before the ROM flash but the tablet seems to be completely out of OS now. I am just wondering whether anyone has solution to this?I have tried a lot of method with no avail