Skip to content

Commit b575525

Browse files
Rafael-SOWNetclaude
andcommitted
Dimensional analysis in the catalogue: dimension and dimensionless_groups
AGENTS.md: an operation the library offers by name is an entry of the catalogue. The two queries answer what MathS.Dimensions.Of and DimensionlessGroups answer, which CatalogueTest checks on an input where the two dimension answers differ. No surface offers them yet: the MCP server's Tools.NotOffered and the terminal's OneShot.notOffered list them, pointing at #2298, which proposes am_dimensions. Part of #2292. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent db1568c commit b575525

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎Sources/AngouriMath/Core/Operations/Catalogue.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,23 @@ internal static class Catalogue
280280
"is_prime", "Whether an integer is prime.",
281281
static n => n.IsPrime);
282282

283+
// ---------------------------------------------------------------- queries on physical dimensions
284+
285+
[ConstantField]
286+
private static readonly Parameter TheDimensions = new("dimensions", "The physical dimension of each variable.");
287+
288+
/// <summary><see cref="MathS.Dimensions.Of(Entity, IReadOnlyDictionary{Variable, Dimension})"/>.</summary>
289+
public static Query<Func<Entity, IReadOnlyDictionary<Variable, Dimension>, DimensionCheck>> Dimension { get; } = new(
290+
"dimension", "The physical dimension of an expression from those of its variables, or the part where two dimensions disagree.",
291+
static (e, dimensions) => MathS.Dimensions.Of(e, dimensions),
292+
TheDimensions);
293+
294+
/// <summary><see cref="MathS.Dimensions.DimensionlessGroups(IReadOnlyList{Variable}, IReadOnlyDictionary{Variable, Dimension})"/>.</summary>
295+
public static Query<Func<IReadOnlyList<Variable>, IReadOnlyDictionary<Variable, Dimension>, IReadOnlyList<Entity>>> DimensionlessGroups { get; } = new(
296+
"dimensionless_groups", "The independent products of powers of variables that have no dimension: their Buckingham pi groups.",
297+
static (variables, dimensions) => MathS.Dimensions.DimensionlessGroups(variables, dimensions),
298+
TheDimensions);
299+
283300
// ---------------------------------------------------------------- the list
284301

285302
/// <summary>Every entry above, in the order written.</summary>
@@ -291,6 +308,7 @@ internal static class Catalogue
291308
ToBase, FromBase,
292309
Determinant, Inverse, Transpose, Rank, ReducedRowEchelonForm, Trace, TensorProduct,
293310
PrimeFactorization, Totient, GreatestCommonDivisor, DivisorCount, IsPrime,
311+
Dimension, DimensionlessGroups,
294312
];
295313

296314
/// <summary>The entry named <paramref name="name"/>, or <see langword="null"/> where there is none.</summary>

‎Sources/MCP/AngouriMath.Mcp/Tools.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ private static JsonObject Schema(JsonObject props, params string[] required)
129129
[Catalogue.Glsl.Name] = "waits for am_shader_source, https://github.com/asc-community/AngouriMath/issues/2298",
130130
[Catalogue.Normalize.Name] = "am_simplify offers the whole simplification, which starts with this pass",
131131
[Catalogue.Evaluate.Name] = "am_evaluate keeps an exact value exact, simplifying rather than evaluating, and adds a numeric value beside it",
132+
[Catalogue.Dimension.Name] = "waits for am_dimensions, https://github.com/asc-community/AngouriMath/issues/2298",
133+
[Catalogue.DimensionlessGroups.Name] = "waits for am_dimensions, https://github.com/asc-community/AngouriMath/issues/2298",
132134
};
133135

134136
/// <summary>The names of the catalogue's entries, which a test checks the lists above against.</summary>

‎Sources/Terminal/AngouriMath.Terminal.Lib/OneShot.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ let notOffered =
7171
"solve_system_with_parameters"; "solve_conjunction_with_parameters"
7272
"alternatives"; "sympy"; "hlsl"; "glsl"; "truth_table"; "satisfying_assignments"; "series"; "to_base"; "from_base"
7373
"determinant"; "inverse"; "transpose"; "rank"; "reduced_row_echelon_form"; "trace"; "tensor_product"
74-
"prime_factorization"; "totient"; "greatest_common_divisor"; "divisor_count"; "is_prime"; "are_equal" ]
74+
"prime_factorization"; "totient"; "greatest_common_divisor"; "divisor_count"; "is_prime"; "are_equal"
75+
"dimension"; "dimensionless_groups" ]
7576

7677
/// The arguments still to read, falling back to a line of stdin where one is missing or is <c>_</c>.
7778
type private Arguments(given: string list, input: TextReader) =

‎Sources/Tests/UnitTests/Core/Operations/CatalogueTest.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ public void EachEntryAnswersAsTheMethodItNames()
262262
Assert.Equal(MathS.NumberTheory.CountDivisors(twelve), Catalogue.DivisorCount.Ask(twelve));
263263
Assert.Equal(twelve.IsPrime, Catalogue.IsPrime.Ask(twelve));
264264
Assert.True(Catalogue.IsPrime.Ask(7));
265+
266+
Variable v = "v", t = "t";
267+
var dimensions = new Dictionary<Variable, Dimension> { [x] = Dimension.Length, [v] = Dimension.Length / Dimension.Time, [t] = Dimension.Time };
268+
Assert.Equal(MathS.Dimensions.Of("x + v t", dimensions), Catalogue.Dimension.Ask("x + v t", dimensions));
269+
Assert.Equal(MathS.Dimensions.Of("x + v", dimensions), Catalogue.Dimension.Ask("x + v", dimensions));
270+
Assert.NotEqual(Catalogue.Dimension.Ask("x + v t", dimensions), Catalogue.Dimension.Ask("x + v", dimensions));
271+
Assert.Equal(MathS.Dimensions.DimensionlessGroups([x, v, t], dimensions), Catalogue.DimensionlessGroups.Ask([x, v, t], dimensions));
265272
}
266273
}
267274
}

0 commit comments

Comments
 (0)