AngouriMath
Piecewise
Method with 2 overloads
Piecewise(System.Collections.Generic.IEnumerable{AngouriMath.Entity.Providedf},AngouriMath.Entity)
Summary
This is a piecewisely defined function, which turns into a particular definition
once there exists a case number N such that case[N].Predicate is turned into true and
for all i less than N : case[i].Predicate is turned into false.
For example, Piecewise(new Providedf(a, b), new Providedf(d, false), new Providedf(f, true))
will remain unchanged, because the first case is uncertain.
Piecewise(new Providedf(a, false), new Providedf(d, false), new Providedf(f, true))
will turn into f
Piecewise(new Providedf(a, false), new Providedf(d, false), new Providedf(f, false))
will turn into NaN
Parameter "cases"
Cases, each of type Provided.
Parameter "otherwise"
An otherwise case. Will be intepreted as otherwise.Provided(true). Optional.
Example
using System; using static AngouriMath.MathS; var expr = Piecewise( ("-1", "x < 0"), ("0", "x = 0"), ("1", true) ); Console.WriteLine(expr); Console.WriteLine(expr.Substitute("x", 10).Evaled); Console.WriteLine(expr.Substitute("x", 0).Evaled); Console.WriteLine(expr.Substitute("x", -14).Evaled); Console.WriteLine(); var weirdSqrt = Piecewise( ("sqrt(x)", "x >= 0"), ("-sqrt(-x)", true) ); Console.WriteLine(weirdSqrt); Console.WriteLine(weirdSqrt.Substitute("x", 16).Evaled); Console.WriteLine(weirdSqrt.Substitute("x", -16).Evaled); Console.WriteLine(); var thousandVisualizer = Piecewise( ("a / 1000000 million", "a > 1000000"), ("a / 1000 thousand", "a > 1000"), ("a", "a >= 0") ); Console.WriteLine(thousandVisualizer.Substitute("a", 19301).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", 19301123).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", 32).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", -24).Evaled);
Prints
(-1 if x < 0, 0 if x = 0, 1 if True) 1 0 -1 (sqrt(x) if x >= 0, -sqrt(-x) if True) 4 -4 19301/1000 * thousand 19301123/1000000 * million 32 NaN
Piecewise(System.ValueTuple{AngouriMath.Entity,AngouriMath.Entity}[])
Summary
This is a piecewisely defined function, which turns into a particular definition
once there exists a case number N such that case[N].Predicate is turned into true and
for all i less than N : case[i].Predicate is turned into false.
For example, Piecewise((a, b), (d, false), (f, true))
will remain unchanged, because the first case is uncertain.
Piecewise((a, false), (d, false), (f, true))
will turn into f
Piecewise((a, false), (d, false), (f, false))
will turn into NaN
Parameter "cases"
Tuples of two expressions: an expression and a predicate
Example
using System; using static AngouriMath.MathS; var expr = Piecewise( ("-1", "x < 0"), ("0", "x = 0"), ("1", true) ); Console.WriteLine(expr); Console.WriteLine(expr.Substitute("x", 10).Evaled); Console.WriteLine(expr.Substitute("x", 0).Evaled); Console.WriteLine(expr.Substitute("x", -14).Evaled); Console.WriteLine(); var weirdSqrt = Piecewise( ("sqrt(x)", "x >= 0"), ("-sqrt(-x)", true) ); Console.WriteLine(weirdSqrt); Console.WriteLine(weirdSqrt.Substitute("x", 16).Evaled); Console.WriteLine(weirdSqrt.Substitute("x", -16).Evaled); Console.WriteLine(); var thousandVisualizer = Piecewise( ("a / 1000000 million", "a > 1000000"), ("a / 1000 thousand", "a > 1000"), ("a", "a >= 0") ); Console.WriteLine(thousandVisualizer.Substitute("a", 19301).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", 19301123).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", 32).Evaled); Console.WriteLine(thousandVisualizer.Substitute("a", -24).Evaled);
Prints
(-1 if x < 0, 0 if x = 0, 1 if True) 1 0 -1 (sqrt(x) if x >= 0, -sqrt(-x) if True) 4 -4 19301/1000 * thousand 19301123/1000000 * million 32 NaN
Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1534 pages online