Skip to content

Commit 0e737d1

Browse files
The complex conjugate and the principal argument are functions (#2181)
Chapter III of Modenov's Problems in Geometry writes every point as a complex number and every statement in z and its conjugate, and its angles are arguments. conjugate was refused by name, and conj and arg since #2136. conjugate(z), also conj(z), is Entity.Conjugatef. A number is conjugated, and the conjugate is an involution. It is a field automorphism, so it is carried through sums, differences, products, quotients and whole powers, which keeps it on the symbols, and an identity between conjugates is then decided as one between symbols. It is not carried through a root or a logarithm, whose cuts break the reflection: conj(sqrt(-1)) is -i, sqrt(conj(-1)) is i. What is known to be real is its own conjugate: a modulus, and a symbol declared real. The codomain setting is not read, since InnerSimplified is cached on the node and the setting is not. conj(f) = v is solved as f = conj(v), and the derivative is taken along the variable's real line, as the modulus's is: that of conj(f) is conj(f'). arg(z) is Entity.Argf, the principal argument in (-pi, pi], real, with no value at 0. A number's argument is exact: the axes are 0, pi and +-pi/2, and elsewhere arctan(b/a), turned by pi into the left half-plane and gathered with a table value of the arctangent, so arg(-1 - i) is -3/4 * pi. Numerically it is the phase. Both print by name, draw as \overline{z} and \arg(z), and export to SymPy's conjugate and arg. The MCP server's syntax document names them, the native smoke test evaluates both, and re and im are still read as products. arg(prime(x)) simplified to 0, because prime's codomain is the primes, where at x = -3 prime(x) has no value, which BoundCheck found. A codomain says what a node's values are and not where it has one; the argument is decided for numbers only. Part of #2145. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 00d857b commit 0e737d1

31 files changed

Lines changed: 692 additions & 127 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,23 @@ the expression's own domain as its condition ([#2142](https://github.com/asc-com
263263
| `"(1 - cos(a))/(1 + cos(a))/tan(a/2)^2".Simplify()` | `(1 - cos(a)) / ((cos(a) + 1) * tan(a / 2) ^ 2)` | `1 provided not cos(a) + 1 = 0 and not tan(a / 2) = 0 and not cos(a / 2) = 0` |
264264
| `"(cos(2*x) - 1)^2 + sin(2*x)^2 - 4*sin(x)^2".Simplify()` ([#2133](https://github.com/asc-community/AngouriMath/issues/2133)) | `2 + (-2) * cos(2 * x) + (-4) * sin(x) ^ 2` | `0` |
265265

266-
### `conj` and `arg` are refused by name
266+
### `conjugate`, `conj` and `arg` are functions
267267

268-
**Not silent: these now throw `UnrecognizedFunctionParseException` where they parsed.** A name the parser does not
269-
know, followed by a bracket, is read as a product, so `arg(z)` was the variable `arg` times `z`, and `arg(z) = 1`
270-
solved to `{ 1 / arg }`. `conjugate` was already refused by name; `conj` and `arg` are the conjugate and the argument
271-
as other systems spell them. `re` and `im` are still read as products, as before: two letters is short enough to be a
272-
variable's name ([#2136](https://github.com/asc-community/AngouriMath/issues/2136)).
268+
**Not silent: these names followed by a bracket are now the complex conjugate and the principal argument, where they
269+
were read as products or refused.** A name the parser does not know, followed by a bracket, is read as a product, so
270+
`arg(z)` was the variable `arg` times `z`, and `arg(z) = 1` solved to `{ 1 / arg }`. `conjugate(z)` and `conj(z)` are
271+
`Entity.Conjugatef`, carried through sums, differences, products, quotients and whole powers and not through a root or
272+
a logarithm; `arg(z)` is `Entity.Argf`, in `(-pi, pi]`, with no value at `0`
273+
([#2136](https://github.com/asc-community/AngouriMath/issues/2136),
274+
[#2145](https://github.com/asc-community/AngouriMath/issues/2145)). `re` and `im` are still read as products.
273275

274276
| Input | Was (2.6.0) | Now |
275277
|---|---|---|
276-
| `"arg(z)".ToEntity()` | `arg * z` | throws `UnrecognizedFunctionParseException` |
277-
| `"conj(z)".ToEntity()` | `conj * z` | throws `UnrecognizedFunctionParseException` |
278-
278+
| `"conjugate(z)".ToEntity()` | throws `UnrecognizedFunctionParseException` | `conjugate(z)` |
279+
| `"conj(z)".ToEntity()` | `conj * z` | `conjugate(z)` |
280+
| `"conj(3 + 4i)".ToEntity().Simplify()` | `(3 + 4i) * conj` | `3 - 4i` |
281+
| `"arg(z)".ToEntity()` | `arg * z` | `arg(z)` |
282+
| `"arg(-1)".ToEntity().Simplify()` | `-arg` | `pi` |
279283
### Over the reals, a modulus of a polynomial is split at the polynomial's real roots
280284

281285
**Silent: an answer with entries that solve nothing is exact.** With the real codomain an equation in moduli was

‎Sources/.editorconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
237237
[Tests/UnitTests/Convenience/BinomialTest.cs]
238238
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
239239

240+
[Tests/UnitTests/Convenience/ConjugateAndArgumentTest.cs]
241+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
242+
240243
[Tests/UnitTests/Convenience/IversonTest.cs]
241244
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
242245

@@ -398,6 +401,8 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
398401

399402
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.Iverson.Classes.cs]
400403
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
404+
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.ComplexParts.Classes.cs]
405+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
401406
[AngouriMath/Core/Entity/Continuous/Entity.Continuous.Aleph.Classes.cs]
402407
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
403408

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,54 @@ public static Entity VectorLength(Matrix v)
13941394
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13951395
public static Entity Iverson(Entity statement) => new Iversonf(statement);
13961396

1397+
/// <summary>The complex conjugate <c>conjugate(z)</c>: <c>a - b i</c> for <c>z = a + b i</c></summary>
1398+
/// <param name="z">The argument, any complex number</param>
1399+
/// <returns>The <see cref="Entity.Conjugatef"/> node</returns>
1400+
/// <remarks>
1401+
/// It is carried through sums, products, quotients and whole powers, and fixes what is known to
1402+
/// be real: a number, and a node whose codomain is real, such as a modulus or <c>domain(x, RR)</c>.
1403+
/// https://github.com/asc-community/AngouriMath/issues/2145
1404+
/// </remarks>
1405+
/// <example>
1406+
/// <code>
1407+
/// using System;
1408+
/// using static AngouriMath.MathS;
1409+
///
1410+
/// Console.WriteLine(Conjugate("3 + 4i").Simplify());
1411+
/// Console.WriteLine(Conjugate("a * b + i").Simplify());
1412+
/// </code>
1413+
/// Prints
1414+
/// <code>
1415+
/// 3 - 4i
1416+
/// -i + conjugate(a) * conjugate(b)
1417+
/// </code>
1418+
/// </example>
1419+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1420+
public static Entity Conjugate(Entity z) => new Conjugatef(z);
1421+
1422+
/// <summary>The principal argument <c>arg(z)</c>, in <c>(-pi, pi]</c>, so that <c>z = |z| e^(i arg(z))</c></summary>
1423+
/// <param name="z">The argument, any complex number but 0, where it has no value</param>
1424+
/// <returns>The <see cref="Entity.Argf"/> node</returns>
1425+
/// <remarks>https://github.com/asc-community/AngouriMath/issues/2145</remarks>
1426+
/// <example>
1427+
/// <code>
1428+
/// using System;
1429+
/// using static AngouriMath.MathS;
1430+
///
1431+
/// Console.WriteLine(Arg("-1").Simplify());
1432+
/// Console.WriteLine(Arg("1 + i").Simplify());
1433+
/// Console.WriteLine(Arg("-1 - i").Simplify());
1434+
/// </code>
1435+
/// Prints
1436+
/// <code>
1437+
/// pi
1438+
/// pi / 4
1439+
/// -3/4 * pi
1440+
/// </code>
1441+
/// </example>
1442+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1443+
public static Entity Arg(Entity z) => new Argf(z);
1444+
13971445
/// <summary>The aleph number <c>aleph(k)</c>, the size of an infinite set</summary>
13981446
/// <param name="index">The index, a whole number from zero</param>
13991447
/// <returns>The <see cref="Entity.Alephf"/> node</returns>

‎Sources/AngouriMath/Core/Antlr/AngouriMath.g‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,19 +635,19 @@ atom returns[Entity value]
635635
| 'dot(' args = function_arguments ')' { Assert("dot", 2, $args.list.Count); $value = ParsingHelpers.Dot($args.list[0], $args.list[1]); }
636636
| 'cross(' args = function_arguments ')' { Assert("cross", (1, 2), $args.list.Count); $value = ParsingHelpers.Cross($args.list); }
637637
| 'resultant(' args = function_arguments ')' { Assert("resultant", 3, $args.list.Count); $value = ParsingHelpers.Resultant($args.list[0], $args.list[1], $args.list[2]); }
638+
/* The complex conjugate, by its name and by the shorter one other systems use.
639+
https://github.com/asc-community/AngouriMath/issues/2145 */
640+
| 'conjugate(' args = function_arguments ')' { Assert("conjugate", 1, $args.list.Count); $value = MathS.Conjugate($args.list[0]); }
641+
| 'conj(' args = function_arguments ')' { Assert("conj", 1, $args.list.Count); $value = MathS.Conjugate($args.list[0]); }
642+
/* The principal argument, in (-pi, pi]. https://github.com/asc-community/AngouriMath/issues/2145 */
643+
| 'arg(' args = function_arguments ')' { Assert("arg", 1, $args.list.Count); $value = MathS.Arg($args.list[0]); }
638644

639645
/* Names the library does not have. Each is a function every other CAS spells this way, so
640646
a caller reaches for it, and without these rules each is silently read as a product --
641647
see NotImplementedFunction above. Refusing is not the feature; it is the difference
642648
between a missing function and a wrong answer. */
643649

644650
| 'trunc(' args = function_arguments ')' { $value = NotImplementedFunction("trunc", "rounding functions"); }
645-
| 'conjugate(' args = function_arguments ')' { $value = NotImplementedFunction("conjugate", "complex conjugate as a symbolic function"); }
646-
/* conj and arg are the conjugate and the argument as other systems spell them. Each was read
647-
as a product: arg(z) was arg * z. re and im are left as products, as
648-
MissingFunctionNamesRefusedTest records. https://github.com/asc-community/AngouriMath/issues/2136 */
649-
| 'conj(' args = function_arguments ')' { $value = NotImplementedFunction("conj", "complex conjugate as a symbolic function"); }
650-
| 'arg(' args = function_arguments ')' { $value = NotImplementedFunction("arg", "complex argument as a symbolic function"); }
651651
| 'domain(' args = function_arguments ')'
652652
{
653653
Assert("domain", 2, $args.list.Count);

‎Sources/AngouriMath/Core/Antlr/AngouriMath.interp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ null
184184
'dot('
185185
'cross('
186186
'resultant('
187-
'trunc('
188187
'conjugate('
189188
'conj('
190189
'arg('
190+
'trunc('
191191
'domain('
192192
'piecewise('
193193
'apply('

‎Sources/AngouriMath/Core/Antlr/AngouriMath.tokens‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ WS=200
382382
'dot('=182
383383
'cross('=183
384384
'resultant('=184
385-
'trunc('=185
386-
'conjugate('=186
387-
'conj('=187
388-
'arg('=188
385+
'conjugate('=185
386+
'conj('=186
387+
'arg('=187
388+
'trunc('=188
389389
'domain('=189
390390
'piecewise('=190
391391
'apply('=191

0 commit comments

Comments
 (0)