A simple clarification on polynomial hierarchy

$ P^{NP}\subseteq BPP^{NP}$ holds. According to current knowledge $ BPP$ is in $ \Sigma_2^P\cap\Pi_2^P$ holds. So according to current knowledge is following true?

  1. $ P^{\Sigma_2^P\cup\Pi_2^P}\subseteq BPP^{NP}\subseteq(\Sigma_2^P\cap\Pi_2^P)^{NP}\subseteq\Sigma_3^P\cap\Pi_3^P$ ?

  2. Is $ P^{\Sigma_2^P\cup\Pi_2^P}$ the largest standard polynomial hierarchy class in $ BPP^{NP}$ and is $ (\Sigma_2^P\cap\Pi_2^P)^{NP}$ the smallest standard polynomial hierarchy class containing $ BPP^{NP}$ ?

Is there any official lore that describes the hierarchy in temples of Pelor?

Is there any official lore for any setting in D&D that describes a hierarchy of clergy in temples dedicated to Pelor?

Something similar to the deacon/priest/diocesan bishop/archbishop etc. in the Catholic Church. Or any other major religious group in lore that I could base it on?

I’d love answers coming from any edition of D&D. I need inspiration and would prefer it to come from official lore sources.

simpler hierarchy method than using taxonomy?

In Drupal 8… I have a couple instances where I need taxonomies with hierarchy, to be able to search by. But the taxonomy sizes are Large. Generally, the standard Drupal Taxonomy is wonderful. But I, very intentionally, want these two taxonomies to be stripped down because it’s causing unnecessary load for the server.

To clarify size – Hierarchical Taxonomy 1 would be: Continent(7) –> Subcontinent(24) –> countries/regions(241) –> states/provinces(4000+)

Hierarchal Taxonomy 2 is, literally, a plant taxonomy, with items at various depths, 5 – 10 levels deep, and totalling at Least 1,000 taxonomy terms.

I know Drupal can handle this.. but with my current resources, this kills database and server space, and chokes the site.

I was looking at trying to understand Nested Sets, but the Taxonomy is often changed as new discoveries modify understanding – and making edits seems to be a weak point to the Nested Set.

Maybe there’s some XML solution, or simpler way without so many tables being created in Drupal

Move file with specific extension from a directory hierarchy to a destination

I have a directory hierarchy containing many images with .jpg file-extension, and there are multiple folders containing these images. There are many .json files as well in these folders.

Is there a way to scan all these subfolders and move the .jpg files to a specific destination/folder?

Why is $BPP^{NP}$ in the polynomial hierarchy?

Why is $ BPP^{NP}$ in the polynomial hierarchy? I know that $ BPP$ is contained in $ NP^{NP}$ , so $ BPP$ is inside $ PH$ . Should I just simply reuse the proof of $ BPP\subset NP^{NP}$ , feed in each machine an oracle solving 3SAT problem, and show that $ BPP^{NP}\subset NP^{NP^{NP}}$ ? Is it because normally, the proof in complexity theory can be easily relativized by an oracle?

Is there more apt terminology to research: order management systems comprised of a hierarchy of entities?

I’ve been grappling with a project at work that seemed straightforward at first but then began to spring up increasingly complex corner cases. Over time I noticed many similarities between this project and one at my previous job, which was basically an order management system (OMS). With how common OMSes are, I feel someone must have exhaustively solved every kind of problem that OMSes can have, from an abstracted system design perspective. But I’m having trouble finding any such reference, using keywords like:

system design architecture order management system oms version mismatch 

The specific subproblem I’m trying to gain insight on is this:

  • You have orders that you send to an external Source of Truth (SoT), be it buy and sell orders on a stock exchange, or line items on an ad server.
  • You provide an interface for your customers to create and manage their orders that get routed to the SoT.
  • Orders have many, many states, affectable by either the customer or the SoT, and they are also versioned but not necessarily audited (i.e. you can’t retrieve the order as it looked N versions ago).
  • Message crossovers are possible. (This is the heart of the matter.) Either there are periods of rapid activity (e.g. opening bell on the stock exchange) that literally cross over with traders’ actions that were made with stale information, or actions take time to formulate or review (e.g. a UI where account managers review the details of an order to approve it) but during that time the order in question may have changed (e.g. edited by the customer, etc.)

How do you design a system that makes sure nothing unexpected happens, at least not without sufficiently notifying the user (and if applicable, reconciling with the SoT). Is there a name or reference for this specific genre of problems? To give very specific examples:

  • There should be an error if the customer attempts to edit the non-latest version of an order.
  • But if the customer’s edit and the latest version are identical, it can be useful to silently succeed (e.g. user can apply an action from different views in the UI; opens a browser tab and commits one action, then in another tab commits another action that implies the first action).

Actually, up to this point, I can handle / come up with a system design myself. But there’s an added dimension (literally) that, in my experience, makes both systems extremely complex and error-prone:

  • Orders are actually a hierarchy of entities, each with a unique set of states and rules, though all versioned. For the stock exchange, the OMS may have had a concept of “parent orders” that housed “child orders.” Worse, the ads OMS has a five-layer hierarchy. What kind of problems do hierarchies introduce? Well, if editing a parent order cascades edits to its child orders, but one the child edits fail at the SoT, what is the state of the parent? If the serving state of an ad depends on all 5 layers being “approved,” and one layer has been edited, … you get the idea.

Is there not a named discipline or textbook that covers: Designing an Order Management System of a Hierarchy of Versioned Entities. That’s what I’m hoping to find out how to research. Originally, I thought maybe I should try to write that reference. But after a few brainstorming sessions, I think I’m in way over my head, and it just seems there’s no way someone didn’t already think all variations of this problem through.

Non-indexed or indexed top hierarchy pages get high PageRank at Google?


We are creating some pages just to capture leads from blog-posts. We created few pages at top hierarchy like website.com/new-page/. I’m just wondering if these pages will take away more PageRank. Do we need to create these pages at low hierarchy like website.com/folder/new-page to avoid passing more PageRank? Is this is how PR distributed even now and it’s same for indexed or non-indexed pages?


“Detailed” exception class hierarchy

I’m designing an modular exception class hierarchy to use in various projects. I intend to inherit from std::exception in order to be maximally compatible with any exception-handling code. A design goal is that each exception’s what() method returns a string which contains a base message, which is dependent on the object’s most specific class (i.e. equal for all objects of the class), and an optional instance-specific details message which specifies the origin of the exception.

The two main goals are ease of use (as in when throwing the exceptions), as well as ensuring that writing another exception subclass is as simple and repetition-free as possible.

Base class

The base exception class I wrote is the following. It is conceptually an abstract class, but not syntactically, since I don’t have any virtual method to make pure virtual. So, as an alternative, I made all constructors protected.

/**  * Base class for all custom exceptions. Stores a message as a string.  * Instances can only be constructed from within a child class,  * since the constructors are protected.  */ class BaseException : public std::exception { protected:     std::string message;  ///< message to be returned by what()      BaseException() = default;      /**      * Construct a new exception from a base message and optional additional details.      * The base message is intended to be class-specific, while the additional      * details string is intended to be instance-specific.      *      * @param baseMessage  generic message for the kind of exception being created      * @param details  additional information as to why the exception was thrown      */     BaseException(const std::string &baseMessage, const std::string &details = "") {         std::ostringstream oss(baseMessage, std::ios::ate);         if (not details.empty()) oss << " (" << details << ')';         message = oss.str();     }  public:     /// `std::exception`-compliant message getter     const char *what() const noexcept override {         return message.c_str();     } }; 

The intention of the above design is that any subclass of BaseException defines a constructor that passes a class-specific base message (as the baseMessage paramter) and an optional detail-specifier (as the details parameter) as arguments to BaseException‘s constructor.

Errors & warnings

Since I want to be able to differentiate between general exception “types”, e.g. errors vs. warnings, I’ve made the following two virtually-inherited bases:

class Error: public virtual BaseException {};  class Warning : public virtual BaseException {}; 


Here are some (project-specific) examples of implementing concrete exception subclasses with this design:

/// Indicates that a command whose keyword is unknown was issued class UnknownCommand : public Error { public:     static constexpr auto base = "unrecognized command";     UnknownCommand(const std::string &specific = "") : BaseException(base, specific) {} };   /// Indicates an error in reading or writing to a file class IOError : public Error { public:     static constexpr auto base = "unable to access file";     IOError(const std::string &specific = "") : BaseException(base, specific) {} };   /// Indicates that an algorithm encountered a situation in which it is not well-defined; /// i.e., a value that doesn't meet a function's prerequisites was passed. class ValueError : public Error { public:     static constexpr auto base = "invalid value";     ValueError(const std::string &specific = "") : BaseException(base, specific) {} };  # [...]  

As you can see, the common pattern is

class SomeException : public Error /* or Warning */ { public:     static constexpr auto base = "some exception's generic description";     SomeException(const std::string &details) : BaseException(base, details) {} } 

Usage example

Taking the previous IOError class as an example:

#include <iostream> #include <fstream> #include "exceptions.h"  // all of the previous stuff  void cat(const std::string &filename) {     std::ifstream file(filename);     if (not file.is_open()) throw IOError(filename);     std::cout << file.rdbuf(); }  int main(int argc, char **argv) {     for (int i = 1; i < argc; ++i) {         try { cat(argv[i]); }         catch (std::exception &e) { std::cerr << e.what() << '\n'; }     } } 

In case of calling the program with an inaccessible file path, e.g. the path “foo”, it should output

unable to access file (foo) 

Mechanism to view and browse complex hierarchy

I’m trying to find the best way to display hierarchy information and to allow the user to explore structural information. At the moment there are the following levels but there could be more potentially:

Field > Installation > Substructure Group > Substructure > Component

The first option that came to my mind is a Tree View but I am not sure it’s the best way of achieving this as so many levels of hierarchy can end up in something slow and hard to interact with.

Another idea I’m considering is a number of panels from left to right conveying the hierarchy (similar to what Finder in OSX does) but this would just work well for up to a few levels so I still have the impression that there must be a better way of achieving this.

Do you guys have any suggestion?

Many thanks!

Progress reporting of a hierarchy of operations

I needed a way to track and report the progress of a hierarchy of operations, the only example I could find on the web is progressive but it’s written in Python, a language I don’t know.

So I just wrote my own from scratch in C# and I would like you to review it.

enter image description here

The example program, a console application:

  • generates a trivial example
  • prints the output to the console
  • there is an issue in GetProgressBar, I need to care about dividing by zero, I don’t know why


using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;  namespace ConsoleApp1 {     internal static class Program     {         private static async Task Main()         {             var root = new ProgressNode {Name = "Root"};              var child1 = root.CreateChild("Child 1");             child1.CreateChild("Child 1A");             child1.CreateChild("Child 1B");              var child2 = root.CreateChild("Child 2");             child2.CreateChild("Child 2A");             child2.CreateChild("Child 2B");              var child3 = root.CreateChild("Child 3");             child3.CreateChild("Child 3A");             child3.CreateChild("Child 3B");              var child4 = root.CreateChild("Child 4");             child4.CreateChild("Child 4A");             child4.CreateChild("Child 4B");              root.ProgressChanged += OnProgressChanged;              var nodes = root.GetLeafs().ToArray();             var tasks = new List<Task>();              var random = new Random();              foreach (var node in nodes)             {                 var task = Task.Run(async () =>                 {                     var total = random.Next(1, 50 + 1);                     var delay = random.Next(10, 100 + 1);                      for (var i = 0; i < total; i++)                     {                         await Task.Delay(delay);                         node.SetProgress(total, i + 1);                     }                 });                 tasks.Add(task);             }              await Task.WhenAll(tasks);             Console.WriteLine("Done!");             Console.ReadKey();         }          #region Console output          private static readonly object Sync = new object();          private static void OnProgressChanged(object sender, EventArgs e)         {             var root = (ProgressNode) sender;              lock (Sync) // cheap hack for slow console             {                 Console.SetCursorPosition(0, 0); // another cheap hack                  var flatten = root.Flatten(s => s);                 foreach (var node in flatten)                 {                     var indent = 0;                     var current = node;                     while (current.Parent != null)                     {                         current = current.Parent;                         indent++;                     }                      var value = node.GetTotalProcessed();                     var total = node.GetTotalElements();                     var progress = GetProgressBar(50, value, total);                     var text = $  "{new string(' ', indent)} '{node.Name}' {progress} {value} of {total}\r\n";                     Console.WriteLine(text);                 }             }         }          public static string GetProgressBar(int width, int value, int total, char foreground = '█', char background = '░')         {             var d = 1.0d / Math.Max(total, 1) * value; // avoid division by zero             var i = (int) Math.Round(d * width);             var s1 = new string(foreground, i);             var s2 = new string(background, width - i);             var s3 = $  "{s1}{s2}";             return s3;         }          #endregion     } } 

The main class, ProgressNode:

It is modeled after the tree data structure, where each leaf node participates in progress reporting. Thanks to LINQ, counting the progress is rather easy.


using System; using System.Collections; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations;  namespace ConsoleApp1 {     /// <summary>     ///     Defines a node that participates in a hierarchy of progress.     /// </summary>     public sealed class ProgressNode : IEnumerable<ProgressNode>     {         public ProgressNode([CanBeNull] ProgressNode parent = null)         {             Parent = parent;         }          #region IEnumerable<ProgressNode> Members          /// <inheritdoc />         IEnumerator IEnumerable.GetEnumerator()         {             return GetEnumerator();         }          /// <inheritdoc />         public IEnumerator<ProgressNode> GetEnumerator()         {             return Children.GetEnumerator();         }          #endregion          #region Events          /// <summary>         ///     Occurs when progress has changed.         /// </summary>         public event EventHandler ProgressChanged;          private void OnProgressChanged()         {             ProgressChanged?.Invoke(this, EventArgs.Empty);         }          #endregion          #region Public Methods          /// <summary>         ///     Creates a child of this instance.         /// </summary>         /// <param name="name"></param>         /// <returns></returns>         public ProgressNode CreateChild([CanBeNull] string name = null)         {             var child = new ProgressNode(this) {Name = name};              Children.Add(child);              return child;         }          /// <summary>         ///     Gets the leaf nodes of this instance.         /// </summary>         /// <returns></returns>         public IEnumerable<ProgressNode> GetLeafs()         {             return this.Flatten(s => s).Where(s => s.IsLeaf);         }          /// <summary>         ///     Gets the count of total elements for this instance and its descendants.         /// </summary>         /// <returns></returns>         public int GetTotalElements()         {             if (IsRoot)             {                 return this.SelectMany(s => s).Sum(s => s.Progress.Total);             }              if (IsNode)             {                 return this.Sum(s => s.Progress.Total);             }              if (IsLeaf)             {                 return Progress.Total;             }              throw new InvalidOperationException("Instance state is not valid.");         }          /// <summary>         ///     Gets the count of elements processed for this instance and its descendants.         /// </summary>         /// <returns></returns>         public int GetTotalProcessed()         {             if (IsRoot)             {                 return this.SelectMany(s => s).Sum(s => s.Progress.Value);             }              if (IsNode)             {                 return this.Sum(s => s.Progress.Value);             }              if (IsLeaf)             {                 return Progress.Value;             }              throw new InvalidOperationException("Instance state is not valid.");         }          /// <summary>         ///     Sets the progress of this instance.         /// </summary>         /// <param name="total"></param>         /// <param name="value"></param>         public void SetProgress(int total, int value)         {             if (total <= 0)                 throw new ArgumentOutOfRangeException(nameof(total));              if (value <= 0 || value > total)                 throw new ArgumentOutOfRangeException(nameof(value));              if (!IsLeaf)                 throw new InvalidOperationException("Progress can only be set on a leaf node.");              Progress.Total = total;             Progress.Value = value;              Root.OnProgressChanged();         }          /// <inheritdoc />         public override string ToString()         {             return $  "{nameof(Name)}: {Name}, {nameof(Progress)}: {Progress}";         }          #endregion          #region Private Properties          private IList<ProgressNode> Children { get; } = new List<ProgressNode>();          private bool IsLeaf => Parent != null && !Children.Any();          private bool IsNode => Parent != null && Children.Any();          private bool IsRoot => Parent == null;          private Progress Progress { get; } = new Progress();          private ProgressNode Root         {             get             {                 var current = this;                  while (current.Parent != null)                 {                     current = current.Parent;                 }                  return current;             }         }          #endregion          #region Public Properties          /// <summary>         ///     Gets or sets the name of this instance.         /// </summary>         public string Name { get; set; }          /// <summary>         ///     Gets the parent of this instance.         /// </summary>         public ProgressNode Parent { get; }          #endregion     } } 

Helper classes:

This stores the actual progress for a leaf node:

namespace ConsoleApp1 {     /// <summary>     ///     Represents the progress of an operation.     /// </summary>     internal sealed class Progress     {         public int Total { get; set; }          public int Value { get; set; }          public override string ToString()         {             return $  "{nameof(Total)}: {Total}, {nameof(Value)}: {Value}";         }     } } 

This flattens a hierarchy of elements:

using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using JetBrains.Annotations;  namespace ConsoleApp1 {     [SuppressMessage("ReSharper", "InconsistentNaming")]     public static class IEnumerableExtensions     {         /// <summary>         ///     Flattens a hierarchy of elements.         /// </summary>         /// <typeparam name="T"></typeparam>         /// <param name="source"></param>         /// <param name="selector"></param>         /// <returns></returns>         public static IEnumerable<T> Flatten<T>([NotNull] this T source, [NotNull] Func<T, IEnumerable<T>> selector)         {             if (source == null)                 throw new ArgumentNullException(nameof(source));              if (selector == null)                 throw new ArgumentNullException(nameof(selector));              yield return source;              foreach (var node in selector(source).SelectMany(s => Flatten(s, selector)))             {                 yield return node;             }         }     } } 

I’ve also put the project online for convenience: https://github.com/aybe/ProgressHierarchy

Thank you!