1
1
import CvxLean
2
+ import CvxLean.Command.Util.TimeCmd
2
3
3
4
noncomputable section
4
5
@@ -16,50 +17,109 @@ def hypersonicShapeDesign :=
16
17
optimization (Δx : ℝ)
17
18
minimize sqrt ((1 / Δx ^ 2 ) - 1 )
18
19
subject to
19
- h1 : 10e-6 ≤ Δx
20
- h2 : Δx ≤ 1
21
- h3 : a * (1 / Δx) - (1 - b) * sqrt (1 - Δx ^ 2 ) ≤ 0
20
+ h₁ : 10e-6 ≤ Δx
21
+ h₂ : Δx ≤ 1
22
+ h₃ : a * (1 / Δx) - (1 - b) * sqrt (1 - Δx ^ 2 ) ≤ 0
22
23
23
- set_option trace.Meta.debug true
24
-
25
- #check Lean.Expr
26
-
27
- equivalence eqv/hypersonicShapeDesignConvex (a b : ℝ) (ha : 0 ≤ a) (hb : b < 1 ) :
24
+ equivalence' eqv₁/hypersonicShapeDesignConvex (a b : ℝ) (ha : 0 ≤ a) (hb₁ : 0 ≤ b) (hb₂ : b < 1 ) :
28
25
hypersonicShapeDesign a b := by
29
26
pre_dcp
30
27
28
+ #print hypersonicShapeDesignConvex
29
+
31
30
@[optimization_param]
32
31
def aₚ : ℝ := 0 .05
33
32
33
+ @[simp high]
34
34
lemma aₚ_nonneg : 0 ≤ aₚ := by
35
35
unfold aₚ; norm_num
36
36
37
37
@[optimization_param]
38
38
def bₚ : ℝ := 0 .65
39
39
40
+ lemma bₚ_nonneg : 0 ≤ bₚ := by
41
+ unfold bₚ; norm_num
42
+
40
43
lemma bₚ_lt_one : bₚ < 1 := by
41
44
unfold bₚ; norm_num
42
45
43
46
@[simp high]
44
- lemma one_sub_bₚ_nonpos : 0 ≤ 1 - bₚ := by
47
+ lemma one_sub_bₚ_nonneg : 0 ≤ 1 - bₚ := by
45
48
unfold bₚ; norm_num
46
49
47
- solve hypersonicShapeDesignConvex aₚ bₚ aₚ_nonneg bₚ_lt_one
50
+ time_cmd solve hypersonicShapeDesignConvex aₚ bₚ aₚ_nonneg bₚ_nonneg bₚ_lt_one
51
+
52
+ #print hypersonicShapeDesignConvex.reduced
48
53
49
54
-- Final width of wedge.
50
- def width := hypersonicShapeDesignConvex.solution
55
+ def width := eqv₁.backward_map aₚ.float bₚ.float hypersonicShapeDesignConvex.solution
51
56
52
- #eval width
57
+ #eval width -- 0.989524
58
+
59
+ #eval aₚ.float * (1 / width) - (1 - bₚ.float) * Float.sqrt (1 - width ^ 2 ) ≤ 0
60
+ #eval aₚ.float * (1 / width) - (1 - bₚ.float) * Float.sqrt (1 - width ^ 2 ) ≤ 0 .000001
53
61
54
62
-- Final height of wedge.
55
63
def height := Float.sqrt (1 - width ^ 2 )
56
64
57
- #eval height
65
+ #eval height -- 0.144368
58
66
59
67
-- Final L/D ratio.
60
68
def ldRatio := 1 / (Float.sqrt ((1 / width ^ 2 ) - 1 ))
61
69
62
- #eval ldRatio
70
+ #eval ldRatio -- 6.854156
71
+
72
+ -- While the above is good enough, we simplify the problem further by performing a change of
73
+ -- variables and simplifying appropriately.
74
+
75
+ equivalence' eqv₂/hypersonicShapeDesignSimpler (a b : ℝ) (ha : 0 ≤ a) (hb₁ : 0 ≤ b)
76
+ (hb₂ : b < 1 ) : hypersonicShapeDesignConvex a b ha hb₁ hb₂ := by
77
+ change_of_variables (z) (Δx ↦ sqrt z)
78
+ conv_constr h₁ =>
79
+ rewrite [le_sqrt' (by norm_num)]; norm_num
80
+ conv_constr h₂ =>
81
+ rewrite [sqrt_le_iff]; norm_num
82
+ rw_constr h₃ =>
83
+ have hz : 0 ≤ z := by arith
84
+ have h_one_sub_z : 0 ≤ 1 - z := by arith
85
+ rewrite [rpow_two (sqrt a), sq_sqrt ha, rpow_two (sqrt z), sq_sqrt hz]
86
+ rewrite [div_le_iff (by arith)]
87
+ have hlhs : 0 ≤ a / sqrt z := div_nonneg ha (sqrt_nonneg _)
88
+ have hrhs : 0 ≤ sqrt (1 - z) * (1 - b) := mul_nonneg (sqrt_nonneg _) (by arith)
89
+ rewrite [← pow_two_le_pow_two hlhs hrhs]
90
+ rewrite [div_rpow ha (sqrt_nonneg _), rpow_two (sqrt z), sq_sqrt hz]
91
+ rewrite [mul_rpow (sqrt_nonneg _) (by arith), rpow_two (sqrt (1 - z)), sq_sqrt h_one_sub_z]
92
+ rewrite [← mul_one_div, ← inv_eq_one_div, mul_comm (1 - z) _]
93
+ rfl
94
+ rename_constrs [h₁, h₂, h₃]
95
+ rw_obj =>
96
+ rewrite [rpow_neg (sqrt_nonneg _), rpow_two (sqrt z), sq_sqrt (by arith)]
97
+ rfl
98
+
99
+ #print hypersonicShapeDesignSimpler
100
+
101
+ time_cmd solve hypersonicShapeDesignSimpler aₚ bₚ aₚ_nonneg bₚ_nonneg bₚ_lt_one
102
+
103
+ #print hypersonicShapeDesignSimpler.reduced
104
+
105
+ -- Final width of wedge.
106
+ def width' :=
107
+ eqv₁.backward_map aₚ.float bₚ.float <|
108
+ eqv₂.backward_map aₚ.float bₚ.float hypersonicShapeDesignSimpler.solution
109
+
110
+ #eval width' -- 0.989524
111
+
112
+ #eval aₚ.float * (1 / width') - (1 - bₚ.float) * Float.sqrt (1 - width' ^ 2 ) ≤ 0
113
+
114
+ -- Final height of wedge.
115
+ def height' := Float.sqrt (1 - width' ^ 2 )
116
+
117
+ #eval height' -- 0.144371
118
+
119
+ -- Final L/D ratio.
120
+ def ldRatio' := 1 / (Float.sqrt ((1 / width' ^ 2 ) - 1 ))
121
+
122
+ #eval ldRatio' -- 6.854031
63
123
64
124
end HypersonicShapeDesign
65
125
0 commit comments