-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (70 loc) · 3.06 KB
/
Program.cs
File metadata and controls
74 lines (70 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Example program to demonstrate use of SymSharp.
using SymSharp;
// Top-level: simple interactive console for demonstration and manual testing.
Console.WriteLine("Welcome to Sym# CAS!");
bool exitted = false;
while (!exitted)
{
// Present simple menu to choose modes (calculator vs differentiation).
Console.WriteLine("\nChoose what you want from the following options:");
Console.WriteLine("0: Quit");
Console.WriteLine("1: Calculator");
Console.WriteLine("2: Differentiation world (BETA, simplification is NOT perfect)");
Console.Write("\nWhich option do you choose? ");
string? optionChosen = Console.ReadLine();
switch (optionChosen)
{
case "0":
// Exit the interactive loop
exitted = true;
continue;
case "1":
// Calculator mode: evaluates purely numeric expressions
Console.WriteLine("\nSym# CAS Mode 1: Calculator");
Console.WriteLine("This works ONLY for numbers, NOT FOR LETTERS!");
Console.WriteLine(" Quote: Numbers and letters are like gasoline and milk.");
Console.WriteLine(" They should not be mixed together.");
Console.WriteLine("TIP: Type nothing or 'q' to quit.");
while (true)
{
Console.Write("\n> ");
string expression = Console.ReadLine() ?? "q";
if (expression == "q")
{
Console.WriteLine("Exitting Sym# CAS Mode 1... ");
break;
}
// Evaluate numeric expression using the Evaluator helper.
var result = Evaluator.Evaluate(expression);
Console.WriteLine($" = {result}");
}
break;
case "2":
// Differentiation mode: parse expression symbolically and compute derivative
Console.WriteLine("\nSym# CAS Mode 2: Differentiation world");
Console.WriteLine("This feature is still BETA.");
Console.WriteLine(" Reason: Expression formatting problem");
Console.WriteLine("TIP: Type nothing or 'q' to quit.");
while (true)
{
// Create a sample variable for convenience when building expressions programmatically.
var x = new Variable("x");
Console.Write("\ny = ");
string yDef = Console.ReadLine() ?? "q";
if (yDef == "q")
{
Console.WriteLine("Exitting Sym# CAS Mode 2... ");
break;
}
// Parse the user input into an expression and show its derivative.
var y = SymFactory.FromString(yDef);
Console.WriteLine($"dy/dx = {y.Derivative("x")}");
}
break;
default:
// Unrecognized menu option
Console.WriteLine("Invalid Option.");
break;
}
}
Console.WriteLine("See you later! :D");