Giter VIP home page Giter VIP logo

laurelang's People

Contributors

timoniq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

laurelang's Issues

Feature: integer ranges enhanced

Proposed syntax to parse included/secluded boundaries of integer domains with complicated expressions including: variables, predicate calls, other domains.

int[] arr = [1, 2, 3];
int range = 0..(length of arr)>;

Revision

inner predicate call can be applied via additional logic variable or common predicate usage (.. and between).

Feature: generic improvements

Bound type to argument

x = map([[[1,2], [3]], [[4, 5, 6], [7, 8]]], flatten{int[]})

flatten{int} will bound int to predicate generic T.

Typevar explicit declaration

predicate{T=int, P=string}()

Also such operations should be supported:

flatten_int ~ flatten{int}.

Checklist

  • Bound type to argument
  • Typevar explicit declaration

Feature: predefined structure relations

: ? married(person, person).
? married(p1_uid, p2_uid) {
    db:Marriage(partner_id=p1_uid, partner2_id=p2_uid);
}%
? married(p1_uid, p2_uid) { married(p2_uid, p1_uid); }

$ InMarriage {
    person(name, _) person_1;
    person person_2;
} where {
    married(person_1, person_2);
    not({
        divorced(person_1, person_2)
        | dead(person_1)
        | dead(person_2);
    });
}

? InMarriage:repr(in_marriage) -> format("{in_marriage:name} is happily married with {partners_name}") {
    person(partners_name, _) = in_marriage:person_2;
}

Feature: smart context query reorderer

Consider a predicate flatten non trivial:

: ?flatten_nt(int[][]) -> int[].
?flatten_nt([]) -> [].
?flatten_nt([x]) -> x.
?flatten_nt(array) -> flattened {
    flattened = append<int>(x, y);
    y = flatten_nt(t);
    linked(x, t) = array;
}

Predicate will fail if we try to instantiate array from flattened:

?- flatten_nt(x) = [1,2,3]
* too broad error *

to change this behaviour queries should be reordered

?flatten_nt(array) -> flattened {
    linked(x, t) = array;
    y = flatten_nt(t);
    flattened = append<int>(x, y);
}

the idea is to do that automatically

qcontext may have order field (a vector with order calculated on scope entering)

[2, 1, 0]

Bug: type-constraint not applied

Expected and real behaviour:

query as_boolean(prime, x) = @false must produce only natural solutions for x due to prime signature ?prime(natural).

but it also produces integer results.

How to reproduce:

as_boolean(prime, x) = @false
-- to fix 'x' can be predefined
x ~ natural, as_boolean(prime, x) = @false

System info

laurelang: dev

OS: unix

Feature: nested relation refs

Let's consider an example:

predicate1(predicate2(A))

Predicate predicate2 must have response argument for relation above to be valid.

Proposed syntax is to mark argument different from response one taking part in relation as $.

Considering predicate signature : ?predicate3(int, int). We can build a relation:

predicate1(predicate3($, 42))

Feature: isolated sets

Using this example:

?- {jealous(x, y) -> jealous(y, x)}, jealous(var1, var2)
  var1 = "vincent",
  var2 = "marcellus";
  var1 = "marcellus",
  var2 = "vincent";
  var1 = "vincent",
  var2 = "marcellus";
  var1 = "marcellus",
  var2 = "vincent";

Two solutions are excess. They are created due to excess choicepoint creation in set.

Possible solutions

Cancel choicepoints with no data carried

Variables in choicepoint (x and y) have no references in future reasoning so choicepoint is redundant.

I don't like this solution because sometimes choicepoints are created to emulate a loop and this solution constrains this.

Use isolated sets

Proposed syntax:

&{jealous(x, y) -> jealous(y, x)}

Set will use its own context with no variables tracked. The terminal statement of the evaluation will be the terminal statement of the set. After that the control will be yielded back to the previous context.

Feature: matrix and union

Matrix

: ?transpose('T'[x][y]) -> 'T'[y][x].

To make size variables invisible in predicate case's scope their names should start with underscore, such as _x.

Implementation. After such cast matrix will gain matrix-confirmation.

Union

Builtin union template โ€“ external datatype sets union operator.

union<'T', ...>
optional<'T'>

s = 1 .. 3;
optional<s> a;

Declaration of a optional<'T'> template

none_T ~ @{none}.
optional<'T'> = union<'T', none_T>

Solutions: @none, 1, 2, 3.

: ?transpose_array('T'[][]) -> optional<'T'>[][].

todo

  • matrix
  • union

Feature: case of cut

To implement non-monotonous predicates, cutting endpoint could be implemented.

Proposed syntax

: ?predicate(int) -> int.
?predicate(42) -> 1%
?predicate(x) -> 2 when even(x).

case with 42 -> 1 is a case of cut. Other cases won't be checked if it succeeds.

Weight of cut

In weighted search case of cut should be avoidable with loss, its weight should be calculated separately, see #14

Feature: methods

Method can be implemented for any kind of datatype.

: ?increment(int) -> int.
?increment(i) -> i + 1.

First argument is automatically assigned to the current instance.

int boo = 2;
message( repr of boo:increment() );
// 3

Methods of atomic instances are freely accessible from nested instances.

int[] shelf = [1, 2, 3, 4..5];
message( repr of shelf:increment() );
// [2, 3, 4, 5]
// [2, 3, 4, 6]

Feature: generic type scheme constraint shortcut

Currently type schemes can be implemented like this:

: #some_constraint('T') -> 'T'[].
#some_constraint(_) -> _.

(see @/abstract package)

The case for the constraint is to some extent looks redundant, so some shortcut maybe useful.

Proposed syntax

: ##some_constraint('T') -> 'T'[].

Feature: predicate determinators & Goal type

Predicate determinators

Sometimes predicate may have multiple meanings and an ability to set non-logical determinators when calling the predicate or constructing new bound predicate instance would be useful.

Goal

Queryset bound to logical names.

[ experimental proposed syntax: ]

!use <prime>.

-- `x` and `y` are meant to be bound names as predicate determinators
g ~ Goal{x, y};
g = {
    int p = 1..15; 
    prime(p);
    x sized_bagof p = y;
    x >= 2;
};
g?;
message(
    format("x = {g:x}, y = {g:y}")
);

inline version

Goal{x, y} {
    ...
}(a, b);

Feature: callable in declaration (auto ID) and for each

New notation for predicates:

: #lt(int) -> int.
#lt(x) -> y when y < x.

int[] a = [1,2,3,4,5].
a = lt(5)[].

num = 1 .. a[3];
num[][] list;
s = no_repeat[];

Predicate usage in declarations and automatic linked vars resolution.

: ?person(string name, natural age) -> ID.
!datalink([person], "...").

: ?reason_field(string).
?reason_field("reason1").
?reason_field("reason2").

: ?some_predicate(person, person).
?some_predicate(person p1, person(name, _) _).

$ ... {
    person(name, _) person1;
    person(_, _) person2; -- or `person person2`
    reason_field reason;
}

progress

  • auto ID
  • for each notation

Feature: formatting

Creating new logical variable as a substring of s using pattern:

string s = "hello, world!";
s = format("hello, {something}!")
&all something { something = "world" };

Creating formatting:

formatting p = "hello, {smt}!";
smt = "abc" | "def";
format(p) = s;
message(s);

In the predicate:

: ?pred(string) -> string.
?pred(s) -> format("wrapped {s}").

pred("hello") = "wrapped hello";
pred(x) = "wrapped abc";
x = "abc";
pred(x) = "wrapped" -> fail();

Feature: better error display + backtracing

New trace message example:

in recursive call:
    pred(a, b, c)
in Imaging:
    a ~ (?(int, unk))
in Predicate Primitive:
    (?(int, unk))
            ^ error: undefined( unk )

Progress:

  • error display
  • backtracing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.