- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
abstract class Var : Expr
{
public double Value;
public override double Eval() { return Value; }
public override double Eval(params Var[] arr)
{
foreach (var i in arr)
{
if (i.GetType() == this.GetType()) return i.Value;
}
return Value;
}
public Var(double value)
{
Value = value;
}
public Var() { }
public override string ToString() { return this.GetType().Name; }
}
class X : Var { public X(double value) : base(value) { } public X() { } }
class Y : Var { public Y(double value) : base(value) { } public Y() { } }
class Z : Var { public Z(double value) : base(value) { } public Z() { } }
class Fun : Expr
{
fun function;
Expr value;
String name;
public Fun(fun function, Expr value, String name = null)
{
this.function = function;
this.value = value;
this.name = name ?? function.Method.Name;
}
public override double Eval()
{
return function(value.Eval());
}
public override double Eval(params Var[] arr)
{
return function(value.Eval(arr));
}
public override string ToString()
{
return String.Format("{0}({1})", name, value);
}
public override int Length { get { return value.Length; } }
public override Expr Simple()
{
var _value = value.Simple();
if (_value is Const) return function(((Const)value).value);
return new Fun(function, _value, name);
}
}
class Func
{
fun function;
String name;
public Func(fun function, String name = null)
{
this.function = function;
this.name = name;
}
public Expr GetFun(Expr value)
{
return new Fun(function, value, name);
}
}
class Fun2 : Expr
{
fun2 function;
Expr left, right;
String name;
public Fun2(fun2 function, Expr left, Expr right, String name = null)
{
this.function = function;
this.left = left;
this.right = right;
this.name = name ?? function.Method.Name;
}
public override double Eval() { return function(left.Eval(), right.Eval()); }
public override double Eval(params Var[] arr) { return function(left.Eval(arr), right.Eval(arr)); }
public override string ToString() { return String.Format("{0}({1},{2})", name, left, right); }
public override int Length { get { return left.Length + right.Length; } }
}
class Func2
{
fun2 function;
String name;
public Func2(fun2 function, String name = null)
{
this.function = function;
this.name = name;
}
public Expr GetFun(Expr left, Expr right)
{
return new Fun2(function, left, right, name);
}
}
delegate double fun(double value);
delegate double fun2(double left, double right);
Комментарии (0) RSS
Добавить комментарий