@@ -13,19 +13,25 @@ function next_variable!(f, eq)
1313 return μ
1414end
1515
16- transformer (eq:: SymbolicUtils.Add , f) = sum (transformer (t,f) for t in arguments (eq); init= 0 )
17- transformer (eq:: SymbolicUtils.Mul , f) = prod (transformer (t,f) for t in arguments (eq); init= 1 )
18- transformer (eq:: SymbolicUtils.Div , f) = transformer (arguments (eq)[1 ],f) * transformer (inv (arguments (eq)[2 ]),f)
16+ function transformer (eq:: SymbolicUtils.Add , f)
17+ sum (transformer (t, f) for t in arguments (eq); init = 0 )
18+ end
19+ function transformer (eq:: SymbolicUtils.Mul , f)
20+ prod (transformer (t, f) for t in arguments (eq); init = 1 )
21+ end
22+ function transformer (eq:: SymbolicUtils.Div , f)
23+ transformer (arguments (eq)[1 ], f) * transformer (inv (arguments (eq)[2 ]), f)
24+ end
1925
2026function transformer (eq:: SymbolicUtils.Pow , f)
2127 y, k = arguments (eq)
2228
2329 if is_pos_int (k)
2430 μ = next_variable! (f, y)
25- return μ ^ k
31+ return μ^ k
2632 elseif is_neg_int (k)
2733 μ = next_variable! (f, inv (y))
28- return μ ^ - k
34+ return μ^ - k
2935 else
3036 return next_variable! (f, y^ k)
3137 end
@@ -60,7 +66,7 @@ function generate_homotopy(eq, x)
6066 q, sub = transform (eq, x)
6167 S = 0
6268
63- for i = 1 : length (sub)
69+ for i in 1 : length (sub)
6470 μ = u[i]
6571 h₁, ∂h₁ = apply_partial_int_rules (sub[μ])
6672 h₂ = expand_derivatives (Differential (μ)(q))
@@ -71,7 +77,7 @@ function generate_homotopy(eq, x)
7177 S += expand ((1 + h₁) * (1 + h₂))
7278 end
7379
74- unique ([one (x); [equivalent (t,x) for t in terms (S)]])
80+ unique ([one (x); [equivalent (t, x) for t in terms (S)]])
7581end
7682
7783# #############################################################################
@@ -81,63 +87,57 @@ function ∂(x)
8187 return isequal (d, 0 ) ? 1 : d
8288end
8389
84- partial_int_rules = [
85- @rule 𝛷 (^ (sin (~ x), ~ k:: is_neg )) => 𝛷 (^ (csc (~ x), - ~ k))
86- @rule 𝛷 (^ (cos (~ x), ~ k:: is_neg )) => 𝛷 (^ (sec (~ x), - ~ k))
87- @rule 𝛷 (^ (tan (~ x), ~ k:: is_neg )) => 𝛷 (^ (cot (~ x), - ~ k))
88- @rule 𝛷 (^ (csc (~ x), ~ k:: is_neg )) => 𝛷 (^ (sin (~ x), - ~ k))
89- @rule 𝛷 (^ (sec (~ x), ~ k:: is_neg )) => 𝛷 (^ (cos (~ x), - ~ k))
90- @rule 𝛷 (^ (cot (~ x), ~ k:: is_neg )) => 𝛷 (^ (tan (~ x), - ~ k))
91-
92- @rule 𝛷 (^ (sinh (~ x), ~ k:: is_neg )) => 𝛷 (^ (csch (~ x), - ~ k))
93- @rule 𝛷 (^ (cosh (~ x), ~ k:: is_neg )) => 𝛷 (^ (sech (~ x), - ~ k))
94- @rule 𝛷 (^ (tanh (~ x), ~ k:: is_neg )) => 𝛷 (^ (coth (~ x), - ~ k))
95- @rule 𝛷 (^ (csch (~ x), ~ k:: is_neg )) => 𝛷 (^ (sinh (~ x), - ~ k))
96- @rule 𝛷 (^ (sech (~ x), ~ k:: is_neg )) => 𝛷 (^ (cosh (~ x), - ~ k))
97- @rule 𝛷 (^ (coth (~ x), ~ k:: is_neg )) => 𝛷 (^ (tanh (~ x), - ~ k))
98-
99- @rule 𝛷 (sin (~ x)) => (cos (~ x), ∂ (~ x))
100- @rule 𝛷 (cos (~ x)) => (sin (~ x), ∂ (~ x))
101- @rule 𝛷 (tan (~ x)) => (log (cos (~ x)), ∂ (~ x))
102- @rule 𝛷 (csc (~ x)) => (log (sin (~ x)^- 1 - cos (~ x)* sin (~ x)^- 1 ), ∂ (~ x))
103- @rule 𝛷 (sec (~ x)) => (log (cos (~ x)^- 1 + sin (~ x)* cos (~ x)^- 1 ), ∂ (~ x))
104- @rule 𝛷 (cot (~ x)) => (log (sin (~ x)), ∂ (~ x))
105-
106- @rule 𝛷 (sinh (~ x)) => (cosh (~ x), ∂ (~ x))
107- @rule 𝛷 (cosh (~ x)) => (sinh (~ x), ∂ (~ x))
108- @rule 𝛷 (tanh (~ x)) => (log (cosh (~ x)), ∂ (~ x))
109- @rule 𝛷 (csch (~ x)) => (log (sinh (~ x)^- 1 + cosh (~ x)* sinh (~ x)^- 1 ), ∂ (~ x))
110- @rule 𝛷 (sech (~ x)) => (log (cosh (~ x)^- 1 + sinh (~ x)* cosh (~ x)^- 1 ), ∂ (~ x))
111- @rule 𝛷 (coth (~ x)) => (log (sinh (~ x)), ∂ (~ x))
112-
113- @rule 𝛷 (asin (~ x)) => (~ x* asin (~ x) + sqrt (1 - ~ x* ~ x), ∂ (~ x))
114- @rule 𝛷 (acos (~ x)) => (~ x* acos (~ x) + sqrt (1 - ~ x* ~ x), ∂ (~ x))
115- @rule 𝛷 (atan (~ x)) => (~ x* atan (~ x) + log (~ x* ~ x + 1 ), ∂ (~ x))
116- @rule 𝛷 (acsc (~ x)) => (~ x* acsc (~ x) + acosh (~ x), ∂ (~ x)) # needs an abs inside acosh
117- @rule 𝛷 (asec (~ x)) => (~ x* asec (~ x) + acosh (~ x), ∂ (~ x)) # needs an abs inside acosh
118- @rule 𝛷 (acot (~ x)) => (~ x* acot (~ x) + log (~ x* ~ x + 1 ), ∂ (~ x))
119-
120- @rule 𝛷 (asinh (~ x)) => (~ x* asinh (~ x) + sqrt (~ x* ~ x + 1 ), ∂ (~ x))
121- @rule 𝛷 (acosh (~ x)) => (~ x* acosh (~ x) + sqrt (~ x* ~ x - 1 ), ∂ (~ x))
122- @rule 𝛷 (atanh (~ x)) => (~ x* atanh (~ x) + log (~ x + 1 ), ∂ (~ x))
123- @rule 𝛷 (acsch (~ x)) => (acsch (~ x), ∂ (~ x))
124- @rule 𝛷 (asech (~ x)) => (asech (~ x), ∂ (~ x))
125- @rule 𝛷 (acoth (~ x)) => (~ x* acot (~ x) + log (~ x + 1 ), ∂ (~ x))
126-
127- @rule 𝛷 (log (~ x)) => (~ x + ~ x * log (~ x), ∂ (~ x))
128-
129- @rule 𝛷 (^ (~ x, ~ k:: is_abs_half )) => (sum (candidate_sqrt (~ x,~ k); init= one (~ x)), 1 )
130- @rule 𝛷 (^ (~ x:: is_poly , ~ k:: is_neg )) => (sum (candidate_pow_minus (~ x, ~ k); init= one (~ x)), 1 )
131- @rule 𝛷 (sqrt (~ x)) => (sum (candidate_sqrt (~ x,0.5 ); init= one (~ x)), 1 )
132- @rule 𝛷 (^ (sqrt (~ x),- 1 )) => 𝛷 (^ (~ x,- 0.5 ))
133-
134- @rule 𝛷 (^ (~ x, - 1 )) => (log (~ x), ∂ (~ x))
135- @rule 𝛷 (1 / ~ x) => 𝛷 (^ (~ x, - 1 ))
136- @rule 𝛷 (^ (~ x, ~ k)) => (^ (~ x, ~ k+ 1 ), ∂ (~ x))
137-
138- @rule 𝛷 (exp (~ x)) => (exp (~ x), ∂ (~ x))
139- @rule 𝛷 (1 ) => (𝑥, 1 )
140- @rule 𝛷 (~ x) => ((~ x + ^ (~ x,2 )), ∂ (~ x))
141- ]
142-
143- apply_partial_int_rules (eq) = expand (Fixpoint (Prewalk (Chain (partial_int_rules))))(𝛷 (value (eq)))
90+ partial_int_rules = [@rule 𝛷 (^ (sin (~ x), ~ k:: is_neg )) => 𝛷 (^ (csc (~ x), - ~ k))
91+ @rule 𝛷 (^ (cos (~ x), ~ k:: is_neg )) => 𝛷 (^ (sec (~ x), - ~ k))
92+ @rule 𝛷 (^ (tan (~ x), ~ k:: is_neg )) => 𝛷 (^ (cot (~ x), - ~ k))
93+ @rule 𝛷 (^ (csc (~ x), ~ k:: is_neg )) => 𝛷 (^ (sin (~ x), - ~ k))
94+ @rule 𝛷 (^ (sec (~ x), ~ k:: is_neg )) => 𝛷 (^ (cos (~ x), - ~ k))
95+ @rule 𝛷 (^ (cot (~ x), ~ k:: is_neg )) => 𝛷 (^ (tan (~ x), - ~ k))
96+ @rule 𝛷 (^ (sinh (~ x), ~ k:: is_neg )) => 𝛷 (^ (csch (~ x), - ~ k))
97+ @rule 𝛷 (^ (cosh (~ x), ~ k:: is_neg )) => 𝛷 (^ (sech (~ x), - ~ k))
98+ @rule 𝛷 (^ (tanh (~ x), ~ k:: is_neg )) => 𝛷 (^ (coth (~ x), - ~ k))
99+ @rule 𝛷 (^ (csch (~ x), ~ k:: is_neg )) => 𝛷 (^ (sinh (~ x), - ~ k))
100+ @rule 𝛷 (^ (sech (~ x), ~ k:: is_neg )) => 𝛷 (^ (cosh (~ x), - ~ k))
101+ @rule 𝛷 (^ (coth (~ x), ~ k:: is_neg )) => 𝛷 (^ (tanh (~ x), - ~ k))
102+ @rule 𝛷 (sin (~ x)) => (cos (~ x), ∂ (~ x))
103+ @rule 𝛷 (cos (~ x)) => (sin (~ x), ∂ (~ x))
104+ @rule 𝛷 (tan (~ x)) => (log (cos (~ x)), ∂ (~ x))
105+ @rule 𝛷 (csc (~ x)) => (log (sin (~ x)^- 1 - cos (~ x) * sin (~ x)^- 1 ), ∂ (~ x))
106+ @rule 𝛷 (sec (~ x)) => (log (cos (~ x)^- 1 + sin (~ x) * cos (~ x)^- 1 ), ∂ (~ x))
107+ @rule 𝛷 (cot (~ x)) => (log (sin (~ x)), ∂ (~ x))
108+ @rule 𝛷 (sinh (~ x)) => (cosh (~ x), ∂ (~ x))
109+ @rule 𝛷 (cosh (~ x)) => (sinh (~ x), ∂ (~ x))
110+ @rule 𝛷 (tanh (~ x)) => (log (cosh (~ x)), ∂ (~ x))
111+ @rule 𝛷 (csch (~ x)) => (log (sinh (~ x)^- 1 + cosh (~ x) * sinh (~ x)^- 1 ), ∂ (~ x))
112+ @rule 𝛷 (sech (~ x)) => (log (cosh (~ x)^- 1 + sinh (~ x) * cosh (~ x)^- 1 ), ∂ (~ x))
113+ @rule 𝛷 (coth (~ x)) => (log (sinh (~ x)), ∂ (~ x))
114+ @rule 𝛷 (asin (~ x)) => (~ x * asin (~ x) + sqrt (1 - ~ x * ~ x), ∂ (~ x))
115+ @rule 𝛷 (acos (~ x)) => (~ x * acos (~ x) + sqrt (1 - ~ x * ~ x), ∂ (~ x))
116+ @rule 𝛷 (atan (~ x)) => (~ x * atan (~ x) + log (~ x * ~ x + 1 ), ∂ (~ x))
117+ @rule 𝛷 (acsc (~ x)) => (~ x * acsc (~ x) + acosh (~ x), ∂ (~ x)) # needs an abs inside acosh
118+ @rule 𝛷 (asec (~ x)) => (~ x * asec (~ x) + acosh (~ x), ∂ (~ x)) # needs an abs inside acosh
119+ @rule 𝛷 (acot (~ x)) => (~ x * acot (~ x) + log (~ x * ~ x + 1 ), ∂ (~ x))
120+ @rule 𝛷 (asinh (~ x)) => (~ x * asinh (~ x) + sqrt (~ x * ~ x + 1 ), ∂ (~ x))
121+ @rule 𝛷 (acosh (~ x)) => (~ x * acosh (~ x) + sqrt (~ x * ~ x - 1 ), ∂ (~ x))
122+ @rule 𝛷 (atanh (~ x)) => (~ x * atanh (~ x) + log (~ x + 1 ), ∂ (~ x))
123+ @rule 𝛷 (acsch (~ x)) => (acsch (~ x), ∂ (~ x))
124+ @rule 𝛷 (asech (~ x)) => (asech (~ x), ∂ (~ x))
125+ @rule 𝛷 (acoth (~ x)) => (~ x * acot (~ x) + log (~ x + 1 ), ∂ (~ x))
126+ @rule 𝛷 (log (~ x)) => (~ x + ~ x * log (~ x), ∂ (~ x))
127+ @rule 𝛷 (^ (~ x, ~ k:: is_abs_half )) => (sum (candidate_sqrt (~ x, ~ k);
128+ init = one (~ x)), 1 );
129+ @rule 𝛷 (^ (~ x:: is_poly , ~ k:: is_neg )) => (sum (candidate_pow_minus (~ x,
130+ ~ k);
131+ init = one (~ x)), 1 )
132+ @rule 𝛷 (sqrt (~ x)) => (sum (candidate_sqrt (~ x, 0.5 ); init = one (~ x)), 1 );
133+ @rule 𝛷 (^ (sqrt (~ x), - 1 )) => 𝛷 (^ (~ x, - 0.5 ))
134+ @rule 𝛷 (^ (~ x, - 1 )) => (log (~ x), ∂ (~ x))
135+ @rule 𝛷 (1 / ~ x) => 𝛷 (^ (~ x, - 1 ))
136+ @rule 𝛷 (^ (~ x, ~ k)) => (^ (~ x, ~ k + 1 ), ∂ (~ x))
137+ @rule 𝛷 (exp (~ x)) => (exp (~ x), ∂ (~ x))
138+ @rule 𝛷 (1 ) => (𝑥, 1 )
139+ @rule 𝛷 (~ x) => ((~ x + ^ (~ x, 2 )), ∂ (~ x))]
140+
141+ function apply_partial_int_rules (eq)
142+ expand (Fixpoint (Prewalk (Chain (partial_int_rules))))(𝛷 (value (eq)))
143+ end
0 commit comments