@@ -960,18 +960,47 @@ private static Entity IntegrateRationalQuadratic(Entity numerator, Entity a, Ent
960960 var sqrtNegDiscriminant = MathS . Sqrt ( - discriminant ) ;
961961 var lnCase = numerator * AntiderivativeLog ( ( twoAxPlusB - sqrtNegDiscriminant ) / ( twoAxPlusB + sqrtNegDiscriminant ) ) / sqrtNegDiscriminant ;
962962
963- // Return as piecewise based on a and discriminant
963+ // Return as piecewise based on a and discriminant, without the arms no real
964+ // coefficients reach: see ReachesAPositiveDiscriminant and ReachesAZeroDiscriminant.
964965 var cases = new List < Entity . Providedf > ( ) ;
965966 if ( ! denominatorVanishesWithoutA )
966967 cases . Add ( new Entity . Providedf ( linearCase , a . EqualTo ( 0 ) ) ) ;
967968 if ( ArmOffTheRealLine ( arctanCase , discriminant ) is { } offTheRealLine )
968969 cases . Add ( offTheRealLine ) ;
969- cases . Add ( new Entity . Providedf ( arctanCase , discriminant > 0 ) ) ;
970- cases . Add ( new Entity . Providedf ( perfectSquareCase , discriminant . EqualTo ( 0 ) ) ) ;
970+ if ( ReachesAPositiveDiscriminant ( b , c ) )
971+ cases . Add ( new Entity . Providedf ( arctanCase , discriminant > 0 ) ) ;
972+ if ( ReachesAZeroDiscriminant ( b , c ) )
973+ cases . Add ( new Entity . Providedf ( perfectSquareCase , discriminant . EqualTo ( 0 ) ) ) ;
971974 cases . Add ( new Entity . Providedf ( lnCase , discriminant < 0 ) ) ;
972975 return MathS . Piecewise ( cases ) . InnerSimplified ;
973976 }
974977
978+ /// <summary>
979+ /// Whether <c>4 a c - b^2</c> can be positive past the arms before it: not with no
980+ /// constant term and a real <c>b</c>, where it is <c>-b^2</c>. <c>1/(u (a + b u))</c>,
981+ /// which every <c>1/(x (a + b x^n))</c> comes to, carried an arctangent on
982+ /// <c>-a^2 > 0</c>. Real as written only: symbols and real numbers by arithmetic and
983+ /// whole powers. Under `sqrt(-(a + b x)^2)` the coefficient is `sqrt(-b^2) a/b`, and the
984+ /// discriminant is `a^2`.
985+ /// </summary>
986+ private static bool ReachesAPositiveDiscriminant ( Entity b , Entity c )
987+ => ! TreeAnalyzer . IsZero ( c ) || ! b . InnerSimplified . Nodes . All ( node => node switch
988+ {
989+ Entity . Variable or Entity . Number . Real => true ,
990+ Entity . Sumf or Entity . Minusf or Entity . Mulf or Entity . Divf => true ,
991+ Entity . Powf ( _ , Entity . Number . Integer ) => true ,
992+ _ => false
993+ } ) ;
994+
995+ /// <summary>
996+ /// Whether <c>4 a c - b^2</c> can be zero where <c>a</c> is not, which the first arm
997+ /// takes: not with no linear term and a number other than 0 for the constant one, where it
998+ /// is <c>4 a c</c>. <c>1/(1 + q u^2)</c> carried a perfect-square arm on <c>4 q = 0</c>,
999+ /// dividing by <c>q</c>.
1000+ /// </summary>
1001+ private static bool ReachesAZeroDiscriminant ( Entity b , Entity c )
1002+ => ! TreeAnalyzer . IsZero ( b ) || c is not Entity . Number || c . Evaled is Entity . Number . Complex { IsZero : true } ;
1003+
9751004 /// <summary>
9761005 /// ∫ k / (a x^2 + b x + c)^n dx for a whole n of two or more, by the reduction that
9771006 /// takes one power off the denominator at a time.
@@ -1040,15 +1069,14 @@ private static Entity IntegrateOverPowerOfQuadratic(
10401069 : 2 * MathS . Arctan ( derivative / sqrtDiscriminant ) / sqrtDiscriminant ;
10411070 Entity firstPowerLog = withoutTheFirstPower ? Entity . Number . Integer . Zero
10421071 : AntiderivativeLog ( ( derivative - sqrtNegDiscriminant ) / ( derivative + sqrtNegDiscriminant ) ) / sqrtNegDiscriminant ;
1043- var arms = new List < Entity . Providedf >
1044- {
1045- new Entity . Providedf ( linearCase , a . EqualTo ( 0 ) ) ,
1046- new Entity . Providedf ( perfectSquareCase , discriminant . EqualTo ( 0 ) )
1047- } ;
1072+ var arms = new List < Entity . Providedf > { new Entity . Providedf ( linearCase , a . EqualTo ( 0 ) ) } ;
1073+ if ( ReachesAZeroDiscriminant ( b , c ) )
1074+ arms . Add ( new Entity . Providedf ( perfectSquareCase , discriminant . EqualTo ( 0 ) ) ) ;
10481075 var arctanArm = Reduce ( firstPowerArctan ) ;
10491076 if ( ArmOffTheRealLine ( arctanArm , discriminant ) is { } offTheRealLine )
10501077 arms . Add ( offTheRealLine ) ;
1051- arms . Add ( new Entity . Providedf ( arctanArm , discriminant > 0 ) ) ;
1078+ if ( ReachesAPositiveDiscriminant ( b , c ) )
1079+ arms . Add ( new Entity . Providedf ( arctanArm , discriminant > 0 ) ) ;
10521080 arms . Add ( new Entity . Providedf ( Reduce ( firstPowerLog ) , discriminant < 0 ) ) ;
10531081 return MathS . Piecewise ( arms ) . InnerSimplified ;
10541082
0 commit comments