Skip to content

Commit

Permalink
2024-03-12 Proposition
Browse files Browse the repository at this point in the history
  • Loading branch information
nomagicisreal committed Mar 12, 2024
1 parent 50e2d16 commit 91b6bdf
Show file tree
Hide file tree
Showing 16 changed files with 932 additions and 338 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## 0.0.1 ~ 0.0.13
## 0.0.1 ~ 0.0.14
- Initial version.
20 changes: 17 additions & 3 deletions bin/cmd.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@

import 'package:damath/src/math/api.dart';

void main(List<String> arguments) {
final Iterable<int> list = <int>[2, 5, 2];
print(list.anyIsEqual);
}
const d1 = 'the computer is complex';
const d2 = 'the computer is easy';

final pT = Proposition(d1, true);
final pF = Proposition(d1, false);
final qT = Proposition(d2, true);
final qF = Proposition(d2, false);

print(((pT | -qT) > (pT & qT)).value);
print(((pT | -qF) > (pT & qF)).value);
print(((pF | -qT) > (pF & qT)).value);
print(((pF | -qF) > (pF & qF)).value);

// final result = (pF | -qF) > (pF & qF);
// print(result);
}
2 changes: 1 addition & 1 deletion lib/src/async/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension FTimer on Timer {
}

static Timer sequencing(List<Duration> steps, List<Listener> listeners) =>
_sequence(steps.forEachCombine(listeners));
_sequence(steps.intersectionIterateCombine(listeners));
}

extension FTimerConsumer on Consumer<Timer> {
Expand Down
15 changes: 8 additions & 7 deletions lib/src/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
typedef Listener = void Function();
typedef Supplier<T> = T Function();
typedef Consumer<T> = void Function(T value);
typedef Intersector<T> = void Function(T v1, T v2);
typedef Absorber<A, B> = void Function(A a, B b);
typedef Intersector<A, B> = void Function(A a, B b);
typedef Mapper<T> = T Function(T value);
typedef Reducer<T> = T Function(T v1, T v2);
typedef Reducer<T> = T Function(T current, T value);
typedef Reducer2<T> = T Function(T current, T v1, T v2);
typedef Companion<T, S> = T Function(T origin, S another);
typedef Companion2<T, S> = T Function(T origin, S v1, S v2);
typedef Companion2<T, A, B> = T Function(T origin, A a, B b);
typedef Translator<T, S> = S Function(T value);
typedef Combiner<T, S> = S Function(T v1, T v2);
typedef Mixer<P, Q, S> = S Function(P p, Q q);
Expand All @@ -58,7 +58,7 @@ typedef Checker<T> = bool Function(int index, T value);
///
/// indexable
///
typedef IntersectorIndexable<T> = void Function(T v1, T v2, int index);
typedef IntersectorIndexable<A, B> = void Function(A a, B b, int index);
typedef ConsumerIndexable<T> = void Function(T value, int index);

///
Expand All @@ -67,9 +67,10 @@ typedef ConsumerIndexable<T> = void Function(T value, int index);
typedef Generator<T> = T Function(int index);
typedef Generator2D<T> = T Function(int i, int j);
typedef CompanionGenerator<T, S> = T Function(T value, S element, int index);
typedef Companion2Generator<T, S> = T Function(T value, S e1, S e2, int index);
typedef Companion2Generator<T, A, B> = T Function(T value, A a, B b, int index);
typedef TranslatorGenerator<T, S> = S Function(T value, int index);
typedef ReducerGenerator<T> = T Function(T v1, T v2, int index);
typedef ReducerGenerator<T> = T Function(T current, T value, int index);
typedef Reducer2Generator<T> = T Function(T current, T v1, T v2, int index);

///
/// differentiator
Expand Down
2 changes: 1 addition & 1 deletion lib/src/flutter/function/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extension FSizingPath on SizingPath {
? FMapper.keep
: (corners) => corners.map((cubics) => cubics * scale);

Path from(Iterable<CubicOffset> offsets) => scaled(offsets).foldWithIndex(
Path from(Iterable<CubicOffset> offsets) => scaled(offsets).foldByIndex(
Path(),
(path, points, index) => path
..moveOrLineToPoint(points.a, index == 0)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/math/api.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
library damath_math;

import 'dart:math' as math;
import 'package:damath/damath.dart';

import '../core.dart';
export '../core.dart';

part 'definition/_additions.dart';
part 'definition/space.dart';
part 'definition/graph.dart';
part 'definition/proposition.dart';
part 'definition/space.dart';
part 'definition/tensor.dart';
part 'extension/_additions.dart';
part 'extension/iterable.dart';
Expand Down
38 changes: 3 additions & 35 deletions lib/src/math/definition/_additions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/// [Operator]
///
///
/// [Combination]
///
///
/// [DurationFR]
///
Expand All @@ -22,8 +20,8 @@
///
///
///
///
///
///
///
///
///
///
Expand All @@ -43,15 +41,14 @@ part of damath_math;
//
mixin ComparableData<C extends Comparable, D extends ComparableData<C, D>>
implements Comparable<D> {
implements Comparable<D> {
bool operator >(D other) => Comparable.compare(this, other) == 1;

bool operator <(D other) => Comparable.compare(this, other) == -1;

static int compareReverse<C extends Comparable>(C a, C b) => b.compareTo(a);
}


///
///
///
Expand Down Expand Up @@ -330,35 +327,6 @@ enum Operator {
};
}

///
///
///
/// [Combination]
///
///
///
//
class Combination {
final int m;
final int n;

const Combination(this.m, this.n) : assert(m >= 0 && n <= m);

int get c => IntExtension.binomialCoefficient(m, n + 1);

int get p => IntExtension.partition(m, n);

List<List<int>> get pGroups =>
IntExtension.partitionGroups(m, n)..sortAccordingly();

@override
String toString() => 'Combination(\n'
'($m, $n), c: $c\n'
'p: $p------${pGroups.fold('', (a, b) => '$a \n $b')}\n'
')';
}

///
///
///
Expand Down
71 changes: 61 additions & 10 deletions lib/src/math/definition/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
///
///
/// [GraphAncestor]
/// [Graph]
/// [GraphVertex]
/// [GraphEdge]
///
/// [GraphMutable]
///
///
Expand Down Expand Up @@ -485,6 +487,8 @@ sealed class EdgeAncestor<T, S, V extends VertexAncestor<T?>> {

EdgeAncestor(this._source, this._destination, this.weight);

String toStringIdentity();

///
/// [contains]
/// [containsBoth]
Expand Down Expand Up @@ -523,8 +527,10 @@ class EdgeNullable<T> extends EdgeAncestor<T, double?, VertexNullable<T>> {
set destination(T? value) => super._destination.data = value;

@override
String toString() =>
'EdgeNullable($weight:${_source.data}===${_destination.data})';
String toStringIdentity() => '$weight:${_source.data}===${_destination.data}';

@override
String toString() => 'EdgeNullable(${toStringIdentity()})';

///
/// [translateToSource], [translateToDestination]
Expand All @@ -546,7 +552,7 @@ class EdgeNullable<T> extends EdgeAncestor<T, double?, VertexNullable<T>> {
class Edge<T> extends EdgeAncestor<T, double, Vertex<T>> {
// Edge._(super.source, super.destination, super.weight);

Edge(T source, T destination, [double weight = 1])
Edge(T source, T destination, [double weight = double.infinity])
: super(Vertex(source), Vertex(destination), weight);

T get source => _source.data;
Expand All @@ -558,7 +564,10 @@ class Edge<T> extends EdgeAncestor<T, double, Vertex<T>> {
set destination(T value) => super._destination.data = value;

@override
String toString() => 'Edge($weight:${_source.data}===${_destination.data})';
String toStringIdentity() => '$weight:${_source.data}===${_destination.data}';

@override
String toString() => 'Edge(${toStringIdentity()})';

///
/// [translateToSource], [translateToDestination]
Expand Down Expand Up @@ -656,6 +665,13 @@ abstract class GraphAncestor<T, S, V extends VertexAncestor<T?>,

Iterable<E> get edges;

String toStringIdentity() => '\n'
'Vertices: ${vertices.map((e) => e.data)}\n'
'Edges: ${edges.map((e) => e.toStringIdentity())}\n';

@override
String toString() => 'GraphAncestor(${toStringIdentity()})';

///
/// [vertexGroupsFromEdges]
/// [destinationsGroupBySources]
Expand Down Expand Up @@ -686,13 +702,25 @@ abstract class GraphAncestor<T, S, V extends VertexAncestor<T?>,
);

///
/// [containsVertex], [containsEdge]
/// [containsVertex], [containsVerticesOnEdge], [containsAllVertices]
/// [containsEdge], [containsAllEdges], [containsEdgeForBoth]
/// [weightFrom]
///
bool containsVertex(V vertex) => vertices.contains(vertex);

bool containsVerticesOnEdge(E edge) =>
containsVertex(edge._source) && containsVertex(edge._destination);

bool containsAllVertices(Iterable<V> vertices) =>
this.vertices.containsAll(vertices);

bool containsEdge(E edge) => edges.contains(edge);

bool containsEdgeForBoth(V source, V destination) =>
edges.any((edge) => edge.containsBoth(source, destination));

bool containsAllEdges(Iterable<E> edges) => this.edges.containsAll(edges);

S weightFrom(V source, V destination) => edges.firstWhereMap(
(edge) => edge.containsBoth(source, destination),
(edge) => edge.weight,
Expand Down Expand Up @@ -776,22 +804,45 @@ abstract class GraphAncestor<T, S, V extends VertexAncestor<T?>,
}

//
class Graph<T> extends GraphAncestor<T, double, Vertex<T>, Edge<T>> {
class GraphVertex<T> extends GraphAncestor<T, double, Vertex<T>, Edge<T>> {
@override
final Set<Vertex<T>> vertices;

@override
final Set<Edge<T>> edges = {};

GraphVertex(this.vertices);

///
/// Returns `true` if [edge] (or an equal value) was not yet in the [edges].
/// Otherwise returns `false` and the set is not changed. See also [Set.add]
///
bool addEdgeForVertices(Edge<T> edge) {
if (containsVerticesOnEdge(edge)) return edges.add(edge);
throw DamathException(
'Edge.source(${edge._source}) or '
'Edge.destination(${edge._destination}) not in $vertices',
);
}
}

//
class GraphEdge<T> extends GraphAncestor<T, double, Vertex<T>, Edge<T>> {
@override
final List<Edge<T>> edges;
final Set<Edge<T>> edges;

@override
Set<Vertex<T>> get vertices => edges.toVertices;

const Graph(this.edges);
GraphEdge(this.edges);
}

///
/// [createVertex], ...
/// [createEdge], ...
///
abstract class GraphMutable<T, S, V extends VertexAncestor<T>,
E extends EdgeAncestor<T, S, V>> extends GraphAncestor<T, S, V, E> {
E extends EdgeAncestor<T, S, V>> extends GraphAncestor<T, S, V, E> {
///
/// [createVertex], [addVertex]
/// [createEdge], [addEdge],
Expand Down
Loading

0 comments on commit 91b6bdf

Please sign in to comment.