Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to operations with collections and indexables #614

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal sealed class KeyStack<TKey, TValue>
{
private readonly List<(TKey key, TValue value)> list = new();

internal TValue Peek() => list[list.Count - 1].value;
internal TValue Peek() => list[^1].value;

internal bool Remove(TKey key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static bool Next(in Span<bool> states)
/// <exception cref="WrongNumberOfArgumentsException"/>
internal static Matrix? SolveTable(Entity expr, Variable[] variables)
{
var count = expr.Vars.Count();
var count = expr.Vars.Count;
// TODO: we probably also should verify the uniqueness of the given variables
if (count != variables.Length)
throw new WrongNumberOfArgumentsException("Number of variables must equal number of variables in the expression");
Expand All @@ -67,7 +67,7 @@ internal static bool Next(in Span<bool> states)

internal static Matrix? BuildTruthTable(Entity expr, Variable[] variables)
{
var count = expr.Vars.Count();
var count = expr.Vars.Count;
// TODO: we probably also should verify the uniqueness of the given variables
if (count != variables.Length)
throw new WrongNumberOfArgumentsException("Number of variables must equal number of variables in the expression");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ private Expression HandlePiecewise(IEnumerable<Expression> en)
}

// last case
var expression = children[children.Length - 2];
var predicate = children[children.Length - 1];
var expression = children[^2];
var predicate = children[^1];
var nan = ConvertNaN(maxType);

(expression, nan) = EqualizeTypesIfAble(expression, nan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static Set Solve(Entity equation, Variable x)

static Entity simplifier(Entity entity) => entity.InnerSimplified;
static Entity evaluator(Entity entity) => entity.Evaled;
var factorizer = equation.Vars.Count() == 1 ? (Func<Entity, Entity>)evaluator : simplifier;
var factorizer = equation.Vars.Count == 1 ? (Func<Entity, Entity>)evaluator : simplifier;


if (solutions is FiniteSet finiteSet)
Expand Down Expand Up @@ -75,7 +75,7 @@ internal static Set Solve(Entity equation, Variable x)
/// </param>
internal static List<List<Entity>> InSolveSystem(List<Entity> equations, ReadOnlySpan<Variable> vars)
{
var var = vars[vars.Length - 1];
var var = vars[^1];
if (equations.Count == 1)
return equations[0].InnerSimplified.SolveEquation(var) is FiniteSet els
? els.Select(sol => new List<Entity> { sol }).ToList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static Entity TryDowncast(Entity equation, Variable x, Entity root)
// https://mathoverflow.net/a/28977

// if nothing has been found so far
if (MathS.Settings.AllowNewton && expr.Vars.Count() == 1)
if (MathS.Settings.AllowNewton && expr.Vars.Count == 1)
return expr.SolveNt(x).Select(ent => TryDowncast(expr, x, ent)).ToSet();

return Enumerable.Empty<Entity>().ToSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ static bool IsPrimeI(Integer num)

static void AddPrimeC()
{
var n = (primes[primes.Count - 1].cache + 2) ?? throw new AngouriBugException("It was supposed to be not null");
var n = (primes[^1].cache + 2) ?? throw new AngouriBugException("It was supposed to be not null");
while (!IsPrimeC(n))
n += 2;
primes.Add((n, n));
}

static void AddPrimeI()
{
var n = (primes[primes.Count - 1].actual + 2) ?? throw new AngouriBugException("It was supposed to be not null");
var n = (primes[^1].actual + 2) ?? throw new AngouriBugException("It was supposed to be not null");
while (!IsPrimeI(n))
n += 2;
primes.Add((n, null));
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/UnitTests/Convenience/FromStringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void TestInequalityCompositionPrettySyntax(
public void TestUnicodeVariablesParser(string exprRaw, string expectedName)
{
Entity actual = exprRaw;
var any = actual.Vars.First();
var any = actual.Vars[0];
Assert.Equal(expectedName, any.Name);
}

Expand Down
Loading