Skip to content

Commit 6a0ca99

Browse files
Twelfth Commit
1 parent 27e745b commit 6a0ca99

14 files changed

Lines changed: 36 additions & 3 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
obj/
3+
*.exe
4+
5+
.fake

MultiplyOperator.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ public IMathExpression Simplified()
9898
return new MultiplyOperator(simplifiedRight, simplifiedLeft);
9999
}
100100

101+
// Distribution!!!
102+
if (simplifiedLeft is AddOperator a && (simplifiedRight is Scalar || simplifiedRight is Variable))
103+
{
104+
return new AddOperator(new MultiplyOperator(a.Left, simplifiedRight), new MultiplyOperator(a.Right, simplifiedRight)).Simplified();
105+
}
106+
107+
// Distribution!!!
108+
if (simplifiedRight is AddOperator b && (simplifiedLeft is Scalar || simplifiedLeft is Variable))
109+
{
110+
return new AddOperator(new MultiplyOperator(b.Left, simplifiedLeft), new MultiplyOperator(b.Right, simplifiedLeft)).Simplified();
111+
}
112+
113+
// Defactor!!
114+
if (simplifiedLeft is AddOperator c && simplifiedRight is AddOperator d)
115+
{
116+
// (c1 + c2)(d1 + d2) = (c1 + c2)d1 + (c1 + c2)d2 = c1d1 + c2d1 + c2d2 + c1d2
117+
return new AddOperator(
118+
new AddOperator(
119+
new MultiplyOperator(c.Left, d.Left),
120+
new MultiplyOperator(c.Right, d.Left)
121+
), new AddOperator(
122+
new MultiplyOperator(c.Left, d.Right),
123+
new MultiplyOperator(c.Right, d.Right)
124+
)
125+
).Simplified();
126+
}
127+
101128
return combinedExpression;
102129
}
103130

Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
Console.WriteLine("Exitting Sym# CAS Mode 2... ");
5959
break;
6060
}
61+
6162
// Parse the user input into an expression and show its derivative.
6263
var y = SymFactory.FromString(yDef);
6364
Console.WriteLine($"dy/dx = {y.Derivative("x")}");

bin/Debug/net9.0/SymSharp.dll

512 Bytes
Binary file not shown.

bin/Debug/net9.0/SymSharp.exe

0 Bytes
Binary file not shown.

bin/Debug/net9.0/SymSharp.pdb

792 Bytes
Binary file not shown.

obj/Debug/net9.0/SymSharp.AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[assembly: System.Reflection.AssemblyCompanyAttribute("SymSharp")]
1414
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
1515
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
16-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3f0be9c27c52ea56d56e6ab9314bd50d30186674")]
16+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+27e745b92bf6a3321f09f17d475f17caacf8ed60")]
1717
[assembly: System.Reflection.AssemblyProductAttribute("SymSharp")]
1818
[assembly: System.Reflection.AssemblyTitleAttribute("SymSharp")]
1919
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f12525410d644237c0ceebf66529e4d78d5f7566ad1355f8087b35b2c54d8cd1
1+
8b4e3f8ac5060963fe52bdf18da42c7a6a7f83ac8ab9e8563c7f5d8966448f0b

obj/Debug/net9.0/SymSharp.dll

512 Bytes
Binary file not shown.

obj/Debug/net9.0/SymSharp.pdb

792 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)