Skip to content

Commit

Permalink
Improve simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Nov 21, 2018
1 parent 8fa7ed6 commit ceb71b9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 73 deletions.
38 changes: 38 additions & 0 deletions expreduce/builtin_expression.go
Expand Up @@ -45,6 +45,35 @@ func leafCount(e expreduceapi.Ex) int64 {
return 1
}

func leafCountSimplify(e expreduceapi.Ex) int64 {
if asExpr, isExpr := e.(expreduceapi.ExpressionInterface); isExpr {
res := int64(0)
for _, part := range asExpr.GetParts() {
res += leafCountSimplify(part)
}
return res
}
if asInt, isInt := e.(*atoms.Integer); isInt {
if asInt.Val.Sign() == -1 {
return 2
}
}
if asCmplx, isCmplx := e.(*atoms.Complex); isCmplx {
return leafCountSimplify(asCmplx.Im) + leafCountSimplify(asCmplx.Re) + 1
}
if asRat, isRat := e.(*atoms.Rational); isRat {
val := int64(3)
if asRat.Num.Sign() == -1 {
val++
}
if asRat.Den.Sign() == -1 {
val++
}
return val
}
return 1
}

func getExpressionDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Head",
Expand Down Expand Up @@ -160,6 +189,15 @@ func getExpressionDefinitions() (defs []Definition) {
return atoms.NewInt(leafCount(this.GetParts()[1]))
},
})
defs = append(defs, Definition{
Name: "ExpreduceLeafCountSimplify",
legacyEvalFn: func(this expreduceapi.ExpressionInterface, es expreduceapi.EvalStateInterface) expreduceapi.Ex {
if len(this.GetParts()) != 2 {
return this
}
return atoms.NewInt(leafCountSimplify(this.GetParts()[1]))
},
})
defs = append(defs, Definition{
Name: "Flat",
OmitDocumentation: true,
Expand Down
4 changes: 2 additions & 2 deletions expreduce/resources.go
Git LFS file not shown
1 change: 1 addition & 0 deletions expreduce/resources/manip.m
Expand Up @@ -61,6 +61,7 @@
ESameTest[(a+b+c+d)/((a+b) (c+d)), (1+a/(c+d)+b/(c+d))/(a+b)//Together],
ESameTest[(a+b+a b c+a b d)/(a b), 1/a+1/b+c+d//Together],
ESameTest[2(a+b), 2a+2b//Together],
], EKnownFailures[
ESameTest[(I (a-b))/(2 Subscript[\[Omega], 0]), (I a)/(2 Subscript[\[Omega], 0])-(I b)/(2 Subscript[\[Omega], 0])//Together],
]
};
Expand Down
4 changes: 3 additions & 1 deletion expreduce/resources/power.m
Expand Up @@ -68,7 +68,9 @@
1, I,
2, -1,
3, -I];
Complex[re_,im_]^n_Integer := Module[{theta = ArcTan[re,im]}, Sqrt[re^2+im^2]^n*Complex[Cos[n*theta],Sin[n*theta]]];
Complex[re_,im_]^n_Integer := If[n===-1,
Complex[re/(re^2+im^2), -(im/(re^2+im^2))],
Module[{theta = ArcTan[re,im]}, Sqrt[re^2+im^2]^n*Complex[Cos[n*theta],Sin[n*theta]]]];
Complex[re_,im_]^n_Real := Module[{theta = ArcTan[re,im]}, Sqrt[re^2+im^2]^n*Complex[Cos[n*theta],Sin[n*theta]]];
Power[ComplexInfinity+_, -1] := 0;
_^ComplexInfinity := Indeterminate;
Expand Down
26 changes: 22 additions & 4 deletions expreduce/resources/simplify.m
Expand Up @@ -35,25 +35,43 @@
And[x1___, a_, x2___, Or[x3___, !a_, x4___], x5___] :> And[a, x1, x2, Or[x3, x4], x5],
And[x1___, Or[x2___, !a_, x3___], x4___, a_, x5___] :> And[a, x1, Or[x2, x3], x4, x5]
};
trigSimplify[exp_] := exp //. {
(Rational[1,2]*c_.*(a_ + b_*Cos[inner_]) /; a == -b) :> c*a*Sin[inner/2]^2
};
tryFactoringOutTerm[e_] := e;
tryFactoringOutTerm[p_Plus] := Module[{cterms, simplest, i, tryVal},
simplest = p;
cterms = ((ExpreduceConstantTerm /@ (List @@ p)) // Transpose)[[1]];
For[i = 1, i <= Length[cterms], i++,
tryVal = cterms[[i]] (p/cterms[[i]] // Distribute);
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[simplest],
simplest = tryVal];
];
simplest
];
simplifyInner[exp_] := Module[{e = exp, tryVal},
e = booleanSimplify[e];
e = trigSimplify[e];
inferredPower = 1;
If[MatchQ[e, s_Plus^n_Integer],
inferredPower := Replace[e, s_Plus^n_Integer -> n]];
If[inferredPower < 5,
(*Similar to Expand, but not using ReplaceAll*)
tryVal = FixedPoint[Replace[#, expandRules]&, e];
If[LeafCount[tryVal] < LeafCount[e], e = tryVal];
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[e], e = tryVal];
];
(*Avoid expressions containing expensive expressions to expand.*)
If[FreeQ[e, a_Plus^(b_Integer?((# >= 5) &))],
tryVal = ComplexExpand[e];
If[LeafCount[tryVal] < LeafCount[e], e = tryVal];
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[e], e = tryVal];
];
tryVal = Together[e];
If[LeafCount[tryVal] < LeafCount[e], e = tryVal];
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[e], e = tryVal];
tryVal = Private`myFactorCommonTerms[e];
If[LeafCount[tryVal] < LeafCount[e], e = tryVal];
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[e], e = tryVal];
tryVal = Private`tryFactoringOutTerm[e];
If[ExpreduceLeafCountSimplify[tryVal] < ExpreduceLeafCountSimplify[e], e = tryVal];
e = trigSimplify[e];
(* also need to try complexexpand to simplify cases like (-1)^(1/3) (1 + I Sqrt[3]) *)
e = Replace[e, Sqrt[inner_] :> Sqrt[FactorTerms[inner]]];
e
Expand Down
100 changes: 50 additions & 50 deletions expreduce/resources/solve.m
@@ -1,14 +1,14 @@
Solve::usage = "`Solve[eqn, var]` solves `eqn` for `var`.";

countVar[expr_, var_Symbol] :=
countVar[expr_, var_Symbol] :=
If[expr === var, 1, Count[expr, var, -1]];

containsOneOccurrence[eqn_Equal, var_Symbol] :=
containsOneOccurrence[eqn_Equal, var_Symbol] :=
Count[eqn, var, -1] == 1;
containsZeroOccurrences[eqn_Equal, var_Symbol] :=
containsZeroOccurrences[eqn_Equal, var_Symbol] :=
Count[eqn, var, -1] == 0;

checkedConditionalExpression[e_, c_] :=
checkedConditionalExpression[e_, c_] :=
Module[{nextC = 1, res, reps, newC = -1},
While[True, If[Count[e, C[nextC], -1] > 0, nextC++, Break[]]];
res = ConditionalExpression[e, c];
Expand Down Expand Up @@ -58,7 +58,7 @@
},
E, If[MatchQ[rhs, _Real],
{pow -> Log[rhs]},
{pow -> ConditionalExpression[2 I Pi C[1] + Log[rhs],
{pow -> ConditionalExpression[2 I Pi C[1] + Log[rhs],
C[1] \[Element] Integers]},
],
_, Message[Solve::ifun, Solve];{pow -> Log[rhs]/Log[base]}
Expand All @@ -76,38 +76,38 @@
{lhs->checkedConditionalExpression[-ArcCos[rhs]+2 Pi C[-1],C[-1]\[Element]Integers],
lhs->checkedConditionalExpression[ArcCos[rhs]+2 Pi C[-1],C[-1]\[Element]Integers]};
applyInverse[Tan[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[ArcTan[rhs] + Pi C[1],
{lhs -> ConditionalExpression[ArcTan[rhs] + Pi C[1],
C[1] \[Element] Integers]};
applyInverse[Cot[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[ArcCot[rhs] + Pi C[1],
{lhs -> ConditionalExpression[ArcCot[rhs] + Pi C[1],
C[1] \[Element] Integers]};
applyInverse[Sec[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[-ArcCos[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcCos[1/rhs] + 2 Pi C[1],
{lhs -> ConditionalExpression[-ArcCos[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcCos[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers]};
applyInverse[Csc[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[Pi - ArcSin[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcSin[1/rhs] + 2 Pi C[1],
{lhs -> ConditionalExpression[Pi - ArcSin[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcSin[1/rhs] + 2 Pi C[1],
C[1] \[Element] Integers]};
(* Inverses for inverse trig functions *)
applyInverse[ArcSin[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[
Sin[rhs], (Re[rhs] == -(Pi/2) && Im[rhs] >= 0) || -(Pi/2) <
Sin[rhs], (Re[rhs] == -(Pi/2) && Im[rhs] >= 0) || -(Pi/2) <
Re[rhs] < Pi/2 || (Re[rhs] == Pi/2 && Im[rhs] <= 0)]};
applyInverse[ArcCos[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[
Cos[rhs], (Re[rhs] == 0 && Im[rhs] >= 0) ||
Cos[rhs], (Re[rhs] == 0 && Im[rhs] >= 0) ||
0 < Re[rhs] < Pi || (Re[rhs] == Pi && Im[rhs] <= 0)]};
applyInverse[ArcTan[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[
Tan[rhs], (Re[rhs] == -(Pi/2) && Im[rhs] < 0) || -(Pi/2) <
Tan[rhs], (Re[rhs] == -(Pi/2) && Im[rhs] < 0) || -(Pi/2) <
Re[rhs] < Pi/2 || (Re[rhs] == Pi/2 && Im[rhs] > 0)]};
applyInverse[Cosh[lhs_] -> rhs_, var_Symbol] :=
{lhs -> ConditionalExpression[-ArcCosh[rhs] + 2 I \[Pi] C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcCosh[rhs] + 2 I \[Pi] C[1],
{lhs -> ConditionalExpression[-ArcCosh[rhs] + 2 I \[Pi] C[1],
C[1] \[Element] Integers], lhs ->
ConditionalExpression[ArcCosh[rhs] + 2 I \[Pi] C[1],
C[1] \[Element] Integers]}

(* Base case: *)
Expand All @@ -116,7 +116,7 @@
isolate[lhs_ -> rhs_, var_Symbol] := Module[{inverseApplied},
(* Switch sides if needed to get var on LHS: *)

If[(countVar[rhs, var] === 1) && (countVar[lhs, var] === 0),
If[(countVar[rhs, var] === 1) && (countVar[lhs, var] === 0),
Return[isolate[rhs -> lhs, var]]];

(* Assert var occurs only once in the LHS: *)
Expand All @@ -125,8 +125,8 @@
Return[$Failed]];

inverseApplied = applyInverse[lhs -> rhs, var];
If[Head[inverseApplied] =!= List,
Print["Solve error: Finding inverse failed for ", lhs -> rhs,
If[Head[inverseApplied] =!= List,
Print["Solve error: Finding inverse failed for ", lhs -> rhs,
", var: ", var]; Return[SolveFailed]];

allIsolated = isolate[#, var]& /@ inverseApplied;
Expand Down Expand Up @@ -187,67 +187,67 @@
{{x->0},{x->0},{x->0},{x->-(d/e)}}/;FreeQ[{d,e},x];

(* Solve using u-substitution for polynomial-like forms.*)
uSubstitute::usage =
uSubstitute::usage =
"uSubstitute[eqn, var] takes a non-polynomial `eqn` and attempts a \
u-substitution such that `eqn` takes a polynomial form. If the \
substitution succeeds, the function returns `{transformed, uValue}`. \
The `transformed` equation will include the `uPlaceholder` symbol as \
the u symbol. The function returns an error symbol if the \
substitution fails to produce a polynomial form.";
uSubstitute[theEqn_, theVar_Symbol] :=
Module[{eqn = theEqn, var = theVar, expGcd, uValue, transformed,
uSubstitute[theEqn_, theVar_Symbol] :=
Module[{eqn = theEqn, var = theVar, expGcd, uValue, transformed,
exponents},
(* Attempt to extract exponents of polynomial-like equations.
(* Attempt to extract exponents of polynomial-like equations.
We wish to ignore any zero-valued exponents. *)

exponents = DeleteCases[Exponent[eqn, var, List], 0];
If[Length[exponents] === 0, Return[$Failed]];
(* Find the signed GCD of the exponents.
This seems to work for many of the problem cases,
(* Find the signed GCD of the exponents.
This seems to work for many of the problem cases,
but may not yield a useful polynomial form for all equations. *)

expGcd = GCD @@ exponents*Sign[exponents[[1]]];
uValue = var^expGcd;
(* Rewrite the variable with our u-value. *)
transformed =

transformed =
eqn /. var -> uPlaceholder^(1/expGcd) // PowerExpand;
(* If our transformed equation is polynomial, we have succeeded. *)

If[PolynomialQ[transformed, var], {transformed, uValue}, $Failed]
];

uSubstitutionSolve::usage =
uSubstitutionSolve::usage =
"uSubstitutionSolve[eqn, var] takes a non-polynomial `eqn` and \
attempts a u-substitution such that `eqn` takes a polynomial form in \
order to solve the equation. The function returns the solve result or \
`$Failed` in case of an issue.";
uSubstitutionSolve[theEqn_, theVar_Symbol] :=
uSubstitutionSolve[theEqn_, theVar_Symbol] :=
Module[{eqn = theEqn, var = theVar, transformed, uSolved, solved},
transformed = uSubstitute[eqn, var];
(* If the u-
substitution fails to produce a polynomial form and instead \
returns an error symbol, fail this solution attempt. *)

If[Head[transformed] =!= List, Return[$Failed]];
(* Find the roots of the equation that was transformed into a \
polynomial form. *)

uSolved = Solve[transformed[[1]] == 0, uPlaceholder];
(* For each of the roots, solve for the original variable. *)
If[Head[uSolved] =!= List, Return[$Failed]];
solved =

solved =
Map[Solve[transformed[[2]] == #[[1, 2]], var] &, uSolved];
(* There may be some roots that have no solution for the original \
variable. Throw these out. *)

solved = Select[solved, (Length[#] >= 1) &];
(* No way to handle multiple solutions yet. *)

If[AnyTrue[solved, (Length[#] != 1) &], Return[$Failed]];
(* Collect the unique solutions of eqn and return. *)

Map[First, solved] // DeleteDuplicates // Sort
];

Expand Down Expand Up @@ -285,7 +285,7 @@
Print["Solve found no solutions for ", eqn, " for ", var];
SolveFailed
];
solveMultOrdered[eqns_List, vars_List] :=
solveMultOrdered[eqns_List, vars_List] :=
Module[{firstSol, secondSol, toSolve},
If[Length[eqns] =!= 2 || Length[vars] =!= 2, Return[SolveFailed]];
firstSol = Solve[eqns[[1]], vars[[1]]];
Expand Down Expand Up @@ -318,9 +318,9 @@
Solve[{a_.*x_Symbol+b_.*y_Symbol==c_,d_.*x_Symbol==f_},{x_Symbol,y_Symbol}] := {{x->f/d,y->-((-c d+a f)/(b d))}}/;FreeQ[{a,b,c,d,f},x]&&FreeQ[{a,b,c,d,f},y]

Attributes[Solve] = {Protected};
normSol[s_List] :=
Sort[(# /.
ConditionalExpression[e_, a_And] :>
normSol[s_List] :=
Sort[(# /.
ConditionalExpression[e_, a_And] :>
ConditionalExpression[e, a // Sort]) & /@ s];
Tests`Solve = {
ESimpleExamples[
Expand Down Expand Up @@ -360,8 +360,8 @@
ESameTest[{}, Solve[E^x==0,x]],
ESameTest[{{x->ConditionalExpression[2 I Pi C[1],C[1]\[Element]Integers]}}, Solve[E^x==1,x]],
(*ESameTest[{{x->2.4663 Log[y]}}, Solve[1.5^x==y,x]],*)
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1])/Log[3]+Log[y]/Log[3],C[1]\[Element]Integers]}}, Solve[3^x == y, x]],
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1])/Log[2]+Log[y]/Log[2],C[1]\[Element]Integers]}}, Solve[2^x == y, x]],
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1])/Log[3]+Log[y]/Log[3],C[1]\[Element]Integers]}}//Simplify, Solve[3^x == y, x]],
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1])/Log[2]+Log[y]/Log[2],C[1]\[Element]Integers]}}//Simplify, Solve[2^x == y, x]],
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1]+Log[y])/(I Pi+Log[2]),C[1]\[Element]Integers]}}, Solve[(-2)^x == y, x]],
ESameTest[{{x->ConditionalExpression[(2 I Pi C[1]+Log[y])/(I Pi+Log[3]),C[1]\[Element]Integers]}}, Solve[(-3)^x == y, x]],
(* Inverse of log *)
Expand Down Expand Up @@ -430,11 +430,11 @@
ESameTest[{{x -> 0}, {x -> 1}}, Solve[4*x*(1 + -x^(1/2)) == 0, x]],
ESameTest[{{x -> (a^(-1)*y)^(b^(-1))}}, Solve[a*x^b + -y == 0, x]],
ESameTest[{{x -> 0}, {x -> a^(-2)}}, Solve[4*x*(1 + -a*x^(1/2)) == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 1*I)*Pi + (0 + 2*I)*Pi*C[1], Element[C[1], Integers]]}}, Solve[1 + E^x == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 1*I)*Pi + (0 + 2*I)*Pi*C[1], Element[C[1], Integers]]}}//Simplify, Solve[1 + E^x == 0, x]],
ESameTest[{{x -> y^3}}, Solve[y^(-2)*(1 + -y^2)^(-1/2)*(x + -y^3) == 0, x]],
ESameTest[{{x -> y^3}}, Solve[y^(-2)*(1 + -y^2)^(-1/2)*(x + -y^3) == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 2*I)*Pi*C[1]*Log[3]^(-1) + Log[3]^(-1)*Log[10], Element[C[1], Integers]]}}, Solve[-10 + 3^x == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 2*I)*Pi*C[1]*Log[3]^(-1) + Log[3]^(-1)*Log[10], Element[C[1], Integers]]}}, Solve[10 + -3^x == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 2*I)*Pi*C[1]*Log[3]^(-1) + Log[3]^(-1)*Log[10], Element[C[1], Integers]]}}//Simplify, Solve[-10 + 3^x == 0, x]],
ESameTest[{{x -> ConditionalExpression[(0 + 2*I)*Pi*C[1]*Log[3]^(-1) + Log[3]^(-1)*Log[10], Element[C[1], Integers]]}}//Simplify, Solve[10 + -3^x == 0, x]],
ESameTest[{{y -> x^(1/3)}, {y -> -(-1)^(1/3)*x^(1/3)}, {y -> (-1)^(2/3)*x^(1/3)}}, Solve[x + -y^3 == 0, y]],
ESameTest[{{x -> ConditionalExpression[-ArcCos[(1/2)*y] + 2*Pi*C[1], Element[C[1], Integers]]}, {x -> ConditionalExpression[ArcCos[(1/2)*y] + 2*Pi*C[1], Element[C[1], Integers]]}}, Solve[-y + 2*Cos[x] == 0, x]],
ESameTest[{{x -> -(1 + -a^(1/2))^(1/2)}, {x -> (1 + -a^(1/2))^(1/2)}, {x -> -(1 + a^(1/2))^(1/2)}, {x -> (1 + a^(1/2))^(1/2)}}, Solve[-a + (-1 + x^2)^2 == 0, x]],
Expand Down
16 changes: 0 additions & 16 deletions expreduce/resources/tests.m
Expand Up @@ -47,24 +47,8 @@
ESameTest[1/2-1/4 E^(-2 I t)-1/4 E^(2 I t), TrigToExp[Sin[t]^2]],
ESameTest[-(I/2), 1/(2\[ImaginaryJ])//FullSimplify],
ESameTest[I/2, -1/(2\[ImaginaryJ])//FullSimplify],
ESameTest[1/2 (-1)^(1/4), (1/2)E^((I Pi)/4)//FullSimplify],
ESameTest[-((I A (1-E^(-(1/2) I k Subscript[T, 0] Subscript[\[Omega], 0])))/(k Subscript[T, 0] Subscript[\[Omega], 0])), 1/Subscript[T, 0]*Integrate[A*E^(-I*k*Subscript[\[Omega], 0]t),{t,0,Subscript[T, 0]/2}]],
ESameTest[A/2, 1/Subscript[T, 0]*Integrate[A*E^(-I*k*Subscript[\[Omega], 0]t)/.k->0,{t,0,Subscript[T, 0]/2}]],
ESameTest[-((I A (-1+E^(I Subscript[T, 0] Subscript[\[Omega], 0])))/(2 Subscript[T, 0] Subscript[\[Omega], 0])), 1/Subscript[T, 0]*Integrate[A*E^(-I*k*Subscript[\[Omega], 0]t)/.k->-2,{t,0,Subscript[T, 0]/2}]],
ESameTest[-((I A (1-E^(-(1/2) I k Subscript[T, 0] Subscript[\[Omega], 0])))/(k Subscript[T, 0] Subscript[\[Omega], 0])), 1/Subscript[T, 0]*A*Integrate[E^(-I*k*Subscript[\[Omega], 0]t),{t,0,Subscript[T, 0]/2}]],
ESameTest[-((I (1-E^(-(1/2) I k Subscript[T, 0] Subscript[\[Omega], 0])))/(k Subscript[\[Omega], 0])), Integrate[E^(-I*k*Subscript[\[Omega], 0]t),{t,0,Subscript[T, 0]/2}]],
ESameTest[(I (-1+Cos[k Pi])+Sin[k Pi])/(k Subscript[\[Omega], 0]), -((I (1-E^(-(1/2) I k *2Pi)))/(k Subscript[\[Omega], 0]))//FullSimplify],
ESameTest[A/2-(I A E^(I t Subscript[\[Omega], 0]) (1-E^(-(1/2) I Subscript[T, 0] Subscript[\[Omega], 0])))/(Subscript[T, 0] Subscript[\[Omega], 0])-(I A E^(-I t Subscript[\[Omega], 0]) (-1+E^(1/2 I Subscript[T, 0] Subscript[\[Omega], 0])))/(Subscript[T, 0] Subscript[\[Omega], 0]), Sum[1/Subscript[T, 0]*Integrate[A*E^(-I*k*Subscript[\[Omega], 0]t)/.k->thek,{t,0,Subscript[T, 0]/2}]*E^(I*thek*Subscript[\[Omega], 0]t),{thek,-1,1}]],
ESameTest[Cos[(2 k Pi t)/Subscript[T, 0]]-I Sin[(2 k Pi t)/Subscript[T, 0]], ExpToTrig[E^(-I*k*((2Pi)/Subscript[T, 0])*t)]],
ESameTest[(Sin[k Pi] Subscript[T, 0])/(2 k Pi), Integrate[Cos[(2Pi*k*t)/Subscript[T, 0]],{t,0,Subscript[T, 0]/2}]],
ESameTest[(I Sin[(k Pi)/2]^2 Subscript[T, 0])/(k Pi), Integrate[I*Sin[(2Pi*k*t)/Subscript[T, 0]],{t,0,Subscript[T, 0]/2}]],
ESameTest[(I (-A+A Cos[k Pi]-I A Sin[k Pi]))/(2 k Pi), A/Subscript[T, 0]*((Sin[k Pi] Subscript[T, 0])/(2 k Pi)-(I Sin[(k Pi)/2]^2 Subscript[T, 0])/(k Pi))//FullSimplify//TrigReduce],
ESameTest[Cos[k t Subscript[\[Omega], 0]]+I Sin[k t Subscript[\[Omega], 0]], ExpToTrig[E^(I*k*Subscript[\[Omega], 0]*t)]],
ESameTest[(I (Cos[(k Pi)/3]-Cos[(2 k Pi)/3]))/(k Pi), ak=1/6*(Integrate[E^(-I*k*(2Pi)/6 t),{t,-2,-1}]+Integrate[-1*E^(-I*k*(2Pi)/6 t),{t,1,2}])//FullSimplify],
ESameTest[0, a0=1/6*(Integrate[1,{t,-2,-1}]+Integrate[-1,{t,1,2}])//FullSimplify],
ESameTest[E^(-I k Pi t) x[t], 1/2 Integrate[x[t]*E^(-I*k*Pi*t),{x,-3/2,1/2}]],
ESameTest[-((I A E^(-I k Pi+(2 I k Pi t)/Subscript[T, 0]) (-1+E^(I k Pi)))/(2 k Pi)), 1/Subscript[T, 0]*Integrate[A*E^(-I*k*((2Pi)/Subscript[T, 0])*t),{t,0,Subscript[T, 0]/2}]*E^(I*k*((2Pi)/Subscript[T, 0])t)],
ESameTest[1/2, 1/10*Integrate[1*E^(-I*0*((2Pi)/10)*t),{t,0,10/2}]*E^(I*0*((2Pi)/10)t)],
ESameTest[Null, ClearAll[ak, a0]],
]
};

0 comments on commit ceb71b9

Please sign in to comment.