Skip to content

Commit 9ade6c9

Browse files
The power reduction of a squared cosine is proved, as the squared sine's is (#2177)
sin(x)^2 - (1 - cos(2x))/2 simplified to 0 and cos(x)^2 - (1 + cos(2x))/2 did not. Its candidates reach -1/2 + cos(x)^2 / 2 + sin(x)^2 / 2, which is 0, and stopped there: a rational coefficient is written as a divisor, so k sin(x)^2 + k cos(x)^2 = k (#2175) does not see cos(x)^2 / 2, and the two squares are not siblings for the switch's rules either. squared-sine-and-cosine-over-one-divisor-sum-to-its-reciprocal gathers sin(x)^2 / d and cos(x)^2 / d of one argument and one divisor and writes 1 / d: Sound, since both sides are defined exactly where d is not 0, two-sided, Collects, and with no backwards reading, as it forgets the angle. Two different divisors are left alone. The census moves by one in WritingARule.md, Saturation's remark and the tests that pin them. On 2.6.0 and on this branch, Simplify: cos(x)^2 - (1 + cos(2*x))/2 unchanged -> 0 Chain against master 856b3cb: verdicts identical, 0 moves; performance gate passed on all 19; unit suite 17,169 passed, 0 failed. RuleCheck passes, Confluence and CanonCheck match their baselines, SimpSweep 10,463/10,463. Part of #2142 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 856b3cb commit 9ade6c9

9 files changed

Lines changed: 105 additions & 22 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ is `null`. A row with symbols in it is tried at one value of them, and where it
231231
| `MathS.Equations("ln(x) + ln(y)", "x - y").Solve("x", "y")` | `[[-1, -1], [1, 1]]` | `[[1, 1]]`: `ln(-1) + ln(-1)` is `2 pi i` |
232232
| `MathS.Equations("sqrt(y) - x", "y - a").Solve("x", "y")` | `[[sqrt(a), (sqrt(a)) ^ 2], [-sqrt(a), (-sqrt(a)) ^ 2]]` | `null`: the second row is a solution only at `a = 0` |
233233

234+
### The power reduction of a squared cosine is proved, as the squared sine's is
235+
236+
**Silent: an identity reaches its value.** `cos(x)^2 = (1 + cos(2x))/2` was not proved while
237+
`sin(x)^2 = (1 - cos(2x))/2` was: the difference reached `-1/2 + cos(x)^2 / 2 + sin(x)^2 / 2`, where the squares
238+
carry their coefficient as a divisor, and no rule found a squared sine and cosine over one divisor among other terms.
239+
`sin(x)^2 / d + cos(x)^2 / d = 1 / d` is now found wherever the two sit in a sum
240+
([#2142](https://github.com/asc-community/AngouriMath/issues/2142)).
241+
242+
| Input | Was (2.6.0) | Now |
243+
|---|---|---|
244+
| `"cos(x)^2 - (1 + cos(2*x))/2".Simplify()` | `cos(x) ^ 2 - (1 + cos(2 * x)) / 2` | `0` |
245+
234246
### `conj`, `arg` and `det` are refused by name
235247

236248
**Not silent: these now throw `UnrecognizedFunctionParseException` where they parsed.** A name the parser does not

‎Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,32 @@ internal static class MatchedRules
372372
Soundness.Sound,
373373
description: "k sin(x)^2 + k cos(x)^2 = k"),
374374

375+
// ... + sin(x)^2 / d + ... + cos(x)^2 / d + ... -> 1 / d + (everything else)
376+
// A rational coefficient is written as a divisor, cos(x)^2 / 2 and not 1/2 cos(x)^2,
377+
// so the rule above does not see it. The power reduction cos(x)^2 = (1 + cos(2x))/2
378+
// reached -1/2 + cos(x)^2 / 2 + sin(x)^2 / 2 and stopped, while its sine twin was 0.
379+
// Sound: both sides are defined exactly where d is not 0.
380+
// https://github.com/asc-community/AngouriMath/issues/2142
381+
new MatchedRule(
382+
"squared-sine-and-cosine-over-one-divisor-sum-to-its-reciprocal",
383+
MatchPattern.Gathered<Sumf>(
384+
"rest",
385+
MatchPattern.Node<Divf>(
386+
MatchPattern.Node<Powf>(
387+
MatchPattern.Node<Sinf>(MatchPattern.Any("x")),
388+
MatchPattern.Exact(Integer.Create(2))),
389+
MatchPattern.Any("d")),
390+
MatchPattern.Node<Divf>(
391+
MatchPattern.Node<Powf>(
392+
MatchPattern.Node<Cosf>(MatchPattern.Any("x")),
393+
MatchPattern.Exact(Integer.Create(2))),
394+
MatchPattern.Any("d"))),
395+
MatchPattern.Node<Sumf>(
396+
MatchPattern.Node<Divf>(MatchPattern.Exact(Integer.Create(1)), MatchPattern.Any("d")),
397+
MatchPattern.Any("rest")),
398+
Soundness.Sound,
399+
description: "sin(x)^2 / d + cos(x)^2 / d = 1 / d"),
400+
375401
// ... + 1 + ... + tan(x)^2 + ... -> sec(x)^2 + (everything else), and the same with
376402
// the cotangent. The identity divided through by cos^2 and by sin^2 is also in
377403
// TrigonometricRules, but for two siblings only, so the sort decided again: secant

‎Sources/AngouriMath/Core/Transformations/Saturation.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ internal static class Saturation
4343
/// one, and that is a measurement rather than a preference.</b> It reads like the value a
4444
/// ceiling should refuse — it means the rule's growth was not judged, because its
4545
/// replacement is code rather than a written pattern, so admitting it accepts a rewrite
46-
/// nobody measured. But it is where the rules are: of the 340 rules in
47-
/// <see cref="MatchedRules"/>, <b>129 collect, 49 rearrange, 36 expand and 126 are
46+
/// nobody measured. But it is where the rules are: of the 341 rules in
47+
/// <see cref="MatchedRules"/>, <b>130 collect, 49 rearrange, 36 expand and 126 are
4848
/// unjudged</b>. A ceiling that refuses the fourth value still refuses 37% of the library,
4949
/// and what is left could not do much when this was written — over six expression pairs
5050
/// equal only through a larger intermediate form, the

‎Sources/AngouriMath/Docs/Contributing/WritingARule.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ effect". This is how to supply those seven things.
1818
## Where a rule goes
1919

2020
`Core/Transformations/Matching/MatchedRules.cs`, as a value in a `MatchedRuleSet`. **33** sets and
21-
**340** rules live there today.
21+
**341** rules live there today.
2222

2323
The `switch` statements in `Functions/Simplification/Patterns` are the older form. **All thirty
2424
registered sets now run as data and describe what they run**; none executes its `switch` any more.
@@ -64,7 +64,7 @@ in a name and putting the identity in brackets after it:
6464
2. Tangent is sine over cosine (tan(a) = sin(a) / cos(a)), so tan(x) becomes sin(x) / cos(x).
6565
```
6666

67-
So the name has to be a clause that survives being read that way. **All 311 distinct rule names are,
67+
So the name has to be a clause that survives being read that way. **All 312 distinct rule names are,
6868
and `StepAsASentenceTest` holds them to it** — a name with a capital, a bracket or an underscore
6969
fails that test rather than degrading the prose quietly.
7070

@@ -91,7 +91,7 @@ debugged for an afternoon.
9191
| `Left.ToString()` | `Divf(var a, Divf(var b, var c))` — how the matcher spells it |
9292

9393
Write the identity with `=`, not `->`: it is an equality, and the arrow belongs to the direction the
94-
rule happens to be applied in. **337** rules carry one today; a new rule should.
94+
rule happens to be applied in. **338** rules carry one today; a new rule should.
9595

9696
## The pattern language
9797

@@ -123,14 +123,14 @@ matches and silently builds nothing. `BuildableNodeTypesTest` is the list.
123123

124124
## Replacement: a pattern, or code
125125

126-
**41** of the 340 rules have a pattern on both sides. The rest build their answer in code, and both
126+
**42** of the 341 rules have a pattern on both sides. The rest build their answer in code, and both
127127
are legitimate — but the choice costs two things, so make it deliberately.
128128

129129
A pattern replacement gets:
130130

131-
- **a direction.** `MatchedRule.Reversed` is the rule read the other way, and **36** of the 41
132-
two-sided rules have one. The other five forget something: `sin²+cos² = 1` and
133-
`k sin² + k cos² = k` forget the angle,
131+
- **a direction.** `MatchedRule.Reversed` is the rule read the other way, and **36** of the 42
132+
two-sided rules have one. The other six forget something: `sin²+cos² = 1`,
133+
`k sin² + k cos² = k` and `sin²/d + cos²/d = 1/d` forget the angle,
134134
`{ x : x in S } = S` forgets the name the set builder bound, and `c ^ log(c, a) = a` and
135135
`c ^ (k * log(c, a)) = a ^ k` for a constant `c` forget which constant, so none has anything to
136136
read back.
@@ -227,7 +227,7 @@ limit, against nothing for handing the node over.
227227
| `SoundUnderAssumptions` | holds given something the rule does not check |
228228
| `Heuristic` | usually right |
229229

230-
**189** of the 340 rules are `Sound` and **151** are conditional. Every one of the thirty registered
230+
**190** of the 341 rules are `Sound` and **151** are conditional. Every one of the thirty registered
231231
*sets* declares `SoundUnderAssumptions`, because a set's tier is the **minimum** over its rules — so
232232
the set grain says nothing and the rule grain says everything. A derivation reports the rule's tier
233233
(`RewriteStep.Soundness`), which is why getting it right matters beyond the label.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath;
9+
using AngouriMath.Extensions;
10+
using Xunit;
11+
using static AngouriMath.Entity.Number;
12+
13+
namespace AngouriMath.Tests.Common
14+
{
15+
/// <summary>
16+
/// <c>cos(x)^2 = (1 + cos(2x))/2</c> was not proved while its sine twin was: the difference
17+
/// reached <c>-1/2 + cos(x)^2 / 2 + sin(x)^2 / 2</c>, and a squared sine and cosine over one
18+
/// divisor was found by no rule.
19+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2142">#2142</a>
20+
/// </summary>
21+
[Trait("Area", "Common")]
22+
public sealed class PowerReductionTest
23+
{
24+
[Theory]
25+
[InlineData("cos(x)^2 - (1 + cos(2*x))/2", "0")]
26+
[InlineData("sin(x)^2 - (1 - cos(2*x))/2", "0")]
27+
[InlineData("sin(x)^2/3 + cos(x)^2/3", "1/3")]
28+
[InlineData("a + sin(t)^2/b + cos(t)^2/b", "a + 1/b")]
29+
public void TheIdentityHolds(string input, string expected)
30+
{
31+
// a + 1/b less itself is 0 provided b is not 0, and the condition is not what is compared.
32+
var difference = (input.Simplify() - expected.ToEntity()).Simplify();
33+
while (difference is AngouriMath.Entity.Providedf(var inner, _))
34+
difference = inner;
35+
Assert.Equal(Integer.Zero, difference);
36+
}
37+
38+
/// <summary>Two different divisors are not the identity.</summary>
39+
[Fact]
40+
public void DifferentDivisorsAreLeft()
41+
=> Assert.Contains("sin", "sin(x)^2/2 + cos(x)^2/3".Simplify().Stringize());
42+
}
43+
}

‎Sources/Tests/UnitTests/Core/Transformations/ReversibleRuleTest.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public void EveryDataRuleIsClassifiedAsWritten()
370370
"one-less-a-squared-sine-is-a-squared-cosine: ReplacementIsCode",
371371
"sine-of-a-whole-multiple-of-an-angle: ReplacementIsCode",
372372
"squared-sine-and-cosine-of-one-argument-sum-to-one: ReplacementDropsHoles",
373+
"squared-sine-and-cosine-over-one-divisor-sum-to-its-reciprocal: ReplacementDropsHoles",
373374
"squared-sine-and-cosine-with-one-coefficient-sum-to-it: ReplacementDropsHoles",
374375
"the-arctangent-of-one-over-root-three: ReplacementIsCode",
375376
"the-arctangent-of-root-three: ReplacementIsCode",
@@ -437,13 +438,13 @@ public void AReversedRuleSaysWhatAnExpressionCameFrom()
437438
[Fact]
438439
public void ARuleThatForgetsAHoleHasNoBackwardsReading()
439440
{
440-
// Both Pythagorean rules of the set, with a coefficient and without, drop the
441-
// argument. The set's other two, 1 + tan^2 = sec^2 and its cotangent twin, keep it,
441+
// The three Pythagorean rules of the set, with a coefficient, a divisor or neither,
442+
// drop the argument. The set's other two, 1 + tan^2 = sec^2 and its cotangent twin, keep it,
442443
// and they are the only ones its reversal holds.
443444
var pythagoras = MatchedRules.PythagoreanIdentity.Rules
444445
.Where(rule => rule.Name.StartsWith("squared-sine-and-cosine", StringComparison.Ordinal))
445446
.ToList();
446-
Assert.Equal(2, pythagoras.Count);
447+
Assert.Equal(3, pythagoras.Count);
447448
foreach (var rule in pythagoras)
448449
{
449450
Assert.Equal(RuleReversal.ReplacementDropsHoles, rule.Reversal);

‎Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static void Stated(int stated, int measured, string claim)
4343
public void WhereARuleGoes()
4444
{
4545
Stated(33, MatchedRules.All.Count, "the number of rule sets written as data");
46-
Stated(340, MatchedRules.All.Sum(set => set.Rules.Count), "the number of rules written as data");
46+
Stated(341, MatchedRules.All.Sum(set => set.Rules.Count), "the number of rules written as data");
4747
Stated(30, RewriteRules.All.Count, "the number of registered sets");
4848
// Two families register under one name and run a data set under another --
4949
// CommonDenominator over MatchedRules.CommonDenominator(level), CanonicalOrder over
@@ -64,7 +64,7 @@ public void TheNameIsASentence()
6464
{
6565
var names = MatchedRules.All.SelectMany(set => set.Rules)
6666
.Select(rule => rule.Name).Distinct(StringComparer.Ordinal).ToList();
67-
Stated(311, names.Count, "the number of distinct rule names");
67+
Stated(312, names.Count, "the number of distinct rule names");
6868

6969
var words = names.Select(name => name.Split('-').Length).ToList();
7070
Stated(4, words.Min(), "the shortest rule name in words");
@@ -73,7 +73,7 @@ public void TheNameIsASentence()
7373

7474
[Fact]
7575
public void TheIdentityIsNotTheName()
76-
=> Stated(337,
76+
=> Stated(338,
7777
MatchedRules.All.SelectMany(set => set.Rules).Count(rule => rule.Description is not null),
7878
"how many rules carry an identity");
7979

@@ -85,7 +85,7 @@ public void ThePatternLanguage()
8585
public void ReplacementAPatternOrCode()
8686
{
8787
var rules = MatchedRules.All.SelectMany(set => set.Rules).ToList();
88-
Stated(41, rules.Count(rule => rule.Right is not null),
88+
Stated(42, rules.Count(rule => rule.Right is not null),
8989
"how many rules have a pattern on both sides");
9090
Stated(36, rules.Count(rule => rule.Reversed is not null),
9191
"how many two-sided rules have a direction");
@@ -97,7 +97,7 @@ public void ReplacementAPatternOrCode()
9797
// rearrange, 9 expand and 270 unjudged", measured before the growth declarations
9898
// went in. The argument survived; the arithmetic did not. A number a remark reasons
9999
// from belongs somewhere that fails when it moves.
100-
Stated(129, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Collects),
100+
Stated(130, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Collects),
101101
"how many rules are declared Collects");
102102
Stated(49, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Rearranges),
103103
"how many rules are declared Rearranges");
@@ -121,6 +121,7 @@ public void ReplacementAPatternOrCode()
121121
"a-constant-raised-to-a-logarithm-of-itself-is-the-antilogarithm",
122122
"a-constant-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm",
123123
"squared-sine-and-cosine-of-one-argument-sum-to-one",
124+
"squared-sine-and-cosine-over-one-divisor-sum-to-its-reciprocal",
124125
"squared-sine-and-cosine-with-one-coefficient-sum-to-it",
125126
},
126127
oneWay);
@@ -133,7 +134,7 @@ public void ReplacementAPatternOrCode()
133134
public void SoundnessIsPerRule()
134135
{
135136
var rules = MatchedRules.All.SelectMany(set => set.Rules).ToList();
136-
Stated(189, rules.Count(rule => rule.Soundness is Soundness.Sound),
137+
Stated(190, rules.Count(rule => rule.Soundness is Soundness.Sound),
137138
"how many rules are Sound");
138139
Stated(151, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions),
139140
"how many rules are SoundUnderAssumptions");

‎Sources/Tests/UnitTests/Core/Transformations/RuleMetadataTest.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public void AddressableGrowthIsTheRulesOwnAnswer()
8888
public void SoundnessIsFinerPerRuleThanPerSet()
8989
{
9090
var rules = MatchedRules.All.SelectMany(set => set.Rules).ToList();
91-
Assert.Equal(340, rules.Count);
92-
Assert.Equal(189,rules.Count(rule => rule.Soundness is Soundness.Sound));
91+
Assert.Equal(341, rules.Count);
92+
Assert.Equal(190,rules.Count(rule => rule.Soundness is Soundness.Sound));
9393
Assert.Equal(151, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions));
9494

9595
// And every set still reports the weakest of them, which is what makes the set grain

‎Sources/Tests/UnitTests/Core/Transformations/StepAsASentenceTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void EveryRuleWrittenAsDataIsNamedInProse()
5959
{
6060
var names = MatchedRules.All.SelectMany(set => set.Rules).Select(rule => rule.Name)
6161
.Distinct(StringComparer.Ordinal).ToList();
62-
Assert.Equal(311, names.Count);
62+
Assert.Equal(312, names.Count);
6363
Assert.All(names, name => Assert.True(Explanation.IsProse(name),
6464
$"'{name}' is a rule name that does not read as a phrase in English"));
6565

0 commit comments

Comments
 (0)