Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ported to C# 4 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlekseyCherepanov
Copy link

Avoiding features: "using static", string interpolations with $ and null-checks with ?. op.

String interpolations were replaced with string.Format.

null-checks are done use if statement.

"using static" is a bit trickier:

  • ListConstructor was inserted explicitly,
  • all methods from Symbolism.Constructors and Symbolism.Trigonometric.Constructors were moved into Symbolism.Function and inheritance was used to "import" names

Also avoided => for method definitions.

I applied the following one-liners to parts of code, not to full files (C-| in emacs):
perl -pe '@A = (); $a = 0; s/$//; s/{([^}]+)}/push @A, $1; "{" . $a++ . "}"/ge; s/"."/"string.Format($&, " . (join ", ", @A) . ")"/ge'
perl -lpe 's/=> /{ return / && s/\s
$/ }/'

Feel free to ignore this pull-request if you would like to keep your code as C# 6. I find "using static" feature useful, while my inheritance is a dirty hack.

Avoiding features: "using static", string interpolations with $ and null-checks with ?. op.

String interpolations were replaced with string.Format.

null-checks are done use if statement.

"using static" is a bit trickier:
- ListConstructor was inserted explicitly,
- all methods from Symbolism.Constructors and Symbolism.Trigonometric.Constructors were moved into Symbolism.Function and inheritance was used to "import" names.
@dharmatech
Copy link
Owner

Wow, this is impressive Aleksey! Very cool that you were able to backport everything. I'll definitely leave this pull request here as a reference in case anyone else needs to port to C# 4. If you're free and willing to comment, would love to know more about why you needed to stick with C# 4.0.

@AlekseyCherepanov
Copy link
Author

On Wed, Nov 04, 2015 at 07:52:24PM -0800, dharmatech wrote:

Wow, this is impressive Aleksey!

Much more impressive is that you have a firm style. :-) It simplified
things greatly.

Very cool that you were able to backport everything. I'll definitely
leave this pull request here as a reference in case anyone else
needs to port to C# 4.

Thank you!

If you're free and willing to comment, would love to know more about
why you needed to stick with C# 4.0.

C# 6 was not convenient for me because I teach students and there is
Visual Studio 2012 in classrooms, VS 2012 does not support C# 6. On my
computer, I have Mono, my Mono supports C# 4 (I heard that newer Mono
understands C# 5 though). So I just ported it.

Also I tried other systems: this one
http://www.codeproject.com/Articles/604792/Computer-Algebra-System-for-NET-Framework
and Math.NET Symbolics
https://github.com/mathnet/mathnet-symbolics
But they did not provide functionality I was looking for.

I teach students Difference equations (not differential equations) and
considered to touch symbolic computations a bit. There are a lot of
sums and products. So we define a formula with custom functions to
represent them. The formula of solution for inhomogeneous linear
first-order difference equation (for instance, u(x + 1) = 2 * u(x) + 1):

var f_solution = P(k, x0, x - 1, p(k)) * (C + S(k, x0, x - 1, f(k) * (P(m, x0, k, p(m))^(-1)) ));

And then, we manipulate the formula. I had to write some code to make
it work, but it goes rather well (except that operator priority caught
me: 1 - q^n turned out to be (1 - q)^n while I meant 1 - (q^n)).

I'll open some issues to talk about problems and possible new features.

Thanks!

Regards,
Aleksey Cherepanov

@dharmatech
Copy link
Owner

(except that operator priority caught me: 1 - q^n turned out to be (1 - q)^n while I meant 1 - (q^n))

Yes, unfotunately the ^ operator in C# has quite a low precedence. I've requested an exponentiation operator from the C# team here: https://github.com/dotnet/roslyn/issues/4594

If they decide to add an operator for exponentiation, it will likely be **. Feel free to lobby them in that issue. ;-)

@dharmatech
Copy link
Owner

I'll open some issues to talk about problems and possible new features.

Yes, please do!

@dharmatech
Copy link
Owner

C# 6 was not convenient for me because I teach students and there is Visual Studio 2012 in classrooms, VS 2012 does not support C# 6.
...
I teach students Difference equations (not differential equations) and considered to touch symbolic computations a bit.

Wow, that's very cool. This is the first I've ever heard of Symbolism being used in a classroom. I wasn't expecting that! But I'm glad to hear it suited your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants