5757
5858# #############################################################################
5959
60+ Symbolics. @register_symbolic Ei (z)
61+ Symbolics. @register_symbolic Si (z)
62+ Symbolics. @register_symbolic Ci (z)
63+ Symbolics. @register_symbolic Li (z)
64+
65+ Symbolics. derivative (:: typeof (Ei), args:: NTuple{1, Any} , :: Val{1} ) = exp (args[1 ]) / args[1 ]
66+ Symbolics. derivative (:: typeof (Si), args:: NTuple{1, Any} , :: Val{1} ) = sin (args[1 ]) / args[1 ]
67+ Symbolics. derivative (:: typeof (Ci), args:: NTuple{1, Any} , :: Val{1} ) = cos (args[1 ]) / args[1 ]
68+ Symbolics. derivative (:: typeof (Li), args:: NTuple{1, Any} , :: Val{1} ) = 1 / log (args[1 ])
69+
70+ @syms si (𝑥) ci (𝑥) ei (𝑥) li (𝑥)
71+
72+ # #############################################################################
73+
6074function substitute_x (eq, x, sub)
6175 eq = substitute (eq, sub)
6276 substitute (eq, Dict (𝑥 => x))
6377end
6478
6579function generate_homotopy (eq, x)
6680 eq = eq isa Num ? eq. val : eq
81+ x = x isa Num ? x. val : x
82+
6783 q, sub = transform (eq, x)
6884 S = 0
6985
7086 for i in 1 : length (sub)
7187 μ = u[i]
7288 h₁, ∂h₁ = apply_partial_int_rules (sub[μ])
89+ h₁ = substitute (h₁, Dict (si => Si, ci => Ci, ei => Ei, li => Li))
7390 h₂ = expand_derivatives (Differential (μ)(q))
7491
7592 h₁ = substitute_x (h₁, x, sub)
7693 h₂ = substitute_x (h₂ * ∂h₁^- 1 , x, sub)
7794
7895 S += expand ((1 + h₁) * (1 + h₂))
7996 end
80-
81- S = simplify (S)
8297
8398 unique ([one (x); [equivalent (t, x) for t in terms (S)]])
8499end
@@ -91,9 +106,9 @@ function ∂(x)
91106end
92107
93108partial_int_rules = [
94- # trigonometric functions
95- @rule 𝛷 (sin (~ x)) => (cos (~ x), ∂ (~ x))
96- @rule 𝛷 (cos (~ x)) => (sin (~ x), ∂ (~ x))
109+ # trigonometric functions
110+ @rule 𝛷 (sin (~ x)) => (cos ( ~ x) + si (~ x), ∂ (~ x))
111+ @rule 𝛷 (cos (~ x)) => (sin (~ x) + ci ( ~ x) , ∂ (~ x))
97112 @rule 𝛷 (tan (~ x)) => (log (cos (~ x)), ∂ (~ x))
98113 @rule 𝛷 (csc (~ x)) => (log (csc (~ x) + cot (~ x)), ∂ (~ x))
99114 @rule 𝛷 (sec (~ x)) => (log (sec (~ x) + tan (~ x)), ∂ (~ x))
@@ -119,12 +134,12 @@ partial_int_rules = [
119134 @rule 𝛷 (^ (csch (~ x), - 1 )) => (cosh (~ x), ∂ (~ x))
120135 @rule 𝛷 (^ (sech (~ x), - 1 )) => (sinh (~ x), ∂ (~ x))
121136 @rule 𝛷 (^ (coth (~ x), - 1 )) => (log (cosh (~ x)), ∂ (~ x))
122- # inverse trigonometric functions
137+ # inverse trigonometric functions
123138 @rule 𝛷 (asin (~ x)) => (~ x * asin (~ x) + sqrt (1 - ~ x * ~ x), ∂ (~ x))
124139 @rule 𝛷 (acos (~ x)) => (~ x * acos (~ x) + sqrt (1 - ~ x * ~ x), ∂ (~ x))
125140 @rule 𝛷 (atan (~ x)) => (~ x * atan (~ x) + log (~ x * ~ x + 1 ), ∂ (~ x))
126- @rule 𝛷 (acsc (~ x)) => (~ x * acsc (~ x) + atanh (1 - ^ (~ x,- 2 )), ∂ (~ x))
127- @rule 𝛷 (asec (~ x)) => (~ x * asec (~ x) + acosh (~ x), ∂ (~ x))
141+ @rule 𝛷 (acsc (~ x)) => (~ x * acsc (~ x) + atanh (1 - ^ (~ x, - 2 )), ∂ (~ x))
142+ @rule 𝛷 (asec (~ x)) => (~ x * asec (~ x) + acosh (~ x), ∂ (~ x))
128143 @rule 𝛷 (acot (~ x)) => (~ x * acot (~ x) + log (~ x * ~ x + 1 ), ∂ (~ x))
129144 # inverse hyperbolic functions
130145 @rule 𝛷 (asinh (~ x)) => (~ x * asinh (~ x) + sqrt (~ x * ~ x + 1 ), ∂ (~ x))
@@ -134,19 +149,26 @@ partial_int_rules = [
134149 @rule 𝛷 (asech (~ x)) => (asech (~ x), ∂ (~ x))
135150 @rule 𝛷 (acoth (~ x)) => (~ x * acot (~ x) + log (~ x + 1 ), ∂ (~ x))
136151 # logarithmic and exponential functions
137- @rule 𝛷 (log (~ x)) => (~ x + ~ x * log (~ x) + sum (candidate_pow_minus (~ x, - 1 ); init = one (~ x)), ∂ (~ x))
138- @rule 𝛷 (exp (~ x)) => (exp (~ x), ∂ (~ x))
152+ @rule 𝛷 (log (~ x)) => (~ x + ~ x * log (~ x) +
153+ sum (candidate_pow_minus (~ x, - 1 ); init = one (~ x)),
154+ ∂ (~ x))
155+ @rule 𝛷 (^ (log (~ x), - 1 )) => (log (log (~ x)) + li (~ x), ∂ (~ x))
156+ @rule 𝛷 (exp (~ x)) => (exp (~ x) + ei (~ x), ∂ (~ x))
139157 @rule 𝛷 (^ (exp (~ x), ~ k:: is_neg )) => (^ (exp (- ~ x), - ~ k), ∂ (~ x))
140158 # square-root functions
141- @rule 𝛷 (^ (~ x, ~ k:: is_abs_half )) => (sum (candidate_sqrt (~ x, ~ k); init = one (~ x)), 1 );
159+ @rule 𝛷 (^ (~ x, ~ k:: is_abs_half )) => (sum (candidate_sqrt (~ x, ~ k);
160+ init = one (~ x)), 1 );
142161 @rule 𝛷 (sqrt (~ x)) => (sum (candidate_sqrt (~ x, 0.5 ); init = one (~ x)), 1 );
143- @rule 𝛷 (^ (sqrt (~ x), - 1 )) => 𝛷 (^ (~ x, - 0.5 ))
144- # rational functions
145- @rule 𝛷 (^ (~ x:: is_poly , ~ k:: is_neg )) => (sum (candidate_pow_minus (~ x, ~ k); init = one (~ x)), 1 )
162+ @rule 𝛷 (^ (sqrt (~ x), - 1 )) => 𝛷 (^ (~ x, - 0.5 ))
163+ # rational functions
164+ @rule 𝛷 (^ (~ x:: is_poly , ~ k:: is_neg )) => (sum (candidate_pow_minus (~ x,
165+ ~ k);
166+ init = one (~ x)), 1 )
146167 @rule 𝛷 (^ (~ x, - 1 )) => (log (~ x), ∂ (~ x))
147- @rule 𝛷 (^ (~ x, ~ k:: is_neg_int )) => (sum (^ (~ x, i) for i in (~ k + 1 ): - 1 ), ∂ (~ x))
168+ @rule 𝛷 (^ (~ x, ~ k:: is_neg_int )) => (sum (^ (~ x, i) for i in (~ k + 1 ): - 1 ),
169+ ∂ (~ x))
148170 @rule 𝛷 (1 / ~ x) => 𝛷 (^ (~ x, - 1 ))
149- @rule 𝛷 (^ (~ x, ~ k)) => (^ (~ x, ~ k + 1 ), ∂ (~ x))
171+ @rule 𝛷 (^ (~ x, ~ k)) => (^ (~ x, ~ k + 1 ), ∂ (~ x))
150172 @rule 𝛷 (1 ) => (𝑥, 1 )
151173 @rule 𝛷 (~ x) => ((~ x + ^ (~ x, 2 )), ∂ (~ x))]
152174
0 commit comments