Repository navigation
Expand file tree
/
Copy pathSimplifier.cs
More file actions
68 lines (61 loc) · 3.27 KB
/
Copy pathSimplifier.cs
File metadata and controls
68 lines (61 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Copyright (c) 2019-2022 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//
using System.Collections.Generic;
using HonkSharp.Laziness;
namespace AngouriMath
{
partial record Entity
{
// The flat list of a chain of one associative connective, cached on the node exactly as
// Sumf.LinearChildren and Mulf.LinearChildren are: a node is immutable, the list is a
// property of it, and a nested chain's list is built from the lists cached on its parts.
// https://github.com/asc-community/AngouriMath/issues/224
partial record Orf
{
/// <summary>The disjuncts of a chain of <c>or</c>, flattened.</summary>
internal static IReadOnlyList<Entity> LinearChildren(Entity expr)
=> expr is Orf chain ? chain.Linear : new[] { expr };
private IReadOnlyList<Entity> Linear => linear.GetValue(static @this => Sumf.Flatten(LinearChildren(@this.Left), LinearChildren(@this.Right)), this);
private LazyPropertyA<IReadOnlyList<Entity>> linear;
}
partial record Andf
{
/// <summary>The conjuncts of a chain of <c>and</c>, flattened.</summary>
internal static IReadOnlyList<Entity> LinearChildren(Entity expr)
=> expr is Andf chain ? chain.Linear : new[] { expr };
private IReadOnlyList<Entity> Linear => linear.GetValue(static @this => Sumf.Flatten(LinearChildren(@this.Left), LinearChildren(@this.Right)), this);
private LazyPropertyA<IReadOnlyList<Entity>> linear;
}
partial record Xorf
{
/// <summary>The operands of a chain of <c>xor</c>, flattened.</summary>
internal static IReadOnlyList<Entity> LinearChildren(Entity expr)
=> expr is Xorf chain ? chain.Linear : new[] { expr };
private IReadOnlyList<Entity> Linear => linear.GetValue(static @this => Sumf.Flatten(LinearChildren(@this.Left), LinearChildren(@this.Right)), this);
private LazyPropertyA<IReadOnlyList<Entity>> linear;
}
partial record Set
{
partial record Unionf
{
/// <summary>The sets of a chain of unions, flattened.</summary>
internal static IReadOnlyList<Entity> LinearChildren(Entity expr)
=> expr is Unionf chain ? chain.Linear : new[] { expr };
private IReadOnlyList<Entity> Linear => linear.GetValue(static @this => Sumf.Flatten(LinearChildren(@this.Left), LinearChildren(@this.Right)), this);
private LazyPropertyA<IReadOnlyList<Entity>> linear;
}
partial record Intersectionf
{
/// <summary>The sets of a chain of intersections, flattened.</summary>
internal static IReadOnlyList<Entity> LinearChildren(Entity expr)
=> expr is Intersectionf chain ? chain.Linear : new[] { expr };
private IReadOnlyList<Entity> Linear => linear.GetValue(static @this => Sumf.Flatten(LinearChildren(@this.Left), LinearChildren(@this.Right)), this);
private LazyPropertyA<IReadOnlyList<Entity>> linear;
}
}
}
}