Skip to content

Commit

Permalink
Improvements to operations with arrays/indexables (#614)
Browse files Browse the repository at this point in the history
Co-authored-by: Lehonti Ramos <lehonti@ramos>
  • Loading branch information
Lehonti and Lehonti Ramos authored Oct 3, 2023
1 parent 2284093 commit 89cb1ea
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
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

0 comments on commit 89cb1ea

Please sign in to comment.