Skip to content

Commit

Permalink
Fix #195
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Apr 3, 2017
1 parent 08da61c commit 21a806c
Show file tree
Hide file tree
Showing 27 changed files with 27 additions and 100 deletions.
61 changes: 27 additions & 34 deletions xFunc.Maths/Analyzers/Simplifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,11 @@ private IExpression AnalyzeBinary(BinaryExpression exp)
return exp;
}

private IExpression AnalyzeTrigonometric(UnaryExpression exp)
private IExpression AnalyzeTrigonometric<T>(UnaryExpression exp) where T : UnaryExpression
{
exp.Argument = exp.Argument.Analyze(this);

var attrs = exp.GetType().GetCustomAttributes(typeof(ReverseFunctionAttribute), false);
if (attrs.Length > 0)
{
var attr = (ReverseFunctionAttribute)attrs[0];

if (exp.Argument.GetType() == attr.ReverseType)
return ((UnaryExpression)exp.Argument).Argument;
}
if (exp.Argument is T trigonometric)
return trigonometric.Argument;

return exp;
}
Expand Down Expand Up @@ -1092,7 +1085,7 @@ public IExpression Analyze(Reciprocal exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arccos exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Cos>(exp);
}

/// <summary>
Expand All @@ -1105,7 +1098,7 @@ public IExpression Analyze(Arccos exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arccot exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Cot>(exp);
}

/// <summary>
Expand All @@ -1118,7 +1111,7 @@ public IExpression Analyze(Arccot exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arccsc exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Csc>(exp);
}

/// <summary>
Expand All @@ -1131,7 +1124,7 @@ public IExpression Analyze(Arccsc exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arcsec exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Sec>(exp);
}

/// <summary>
Expand All @@ -1144,7 +1137,7 @@ public IExpression Analyze(Arcsec exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arcsin exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Sin>(exp);
}

/// <summary>
Expand All @@ -1157,7 +1150,7 @@ public IExpression Analyze(Arcsin exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arctan exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Tan>(exp);
}

/// <summary>
Expand All @@ -1170,7 +1163,7 @@ public IExpression Analyze(Arctan exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Cos exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arccos>(exp);
}

/// <summary>
Expand All @@ -1183,7 +1176,7 @@ public IExpression Analyze(Cos exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Cot exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arccot>(exp);
}

/// <summary>
Expand All @@ -1196,7 +1189,7 @@ public IExpression Analyze(Cot exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Csc exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arccsc>(exp);
}

/// <summary>
Expand All @@ -1209,7 +1202,7 @@ public IExpression Analyze(Csc exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Sec exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arcsec>(exp);
}

/// <summary>
Expand All @@ -1222,7 +1215,7 @@ public IExpression Analyze(Sec exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Sin exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arcsin>(exp);
}

/// <summary>
Expand All @@ -1235,7 +1228,7 @@ public IExpression Analyze(Sin exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Tan exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arctan>(exp);
}

#endregion
Expand All @@ -1252,7 +1245,7 @@ public IExpression Analyze(Tan exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arcosh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Cosh>(exp);
}

/// <summary>
Expand All @@ -1265,7 +1258,7 @@ public IExpression Analyze(Arcosh exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arcoth exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Coth>(exp);
}

/// <summary>
Expand All @@ -1278,7 +1271,7 @@ public IExpression Analyze(Arcoth exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arcsch exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Csch>(exp);
}

/// <summary>
Expand All @@ -1291,7 +1284,7 @@ public IExpression Analyze(Arcsch exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arsech exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Sech>(exp);
}

/// <summary>
Expand All @@ -1304,7 +1297,7 @@ public IExpression Analyze(Arsech exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Arsinh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Sinh>(exp);
}

/// <summary>
Expand All @@ -1317,7 +1310,7 @@ public IExpression Analyze(Arsinh exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Artanh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Tanh>(exp);
}

/// <summary>
Expand All @@ -1330,7 +1323,7 @@ public IExpression Analyze(Artanh exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Cosh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arcosh>(exp);
}

/// <summary>
Expand All @@ -1343,7 +1336,7 @@ public IExpression Analyze(Cosh exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Coth exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arcoth>(exp);
}

/// <summary>
Expand All @@ -1356,7 +1349,7 @@ public IExpression Analyze(Coth exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Csch exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arcsch>(exp);
}

/// <summary>
Expand All @@ -1369,7 +1362,7 @@ public IExpression Analyze(Csch exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Sech exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arsech>(exp);
}

/// <summary>
Expand All @@ -1382,7 +1375,7 @@ public IExpression Analyze(Sech exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Sinh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Arsinh>(exp);
}

/// <summary>
Expand All @@ -1395,7 +1388,7 @@ public IExpression Analyze(Sinh exp)
[ExcludeFromCodeCoverage]
public IExpression Analyze(Tanh exp)
{
return AnalyzeTrigonometric(exp);
return AnalyzeTrigonometric<Artanh>(exp);
}

#endregion Hyperbolic
Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Arcosh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Arcosh function.
/// </summary>
[ReverseFunction(typeof(Cosh))]
public class Arcosh : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Arcoth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Arcoth function.
/// </summary>
[ReverseFunction(typeof(Coth))]
public class Arcoth : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Arcsch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Arcsch function.
/// </summary>
[ReverseFunction(typeof(Csch))]
public class Arcsch : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Arsech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Arsech function.
/// </summary>
[ReverseFunction(typeof(Sech))]
public class Arsech : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Arsinh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Arsinh function.
/// </summary>
[ReverseFunction(typeof(Sinh))]
public class Arsinh : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Artanh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Artanh function.
/// </summary>
[ReverseFunction(typeof(Tanh))]
public class Artanh : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Cosh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic cosine function.
/// </summary>
[ReverseFunction(typeof(Arcosh))]
public class Cosh : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Coth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic cotangent function.
/// </summary>
[ReverseFunction(typeof(Arcoth))]
public class Coth : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Csch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic cosecant function.
/// </summary>
[ReverseFunction(typeof(Arcsch))]
public class Csch : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Sech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic secant function.
/// </summary>
[ReverseFunction(typeof(Arsech))]
public class Sech : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Sinh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic sine function.
/// </summary>
[ReverseFunction(typeof(Arsinh))]
public class Sinh : HyperbolicExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Hyperbolic/Tanh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Hyperbolic
/// <summary>
/// Represents the Hyperbolic tangent function.
/// </summary>
[ReverseFunction(typeof(Artanh))]
public class Tanh : HyperbolicExpression
{

Expand Down
41 changes: 0 additions & 41 deletions xFunc.Maths/Expressions/ReverseFunctionAttribute.cs

This file was deleted.

1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Trigonometric/Arccos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Trigonometric
/// <summary>
/// Represents the Arccosine function.
/// </summary>
[ReverseFunction(typeof(Cos))]
public class Arccos : TrigonometricExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Trigonometric/Arccot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Trigonometric
/// <summary>
/// Represents the Arcotangent function.
/// </summary>
[ReverseFunction(typeof(Cot))]
public class Arccot : TrigonometricExpression
{

Expand Down
1 change: 0 additions & 1 deletion xFunc.Maths/Expressions/Trigonometric/Arccsc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace xFunc.Maths.Expressions.Trigonometric
/// <summary>
/// Represents the Arccosecant function.
/// </summary>
[ReverseFunction(typeof(Csc))]
public class Arccsc : TrigonometricExpression
{

Expand Down

0 comments on commit 21a806c

Please sign in to comment.