What algorithms/data structures should I look into for parametric & subtyping polymorphism implementation in a toy language?

I’ve been trying to replicate a simple imperative OOP language that supports subtype and parametric polymorphism. So far I’ve got the basics down: simple control flow statements, variable declaration/assignment, function declaration & calls.

Thing is, my implementation so far is pretty on-the-fly, I’ve been using pretty elementary concepts to implement the things listed above: dictionaries for variable/function declarations (with a few guards to keep track of scope), a stack for program execution, and 2 class hierarchies for expressions (things that can be evaluated and return a value) and statements (things that modify the program state). Subtyping and generics on the other hand sound a little more complex and I’m trying to find some resources to see how I could implement them.

At the type level, the project is extremely simple – I only support a few primitives as of right now. I have an interface for Types that all primitives implement:

public interface Type {
    boolean instanceOf(Type other);
    Value getDefaultValue();
}

so integers for instance look something like this:

public class IntType implements Type {
    public boolean instanceOf(Type other) { return this.getClass().equals(other.getClass()); }
    public IntValue getDefaultValue() { return new IntValue(0); }
    public String toString() { return "int"; }
}

Extending the code in an OO direction would imply the following:

the ability to declare new types (classes) => I’ll probably need a new dictionary-like structure for types

classes have member variables and methods => whatever the new representation for types is, it’ll need to have a list of variables and methods (don’t think I’ll bother with access specifiers yet)

a way to define subtyping relationships between classes => most likely a function that tells us whether B is a subtype of A for any A, B

parameterizing means implementing some sort of symbolic types that are replaced at run time just like with variables

And then all this stuff needs to be implemented in a way that can be type checked at compile time.

So if anyone has any resources that cover this sort of stuff please let me know.

data structures – How do we pick and switch hash functions from a universal family?

When we have a universal family of hash functions, it gives us a few useful mathematical guarantees. But, if we pick a specific function from the family and use it all the time it’s effectively like the family doesn’t exists and we only have this one function.

Therefore, the only logical thing seems to be switching a hash function every once in a while (picking a new function from our family). If indeed this is what we should do, how often should we switch functions? How should this time period be selected and is there an optimal time period for different tasks?

soft question – Weaker systems than ZFC that contain richer structures

The standard foundation we have in mathematics today is ZFC set theory and classical logic. But there have been a number of theories, whose proponents criticize ZFC. There are ultra finitists, who criticize pretty much everything about ZFC. Other people just criticize the Axiom of Choice. Then there are advocates of intuitionistic logic, who despise using the Law of Excluded Middle.

When I hear these mathematicians speak about their views, the question I’ve always had is: “Yes, but what do we actually gain by weakening our system?” If the reasons to reject ZFC are philosophical, I’m not persuaded. I choose pragmatism over philosophy since I’m an anti-realist and so choosing my axiomatic system doesn’t violate some kind of objective, holy laws of the universe.

But if considering weaker systems have actually interesting implications, that’s an another story. So, I would like to know whether there are actually any interesting theories developed in a weaker framework than ZFC that one can’t have in ZFC. I do know that constructive mathematics is very useful, when writing theorem provers, but I’m more interested in the pure maths side of things.

Thank you!

gr.group theory – How to classify rings by combinatorial structures?

There are many ways to encode information about algebraic structures such as groups, rings, etc… in combinatorial form. For example the Cayley graph of a group with a subset of generators, or the various graphs associated to rings, as can be found in, e.g., the answers to
Why do we associate a graph to a ring?. So I was wondering about the converse questions, which for groups and rings take the form:

First question(s): Given $X$ a graph is there a way to discover, intrinsically, constructively and algorithmically, whether it is the Cayley graph of a group? How to recover the group structure from the graph? Is there a unique group $G$ such that $X = CG(G)$, the Cayley graph of $G$? How to find such a group $G$? Which graphs are the Cayley Graphs of some Group?

Second Question: Is there a combinatorial structure (such as a system of graphs) associated to rings (or algebra or module of an algebra) from which you can recover the full ring (or module) in a similar manner as in the first question? Preferably in an intrinsic, constructive and algorithmic way. Assuming one could find such a combinatorial category, how to find out which objects in it are the objects associated to rings (or modules)?

I would also be interested in considering similar types of questions for general well-known algebraic structures (some kind of combinatorial informational encoding for these algebraic structures) in the sense that you can define precisely combinatorial structures out of algebraic structures, intrinsically constructively and algorithmically, but from which you can recover the original structure, also intrinsically constructively and algorithmically and intrinsically.

For groups, there is positive answer given by Sabidussi’s theorem, as mentioned in https://en.wikipedia.org/wiki/Cayley_graph#Characterization, which characterizes graphs which are Cayley Graphs of groups. This theorem would suffice in terms of instrisic, constructive and algorithmic profile of the proof, for question 1.

I would be satisfied with partial answers.

data structures – Given a binary min-heap, find the $k$-th element

I’m given a binary min-heap (implemented with an array) and need to come up with a (simple) efficient (no more than $k$ comparisons) to find the $k$-th minimal element.

My attempt was as follows:

  1. check who is the smallest among the root children
  2. scan the corresponding sub-heap maintaining a counter counting how many nodes are smaller than the larger child of the root (but larger than the smaller child). If the counter reaches $k-1$ return the value of the current node. other-wise after the scan is finished, call this method recursively on the larger root child to find the ($k$ $-$ couter_value + 1)-th minimal element of the larger child.

I just can’t put this together formally and not sure this can be implemented with no more than $k$ comparisons.

Thanks for any help.

data structures – Reverse An Array whats wrong with this type of code?

data structures – Reverse An Array whats wrong with this type of code? – Computer Science Stack Exchange

Are there paths of exact forms joining two symplectic structures on open manifolds?

There is a Theorem of Conolly, L$hat{text{e}}$ and Ono which states that on a closed simply-connected $4$-manifold two cohomologous symplectic forms can be joined by a path of non-degenerate $2$-forms.

I was wondering is there any open analogue of this theorem? For example:

Let $omega_0$ and $omega_1$ be two cohomologous symplectic structures on an open simply-connected $4$-manifold $M$ which are equal on the complement of some compact set. Are there any results on the existence of a path ${omega_t}_{tin [0,1]}$ of non-degenerate $2$-forms joining $omega_0$ and $omega_1$ such that all $omega_t$ are equal on the complement of some compact set?

I am especially interested in the case $M=mathbb{R}^4$.

data structures – Should Binary Expressions make use of built in functions in interpreters?

I have been developing a statically typed language with support for autocasting. The language has a lot of built in functions with good support for overloading. I’ve noticed that this built in function system could be used to evaluate binary expressions by implementing operator built in functions with different overloads e.g.

int operator+(int, int)
float operator+(float, float)  
int operator-(int, int)
float operator-(float, float)  

It feels like I’m doubling up my efforts to handle operator evaluation, when realistically they could piggyback the built in method system which has type checking and links the node (my interpreter uses the visitor pattern) to the actual function that would retrieve the parameters and do some computation with them – effectively what the old operator system already has to evaluate an expression.

Does this approach sound sensible? In theory it sounds good to me but I don’t know if I’m oversighting something. I know that all languages must have a intrinsic implementation for operators, but I don’t know how they link it to the actual AST.

Implementation

If this approach is indeed a good approach, at what level should I implement the built in function support to a binary expression? For example I could adjust the parser so that when it receives 2+2 it can generate a methodCall node with parameters (2, 2) and the name operator+, which would effectively treat all operators as calls to methods from the get go. Or I could stick with a binaryExpression node and link it to the correct function during semantic analysis.

data structures – Sort a d-sorted array

Given an array (1,…,n), The array will be called d-sorted, if every key in the array is located in a distance not greater then a constant d from his location in the sorted array A

I need to write algorithms that get a d-sorted array with the length of n and sorts the array in the runtime of:

  1. Θ(n) if d is a constant
  2. Θ(n(log(log(n)))) if d is Θ(log(n))

My Attempts:
I wrote this following pseudo-code:

Sort_d_array(A(),d)
 min-heap-size <- d
 for i <- 1 to n 
    BUILD-MIN-HEAP(min-heap,heap-size)
      if min-heap not empty
        then EXTRACT-MIN <- A(i)
          if i+d<=n
            then heap-insert-min(min-heap,A(i+d))   

But in terms of runtime, all I get is BigO(nlog(log(d)))

MY METHOD: I initialized i <- 1 and then I built a min-heap that contains all of the first d elements
as long as the heap is not empty, I used EXTRACT-MIN and put the element at i index in
the array and if i+d<=n, then A(i+d) will be an element in the
min-heap

Any help?

lo.logic – Are there structures in a finite signature that are recursively categorically axiomatizable in SOL but not finitely categorically axiomatizable?

Recall that a structure $mathcal{M} = langle M, I^sigma_M rangle$ in a signature $sigma$ is categorically axiomatized by a second-order theory $T$ when, for any $sigma$-structure $mathcal{N} = langle N, I^sigma_N rangle$, $langle N, mathcal{P}(N), I^sigma_N rangle vDash T$ just in case $mathcal{N}$ is isomorphic to $mathcal{M}$.

It is fairly easy to find a structure in a finite signature that is categorically second-order axiomatizable but not finitely categorically second-order axiomatizable. Add a single function symbol $f$ to the language of second-order arithmetic, and choose a non-second-order-definable $zeta: mathbb{N} rightarrow mathbb{N}$. Then consider the theory $T$ that adds to the axioms of second-order arithmetic ($mathsf{Z}^2$) the sentence $f(bar{n}) = overline{zeta(n)}$ for each natural number $n$, where $bar{m}$ is the canonical numeral for $m$. (I owe the idea for this example to Andrew Bacon.)

This theory $T$, however, is not recursively axiomatizable. Is there a structure in a finite signature that has a recursive categorical second-order axiomatization but no finite categorical second-order axiomatization?

I believe that it is possible to find a recursively axiomatizable second-order theory $T$ whose spectrum (i.e., the set ${kappa in mathsf{Card}: exists mathcal{M} (mathcal{M} vDash T$ and $vert mathscr{M} vert = kappa)}$) is shared by no finitely axiomatizable second-order theory, using partial truth predicates. (Consider the theory with $mathsf{Z}^2$ relativized to some predicate $N$ and ${$“The cardinality of the non-$N$s is not $Sigma^1_n$-characterizable”$: n in omega}$.) But I cannot see how to turn this into a categorical theory.

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123