Repository navigation
Expand file tree
/
Copy pathProvidedImpliedByTheExpressionTest.cs
More file actions
77 lines (72 loc) · 3.86 KB
/
Copy pathProvidedImpliedByTheExpressionTest.cs
File metadata and controls
77 lines (72 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//
using AngouriMath;
using AngouriMath.Extensions;
using Xunit;
namespace AngouriMath.Tests.Core
{
/// <summary>
/// A <c>provided</c> condition the expression states on its own is dropped: <c>1/x provided
/// not x = 0</c> is <c>1/x</c>, since the quotient's own domain condition, read in the
/// ambient codomain, already excludes zero. Only where that domain condition proves it, and
/// on the expression as it stands after simplification, so that <c>x/x</c>, which becomes
/// <c>1</c>, keeps the condition it can no longer state.
/// https://github.com/asc-community/AngouriMath/issues/1394
/// </summary>
[Trait("Area", "Core")]
public sealed class ProvidedImpliedByTheExpressionTest
{
[Theory]
[InlineData("(1 - ln(x)) / x^2 provided not x = 0", "(1 - ln(x)) / x^2")]
[InlineData("(1 + ln(x)) * x^x provided not x = 0", "(1 + ln(x)) * x^x")]
[InlineData("1/x provided not x = 0", "1/x")]
[InlineData("x^(-2) provided not x = 0", "1/x^2")]
[InlineData("ln(x) provided not x = 0", "ln(x)")]
[InlineData("sin(x)/x + x^x provided not x = 0 and not y = 0", "sin(x)/x + x^x provided not y = 0")]
[InlineData("tan(x) provided not cos(x) = 0", "tan(x)")]
[InlineData("1/(x * y) provided not x = 0 and not y = 0", "1/(x * y)")]
[InlineData("1/(x^2 + x) provided not x = 0 and not x + 1 = 0", "1/(x^2 + x)")]
[InlineData("1/(x^2 + x) provided not x = 0 and not y = 0", "1/(x^2 + x) provided not y = 0")]
public void TheConditionTheExpressionStatesIsDropped(string input, string expected)
=> Assert.Equal(expected.ToEntity().Simplify(), input.ToEntity().Simplify());
/// <summary>
/// An implication needs its conclusion's condition only where its assumption holds, and
/// not at all where the assumption states it: <c>not x = 0 implies x/x = 1</c> holds at
/// every <c>x</c>, 0 among them, where it was <c>True provided not x = 0</c>.
/// https://github.com/asc-community/AngouriMath/issues/1409
/// </summary>
[Theory]
[InlineData("not x = 0 implies x / x = 1", "True")]
[InlineData("x > 0 and not x = 0 implies x / x = 1", "True")]
[InlineData("not x = 0 implies (y / y = 1)", "(not x = 0 implies True) provided (not x = 0 implies not y = 0)")]
public void AnAssumptionDischargesTheConditionItStates(string input, string expected)
=> Assert.Equal(expected.ToEntity().Simplify(), input.ToEntity().Simplify());
/// <summary>
/// The derivatives the comparison page shows, which carried the condition twice.
/// </summary>
[Theory]
[InlineData("ln(x) / x", "(1 - ln(x)) / x^2")]
[InlineData("x^x", "(1 + ln(x)) * x^x")]
public void ADerivativeStatesItsOwnDomain(string function, string derivative)
{
var got = function.ToEntity().Differentiate("x").Simplify();
Assert.DoesNotContain("provided", got.Stringize());
Assert.Equal(derivative.ToEntity().Simplify(), got);
}
/// <summary>
/// A condition the expression does not state stays: the one on a quotient that has
/// cancelled, one about a symbol the expression no longer holds, and one about a factor
/// beside the one the quotient is by.
/// </summary>
[Theory]
[InlineData("x / x provided not x = 0")]
[InlineData("1 / (x^2 + 1) provided not x = 0")]
[InlineData("y / x provided not a * x = 0")]
public void AConditionTheExpressionDoesNotStateStays(string input)
=> Assert.Contains("provided", input.ToEntity().Simplify().Stringize());
}
}