Skip to content

Commit

Permalink
2024/02/10 - Slowly towards a more sensible implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
FadiShawki committed Jan 10, 2024
1 parent 7ce9785 commit d6ee5ba
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 77 deletions.
19 changes: 19 additions & 0 deletions src/@orbitmines/explorer/JS.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {JS} from "./Ray";

describe("JS", () => {
test(".Object", () => {
const ray = JS.Object({
a: 'b',
position: [0, 1, 2],
func: () => 'c'
});

expect(ray.any.a).toBe('b');
expect(ray.any.test).toBe(undefined);
expect(() => ray.any.undefinedFunction()).toThrow();
expect(ray.any.position).toEqual([0, 1, 2]);
expect(ray.any.func()).toBe('c');
});


});
58 changes: 41 additions & 17 deletions src/@orbitmines/explorer/Ray.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import {JS, Ray, RayType} from "./Ray";
import {PreventsImplementationBug} from "./errors/errors";
import {Ray, RayType} from "./Ray";

describe("JS", () => {
test(".Object", () => {
const ray = JS.Object({
a: 'b',
position: [0, 1, 2],
func: () => 'c'
});

expect(ray.any.a).toBe('b');
expect(ray.any.test).toBe(undefined);
expect(() => ray.any.undefinedFunction()).toThrow();
expect(ray.any.position).toEqual([0, 1, 2]);
expect(ray.any.func()).toBe('c');
})
});
describe("Ray", () => {
// test(".vertex.#.debug", () => {
// const a = Ray.vertex().as_reference();
Expand Down Expand Up @@ -77,6 +61,26 @@ describe("Ray", () => {
expect(initial.is_reference()).toBe(false);
expect(initial.type).toBe(RayType.INITIAL);
});
test(".initial.#", () => {
/** [ |-?] */ const initial = Ray.initial().as_reference();

expect(initial.self.initial.is_none()).toBe(true);
expect(initial.self).not.toBe(initial.self.self); // If self-referential, that means none.

expect(initial.self.terminal.initial).toBe(initial.self);

expect(initial.self.is_none()).toBe(false);
expect(initial.self.self.is_none()).toBe(true);

expect(initial.is_some()).toBe(true);
expect(initial.self.terminal.is_none()).toBe(false);

expect(initial.is_initial()).toBe(true);
expect(initial.is_vertex()).toBe(false);
expect(initial.is_terminal()).toBe(false);
expect(initial.is_reference()).toBe(false);
expect(initial.type).toBe(RayType.INITIAL);
});
test(".vertex.terminal.#", () => {
/** [--|--] */ const vertex = Ray.vertex();
/** [ |--] */ const terminal = vertex.terminal.as_reference();
Expand All @@ -100,6 +104,26 @@ describe("Ray", () => {
expect(terminal.is_reference()).toBe(false);
expect(terminal.type).toBe(RayType.TERMINAL);
});
test(".terminal.#", () => {
/** [--| ] */ const terminal = Ray.terminal().as_reference();

expect(terminal.self.terminal.is_none()).toBe(true);
expect(terminal.self).not.toBe(terminal.self.self); // If self-referential, that means none.

expect(terminal.self.initial.terminal).toBe(terminal.self);

expect(terminal.self.is_none()).toBe(false);
expect(terminal.self.self.is_none()).toBe(true);

expect(terminal.is_some()).toBe(true);
expect(terminal.self.initial.is_none()).toBe(false);

expect(terminal.is_terminal()).toBe(true);
expect(terminal.is_vertex()).toBe(false);
expect(terminal.is_initial()).toBe(false);
expect(terminal.is_reference()).toBe(false);
expect(terminal.type).toBe(RayType.TERMINAL);
});
test(".None", () => {
/** [ ] */
const ray = Ray.None();
Expand Down
48 changes: 30 additions & 18 deletions src/@orbitmines/explorer/Ray.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import _, {initial} from "lodash";
import _ from "lodash";
import {NotImplementedError, PreventsImplementationBug} from "./errors/errors";
import {InterfaceOptions} from "./OrbitMinesExplorer";
import {value} from "../../lib/typescript/React";
import {current} from "../../profiles/FadiShawki/FadiShawki2";
import {debug} from "node:util";


// SHOULDNT CLASSIFY THESE?
Expand All @@ -20,6 +16,20 @@ export type Arbitrary<T> = (...args: any[]) => T;
export type Constructor<T> = new (...args: any[]) => T;
export type ParameterlessConstructor<T> = new () => T;

export function initial() {

return function (target: any, propertyKey: string): any {
Object.defineProperty(target, propertyKey, {
get: (): any => { return target.initial; },
set: (value) => {
target.initial = value;
},
// enumerable: true,
// configurable: true
});
}
}

/**
* https://en.wikipedia.org/wiki/Homoiconicity
*/
Expand All @@ -31,6 +41,7 @@ export interface PossiblyHomoiconic<T extends PossiblyHomoiconic<T>> {

export interface AbstractDirectionality<T> { initial: Arbitrary<T>, vertex: Arbitrary<T>, terminal: Arbitrary<T> }

// TODO: better debug
export type DebugResult = { [label: string]: DebugRay }
export type DebugRay = {
label: string,
Expand Down Expand Up @@ -63,6 +74,12 @@ export type DebugRay = {
* TODO: Can do some workaround overloading through properties, at least for +/-
*
* TODO: Singlke keybind for now to show/hide the ray disambiguation or 'dead edges/..'/
*
*
* TODO: Automatically implement any function with paramters, as being callable from a ray of that size..
*
*
* TODO: Consistency of Arbitrary vs non-arbitrary.
*/
export class Ray // Other possibly names: AbstractDirectionality, ..., ??
implements
Expand All @@ -79,18 +96,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
protected _vertex: Arbitrary<Ray>; get vertex(): Ray { return this._vertex(); } set vertex(vertex: Arbitrary<Ray>) { this._vertex = vertex; }
protected _terminal: Arbitrary<Ray>; get terminal(): Ray { return this._terminal(); } set terminal(terminal: Arbitrary<Ray>) { this._terminal = terminal; }

get self(): Ray {
// if (!this.vertex.is_none())
// throw new PreventsImplementationBug('Preventing bugs, .self is used for the assumption of a reference..');
//
return this.vertex;
};
set self(self: Arbitrary<Ray>) {
// if (!this.is_reference())
// throw new PreventsImplementationBug('Preventing bugs, .self is used for the assumption of a reference..');
//
this.vertex = self;
}
get self(): Ray { return this.vertex; }; set self(self: Arbitrary<Ray>) { this.vertex = self; }

[index: number]: Ray;

Expand Down Expand Up @@ -147,6 +153,8 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??

/** [--?--] */ return vertex;
}
/** [ |-?] */ static initial = () => Ray.vertex().initial;
/** [?-| ] */ static terminal = () => Ray.vertex().terminal;

static size = (of: number, value: any = undefined): Ray => {
let current = Ray.vertex().as_reference(); // TODO; This sort of thing should be lazy
Expand Down Expand Up @@ -232,6 +240,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
// return Arbitrary.Fn(() => length(of, value).resolve().at_terminal(index));
// }
//
// step = this.at; ???
at = (steps: number | Ray | Arbitrary<Ray>): Ray => { throw new NotImplementedError(); }
//
// export const permutation = (permutation: number | undefined, of: number): Arbitrary<Ray<any>> => at(
Expand Down Expand Up @@ -327,7 +336,7 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
return this;
}

protected property = (property: string | symbol, _default?: any): any => this.any[property] ??= _default; // TODO: Can this be prettier??
protected property = (property: string | symbol, _default?: any): any => this.any[property] ??= (_default ?? Ray.None()); // TODO: Can this be prettier??

protected _proxy: any;
protected _dirty_store: { [key: string | symbol]: object } = {}
Expand Down Expand Up @@ -388,6 +397,9 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??
return this.any.label = `"${Ray._label++} (${this.any.debug?.toString() ?? '?'})})"`;
}

push_back = (ray: Ray) => { throw new NotImplementedError(); }
push_front = (ray: Ray) => { throw new NotImplementedError(); }

// length: number;
//
// concat(...items: ConcatArray<Ray>[]): Ray[];
Expand Down
13 changes: 10 additions & 3 deletions src/@orbitmines/external/chyp/Chyp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {Ray} from "../../explorer/Ray";
import {Chyp} from "./Chyp";

describe("Chyp", () => {
describe("Graph", () => {
test(".o", () => {
describe(".Graph", () => {
test(".set_inputs", () => {
const graph = new Chyp.Graph()
.set_inputs(Ray.vertex().o({ js: 'B' }).as_arbitrary())
.set_inputs(Ray.vertex().o({ js: 'A' }).as_arbitrary());

expect('a').toBe('c');
expect(graph.inputs.any.js).toBe('A');
expect(graph.initial.any.js).toBe('A');
expect(graph.inputs.any.js).toBe(graph.initial.any.js);
expect(graph.inputs).toBe(graph.initial);
})

});
Expand Down
29 changes: 29 additions & 0 deletions src/@orbitmines/external/chyp/Chyp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Arbitrary, initial, Ray, second} from "../../explorer/Ray";

/**
* An interface from Aleks Kissinger's [Chyp (Cospans of HYPergraphs)](https://github.com/akissinger/chyp) to (OrbitMines') Rays.
*
Expand All @@ -10,3 +12,30 @@
* Note that this is mainly here for reference to the existing Chyp codebase - for anyone who understands that structure, to quickly translate that knowledge into how Rays work. - Other than that functionality, everything here should be considered as deprecated. Or considered as a legacy translation, which will be accessibly through OrbitMines.
*/

export namespace Chyp {

export type VData = Vertex; class Vertex extends Ray {

}

export type EData = Edge; class Edge extends Ray {

}

export class Graph extends Ray {

/**
* These are all just slightly differently abstracted in TypeScript here to make them a little more native.
*/
// Graph.inputs = Ray.initial
get inputs(): Ray { return this.initial; } set inputs(ray: Arbitrary<Ray>) { this.initial = ray; }
set_inputs = (ray: Arbitrary<Ray>): Graph => { this.inputs = ray; return this; }
add_inputs = (ray: Ray): Graph => { this.inputs.continues_with(ray); return this; }
// Graph.inputs = Ray.terminal
get outputs(): Ray { return this.terminal; } set outputs(ray: Arbitrary<Ray>) { this.terminal = ray; }
set_outputs = (ray: Arbitrary<Ray>): Graph => { this.outputs = ray; return this; }
add_outputs = (ray: Ray): Graph => { this.outputs.continues_with(ray); return this; }

}

}
48 changes: 10 additions & 38 deletions src/@orbitmines/external/chyp/Chyp_naive_pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import {JS, Ray} from "../../explorer/Ray";
import {NotImplementedError} from "../../explorer/errors/errors";

/**
* An interface from Aleks Kissinger's Chyp (Cospans of HYPergraphs) to Rays.
* GitHub: https://github.com/akissinger/chyp
*
* A simple way of phrasing this conversion, is that the concept of a 'Vertex', 'Edge', 'Graph', 'Rule', ..., 'Rewrite' are merged into one thing: a Ray.
*
* NOTE:
* This is just here for reference to the existing Chyp codebase - for anyone who understands that structure, to quickly translate that knowledge into how Rays work. - Other than that functionality, everything here should be considered as deprecated.
*
* - The .copy()'s are implemented on Ray.
*
* TODO: There's a lot of duplicate code, unnecessary documentation and non-generality in Chyp. It was probably developed as a proof of concept? - Expecting that to be addressed in the projects Aleks Kissinger is currently setting up.
Expand Down Expand Up @@ -368,43 +360,23 @@ export class Graph extends Ray {

// TODO: Can these be overlaoded in properties using -=, += in TS?

/**
* Append `inp` to the inputs of the graph.
*
* @param inp The list of vertex integer identifiers of the appended inputs.
*/
add_inputs = (inp = list(int)): Ray => {
this.inputs.continues_with(inp); // TODO: Perhaps splat
}
/**
* Append `outp` to the outputs of the graph.
*
* @param outp The list of vertex integer identifiers of the appended outputs.
*/
add_outputs = (outp = list(int)): Ray => {
this.outputs.continues_with(outp); // TODO: Perhaps splat
}
// TODO; these are then again duplicated to self.vdata[v].out_indices.add(i)



// TODO: These are just one possibly ignorant ray through the initial/terminal ends which aren't matched - could just generate these on the fly, or similar to chyp add when added.

// Return the list of vertex ids of the graph inputs.
get inputs(): Ray { throw new NotImplementedError(); }
// Return the list of vertex ids of the graph outputs.
get outputs(): Ray { throw new NotImplementedError(); }


// set function:
// TODO: Clears the matched in/out indices, then sets them to the ones found in in/outputs
set inputs(ray = list(int)) { throw new NotImplementedError(); }
set outputs(ray = list(int)) { throw new NotImplementedError(); }
// inputs =, outputs =
// for the add functions: // TODO: Perhaps splat
// also for add // TODO; these are then again duplicated to self.vdata[v].out_indices.add(i)


// TODO: Move these to a "reference-like" structure, need to be on VData..

/**
* These are all just slightly differently abstracted in TypeScript here to make them a little more native.
*/
set_inputs = (inp = list(int)): Ray => this.inputs = inp;
set_outputs = (outp = list(int)): Ray => this.outputs = outp;

// TODO: Move these to a "reference-like" structure, need to be on VData..

/**
* All these are just delegations from some Vertex/Edge structure.
Expand Down Expand Up @@ -975,7 +947,7 @@ export class Chyp extends Ray {
*
* return gen('_redistributer', domain, codomain)
*/

}

/**
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"isolatedModules": true,
"suppressImplicitAnyIndexErrors": false,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": [
"src"
Expand Down

0 comments on commit d6ee5ba

Please sign in to comment.