@@ -323,7 +323,11 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
323323
324324 return result ;
325325 } ,
326- evaluate : ( [ num , den ] ) => num . div ( den ) ,
326+ evaluate : ( [ num , den ] , { numericApproximation } ) => {
327+ const res = num . div ( den ) ;
328+ if ( numericApproximation && res . operator !== 'Divide' ) return res . N ( ) ;
329+ return res ;
330+ } ,
327331 } ,
328332
329333 Exp : {
@@ -1787,11 +1791,13 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
17871791
17881792 evaluate : ( ops , options ) => {
17891793 const ce = options . engine ;
1794+ const numericApproximation = options . numericApproximation ;
17901795 const result = run (
17911796 reduceBigOp (
17921797 ops [ 0 ] ,
17931798 ops . slice ( 1 ) ,
1794- ( acc : Expression , x ) => acc . mul ( x . evaluate ( options ) ) ,
1799+ ( acc : Expression , x ) =>
1800+ acc . mul ( x . evaluate ( { numericApproximation } ) ) ,
17951801 ce . One
17961802 ) ,
17971803 ce . _timeRemaining
@@ -1801,16 +1807,18 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
18011807 return undefined ; // Return undefined to keep expression symbolic
18021808 }
18031809 // Evaluate the accumulated result to combine numeric factors
1804- return result ?. evaluate ( ) ?? ce . NaN ;
1810+ return result ?. evaluate ( { numericApproximation } ) ?? ce . NaN ;
18051811 } ,
18061812
18071813 evaluateAsync : async ( ops , options ) => {
18081814 const ce = options . engine ;
1815+ const numericApproximation = options . numericApproximation ;
18091816 const result = await runAsync (
18101817 reduceBigOp (
18111818 ops [ 0 ] ,
18121819 ops . slice ( 1 ) ,
1813- ( acc : Expression , x ) => acc . mul ( x . evaluate ( options ) ) ,
1820+ ( acc : Expression , x ) =>
1821+ acc . mul ( x . evaluate ( { numericApproximation } ) ) ,
18141822 ce . One
18151823 ) ,
18161824 ce . _timeRemaining ,
@@ -1820,7 +1828,7 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
18201828 if ( result === NON_ENUMERABLE_DOMAIN ) {
18211829 return undefined ; // Return undefined to keep expression symbolic
18221830 }
1823- return result ?. evaluate ( ) ?? ce . NaN ;
1831+ return result ?. evaluate ( { numericApproximation } ) ?? ce . NaN ;
18241832 } ,
18251833 } ,
18261834
@@ -1837,12 +1845,13 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
18371845 canonical : ( [ body , ...bounds ] , { scope } ) =>
18381846 canonicalBigop ( 'Sum' , body , bounds , scope ) ,
18391847
1840- evaluate : ( [ body , ...indexes ] , { engine } ) => {
1848+ evaluate : ( [ body , ...indexes ] , { engine, numericApproximation } ) => {
18411849 const result = run (
18421850 reduceBigOp (
18431851 body ,
18441852 indexes ,
1845- ( acc : Expression , x ) => acc . add ( x . evaluate ( ) ) ,
1853+ ( acc : Expression , x ) =>
1854+ acc . add ( x . evaluate ( { numericApproximation } ) ) ,
18461855 engine . Zero
18471856 ) ,
18481857 engine . _timeRemaining
@@ -1853,15 +1862,16 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
18531862 }
18541863 // Evaluate the accumulated result to combine numeric terms
18551864 // e.g., 3x + 1 + 2 + 3 → 3x + 6
1856- return result ?. evaluate ( ) ?? engine . NaN ;
1865+ return result ?. evaluate ( { numericApproximation } ) ?? engine . NaN ;
18571866 } ,
18581867
1859- evaluateAsync : async ( xs , { engine, signal } ) => {
1868+ evaluateAsync : async ( xs , { engine, signal, numericApproximation } ) => {
18601869 const result = await runAsync (
18611870 reduceBigOp (
18621871 xs [ 0 ] ,
18631872 xs . slice ( 1 ) ,
1864- ( acc : Expression , x ) => acc . add ( x . evaluate ( ) ) ,
1873+ ( acc : Expression , x ) =>
1874+ acc . add ( x . evaluate ( { numericApproximation } ) ) ,
18651875 engine . Zero
18661876 ) ,
18671877 engine . _timeRemaining ,
@@ -1871,7 +1881,7 @@ export const ARITHMETIC_LIBRARY: SymbolDefinitions[] = [
18711881 if ( result === NON_ENUMERABLE_DOMAIN ) {
18721882 return undefined ; // Return undefined to keep expression symbolic
18731883 }
1874- return result ?. evaluate ( ) ?? engine . NaN ;
1884+ return result ?. evaluate ( { numericApproximation } ) ?? engine . NaN ;
18751885 } ,
18761886 } ,
18771887 } ,
0 commit comments