using System using System Collections Generic using System Linq using

 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace огыеагт
{
class Program
{
static void Main(string[] args)
{
ParameterExpression value = Expression.Variable(typeof(double), "value");
ParameterExpression value2 = Expression.Variable(typeof(double), "value2");
ParameterExpression J = Expression.Parameter(typeof(double), "J");
ParameterExpression upperBound = Expression.Parameter(typeof(double), "upperBound");
ParameterExpression result = Expression.Variable(typeof(double), "result");
ParameterExpression mainResult = Expression.Variable(typeof(double), "mainResult");
LabelTarget innerLoopLabel = Expression.Label(typeof(double));
LabelTarget outerLoopLabel = Expression.Label(typeof(double));
BlockExpression block = Expression.Block(
new[] { mainResult, result },
Expression.Assign(mainResult, Expression.Constant(0.0)),
Expression.Assign(result, Expression.Constant(1.0)),
Expression.Loop(
Expression.IfThenElse(
Expression.And(
Expression.GreaterThan(result, Expression.Constant(0.0001)),
Expression.LessThan(J,upperBound)
),
Expression.Block(
new[] { value, value2 },
Expression.Assign(result, Expression.Constant(1.0)),
Expression.Assign(value,J),
Expression.Assign(value2, Expression.Add(
Expression.Multiply(Expression.Constant(2.0), J),
Expression.Constant(1.0)
)
),
Expression.Loop(
Expression.IfThenElse(
Expression.GreaterThan(value2, Expression.Constant(0.0)),
Expression.MultiplyAssign(result,
Expression.Divide(value, Expression.PostDecrementAssign(value2))),
Expression.Break(innerLoopLabel, result)
),
innerLoopLabel
),
Expression.AddAssign(mainResult,result),
Expression.AddAssign(J,Expression.Constant(0.05))
),
Expression.Break(outerLoopLabel, mainResult)
),
outerLoopLabel
)
);
Console.WriteLine(Expression.Lambda<Func<double, double, double>>(block, J, upperBound).Compile()(0.1D, 1.1D));
Console.ReadKey();
}
}
}