← Back to the main page

Here we will cover the way you can manipulate global settings of the library.


There are a lot of points at which we cannot trust our choice, and you might want to change the behaviour. That is why we introduced global settings. There is no need to create additional files, and those settings are static properties. The settings are, although static, thread-safe. Every setting is set for one thread only (via [ThreadStatic]), so setting in one thread will not affect the same setting in another thread.

Using Settings

Let us consider a particular example. When AM cannot solve an equation analytically, it would apply numerical methods to solve it, for example, that of Newton. Example:
Entity expr = "x + sin(x) = 0";
Will print:
{ 10.712... + 3.103...i, ... }
(Major share of the result was omitted under "...") This equation does not have a elementary roots (except for 0). We want to restrict it to solving only analytically, and if it cannot solve it so, it should not apply Newton's method. Let us set this setting:
using var _ = MathS.Settings.AllowNewton.Set(false);

Entity expr = "x + sin(x) = 0";
{  }
As it can be seen, it does not apply the Newton's method when solving, even if no analytical solution was found. Summing up, the syntax has two options. The first one is more convenient:
using var _ = MathS.Settings.SomeSetting.Set(SomeValue);
// code
The second one might be useful for parts, when the setting should be reverted before the method ends:
using (var _ = MathS.Settings.SomeSetting.Set(SomeValue))
    // code


This using var _ = syntactical detail might not be appealing, but it allows to revert the value of the setting back to normal at the end of the scope. Make sure that you write exactly like this, otherwise the value will not be reverted back and you might get undesired results.

Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1534 pages online