text:
For in GOD we live, and move, and have our being. - Acts 17:28

The Joy of a Teacher is the Success of his Students. - Samuel Chukwuemeka

# Fractions, Ratios, and Proportions

Calculators for Fractions

For ACT Students
The ACT is a timed exam...$60$ questions for $60$ minutes
This implies that you have to solve each question in one minute.
Some questions will typically take less than a minute a solve.
Some questions will typically take more than a minute to solve.
The goal is to maximize your time. You use the time saved on those questions you solved in less than a minute, to solve the questions that will take more than a minute.
So, you should try to solve each question correctly and timely.
So, it is not just solving a question correctly, but solving it correctly on time.
Please ensure you attempt all ACT questions.
There is no "negative" penalty for any wrong answer.

For JAMB and CMAT Students
Calculators are not allowed. So, the questions are solved in a way that does not require a calculator.

Solve all questions.
Use at least two (two or more) methods whenever applicable.
Show all work.
For all my applicable students: Calculators ARE NOT allowed for all questions.

(1.) CSEC Using a calculator, or otherwise, calculate the EXACT value of:

$\dfrac{3\dfrac{1}{2} * 1\dfrac{2}{3}}{4\dfrac{1}{5}} \\[5ex]$

$\dfrac{3\dfrac{1}{2} * 1\dfrac{2}{3}}{4\dfrac{1}{5}} \\[10ex] \underline{Numerator} \\[3ex] 3\dfrac{1}{2} = \dfrac{2 * 3 + 1}{2} = \dfrac{6 + 1}{2} = \dfrac{7}{2} \\[5ex] 1\dfrac{2}{3} = \dfrac{3 * 1 + 2}{3} = \dfrac{3 + 2}{3} = \dfrac{5}{3} \\[5ex] 3\dfrac{1}{2} * 1\dfrac{2}{3} \\[5ex] = \dfrac{7}{2} * \dfrac{5}{3} \\[5ex] = \dfrac{7 * 5}{2 * 3} \\[5ex] = \dfrac{35}{6} \\[5ex] \underline{Denominator} \\[3ex] 4\dfrac{1}{5} = \dfrac{5 * 4 + 1}{5} = \dfrac{20 + 1}{5} = \dfrac{21}{5} \\[5ex] \underline{Entire\:\:Question} \\[3ex] Quotient = \dfrac{35}{6} \div \dfrac{21}{5} \\[5ex] = \dfrac{35}{6} * \dfrac{5}{21} \\[5ex] = \dfrac{35 * 5}{6 * 21} \\[5ex] = \dfrac{5 * 5}{6 * 3} \\[5ex] = \dfrac{25}{18} \\[5ex] = 1\dfrac{7}{18}$
(2.) ACT What is the least common denominator of the fractions

$\dfrac{4}{21}, \dfrac{1}{12},\:\:and\:\:\dfrac{3}{8} \\[5ex] F.\:\: 56 \\[3ex] G.\:\: 168 \\[3ex] H.\:\: 252 \\[3ex] J.\:\: 672 \\[3ex] K.\:\: 2,016 \\[3ex]$

The colors besides red indicate the common factors that should be counted only one time.
Begin with them in the multiplication for the LCD.
Then, include the rest.

$Denominators = 21, 12, 8 \\[3ex] 8 = \color{darkblue}{2} * \color{purple}{2} * 2 \\[3ex] 12 = \color{darkblue}{2} * \color{purple}{2} * \color{black}{3} \\[3ex] 21 = \color{black}{3} * 7 \\[3ex] LCD = \color{darkblue}{2} * \color{purple}{2} * \color{black}{3} * 2 * 7 \\[3ex] LCD = 168$
(3.) CSEC Using a calculator, or otherwise, calculate

$5\dfrac{1}{2} \div 3\dfrac{2}{3} + 1\dfrac{4}{5} \\[5ex]$ giving your answer as a fraction in its lowest terms

$PEMDAS \\[3ex] 5\dfrac{1}{2} \div 3\dfrac{2}{3} + 1\dfrac{4}{5} \\[7ex] 5\dfrac{1}{2} = \dfrac{2 * 5 + 1}{2} = \dfrac{10 + 1}{2} = \dfrac{11}{2} \\[5ex] 3\dfrac{2}{3} = \dfrac{3 * 3 + 2}{3} = \dfrac{9 + 2}{3} = \dfrac{11}{3} \\[5ex] 1\dfrac{4}{5} = \dfrac{5 * 1 + 4}{5} = \dfrac{5 + 4}{5} = \dfrac{9}{5} \\[5ex] 5\dfrac{1}{2} \div 3\dfrac{2}{3} \\[5ex] = \dfrac{11}{2} \div \dfrac{11}{3} \\[5ex] = \dfrac{11}{2} * \dfrac{3}{11} \\[5ex] = \dfrac{3}{2} \\[5ex] = 1\dfrac{1}{2} \\[5ex] 1\dfrac{1}{2} + 1\dfrac{4}{5} \\[5ex] We\:\:can\:\:solve\:\:in\:\:two\:\:ways \\[3ex] Use\:\:any\:\:method\:\:you\:\:prefer \\[3ex] \underline{First\:\:Method} \\[3ex] Fractions:\:\: \dfrac{1}{2} + \dfrac{4}{5} \\[5ex] LCD = 10 \\[3ex] = \dfrac{5}{10} + \dfrac{8}{10} \\[5ex] = \dfrac{5 + 8}{10} \\[5ex] = \dfrac{13}{10} \\[5ex] = 1\dfrac{3}{10} \\[5ex] Integers:\:\: 1 + 1 = 2 \\[3ex] Answer:\:\: = 2 + 1\dfrac{3}{10} = 3\dfrac{3}{10} \\[5ex] \therefore 5\dfrac{1}{2} \div 3\dfrac{2}{3} + 1\dfrac{4}{5} = 3\dfrac{3}{10} \\[5ex] \underline{Second\:\:Method} \\[3ex] 1\dfrac{1}{2} + 1\dfrac{4}{5} \\[5ex] = \dfrac{3}{2} + \dfrac{9}{5} \\[5ex] Denominators = 2, 5 \\[3ex] LCD = 10 \\[3ex] = \dfrac{15}{10} + \dfrac{18}{10} \\[5ex] = \dfrac{15 + 18}{10} \\[5ex] = \dfrac{33}{10} \\[5ex] = 3\dfrac{3}{10} \\[5ex] \therefore 5\dfrac{1}{2} \div 3\dfrac{2}{3} + 1\dfrac{4}{5} = 3\dfrac{3}{10}$
(4.) CSEC Evaluate $\dfrac{\dfrac{1}{2} * \dfrac{3}{5}}{3\dfrac{1}{2}}$, giving your answer as fraction in its lowest terms.

$\dfrac{\dfrac{1}{2} * \dfrac{3}{5}}{3\dfrac{1}{2}} \\[10ex] \underline{Numerator} \\[3ex] \dfrac{1}{2} * \dfrac{3}{5} \\[5ex] = \dfrac{1 * 3}{2 * 5} \\[5ex] = \dfrac{3}{10} \\[5ex] \underline{Denominator} \\[3ex] 3\dfrac{1}{2} = \dfrac{2 * 3 + 1}{2} = \dfrac{6 + 1}{2} = \dfrac{7}{2} \\[5ex] \underline{Entire\:\:Question} \\[3ex] Quotient = \dfrac{3}{10} \div \dfrac{7}{2} \\[5ex] = \dfrac{3}{10} * \dfrac{2}{7} \\[5ex] = \dfrac{3}{5} * \dfrac{1}{7} \\[5ex] = \dfrac{3 * 1}{5 * 7} \\[5ex] = \dfrac{3}{35}$
(5.) ACT

$\dfrac{1}{4} * \dfrac{2}{5} * \dfrac{3}{6} * \dfrac{4}{7} * \dfrac{5}{8} * \dfrac{6}{9} * \dfrac{7}{n} = ? \\[5ex] F.\:\: 1 \\[3ex] G.\:\: \dfrac{1}{n} \\[5ex] H.\:\: \dfrac{1}{12n} \\[5ex] J.\:\: \dfrac{2}{9n} \\[5ex] K.\:\: \dfrac{6}{17n} \\[5ex]$

$\dfrac{1}{4} * \dfrac{2}{5} * \dfrac{3}{6} * \dfrac{4}{7} * \dfrac{5}{8} * \dfrac{6}{9} * \dfrac{7}{n} \\[5ex] = \dfrac{1}{2} * \dfrac{1}{1} * \dfrac{1}{2} * \dfrac{1}{1} * \dfrac{1}{1} * \dfrac{1}{3} * \dfrac{1}{n} \\[5ex] = \dfrac{1 * 1 * 1 * 1 * 1 * 1 * 1}{2 * 1 * 2 * 1 * 1 * 3 * n} \\[5ex] = \dfrac{1}{12n}$
(6.) ACT What is the least common denominator of the fractions

$\dfrac{4}{21}, \dfrac{1}{24},\:\:and\:\:\dfrac{3}{16} \\[5ex] F.\:\: 112 \\[3ex] G.\:\: 336 \\[3ex] H.\:\: 504 \\[3ex] J.\:\: 2,688 \\[3ex] K.\:\: 8,064 \\[3ex]$

The colors besides red indicate the common factors that should be counted only one time.
Begin with them in the multiplication for the LCD.
Then, include the rest.

$Denominators = 21, 24, 16 \\[3ex] 21 = \color{black}{3} * 7 \\[3ex] 24 = \color{darkblue}{2} * \color{purple}{2} * \color{grey}{2} * \color{black}{3} \\[3ex] 16 = \color{darkblue}{2} * \color{purple}{2} * \color{grey}{2} * 2 \\[3ex] LCD = \color{black}{3} * \color{darkblue}{2} * \color{purple}{2} * \color{grey}{2} * 7 * 2 \\[3ex] LCD = 336$
(7.) CSEC Using a calculator, or otherwise, determine the exact value of

$\dfrac{3\dfrac{1}{3} - 2\dfrac{3}{5}}{2\dfrac{1}{5}} \\[7ex]$

$\dfrac{3\dfrac{1}{3} - 2\dfrac{3}{5}}{2\dfrac{1}{5}} \\[10ex] \underline{Numerator} \\[3ex] 3\dfrac{1}{3} - 2\dfrac{3}{5} \\[5ex] \underline{First\:\:Method} \\[3ex] Fractions:\:\: \dfrac{1}{3} - \dfrac{3}{5} \\[3ex] LCD = 15 \\[3ex] = \dfrac{5}{15} - \dfrac{9}{15} \\[5ex] = \dfrac{5 - 9}{15} \\[5ex] = -\dfrac{4}{15}...Not\:\:what\:\:we\:\:want \\[5ex] Borrow\:\:1\:\:from\:\:the\:\:Integer, 3 \\[3ex] Remaining:\:\: 3 - 1 = 2 \\[3ex] Add\:\:that\:\:1\:\:to\:\:\dfrac{1}{3} \\[5ex] 1 + \dfrac{1}{3} \\[5ex] = \dfrac{3}{3} + \dfrac{1}{3} \\[5ex] = \dfrac{3 + 1}{3} \\[5ex] = \dfrac{4}{3} \\[5ex] Fractions\:\:again:\:\: \dfrac{4}{3} - \dfrac{3}{5} \\[5ex] LCD = 15 \\[3ex] = \dfrac{20}{15} - \dfrac{9}{15} \\[5ex] = \dfrac{20 - 9}{15} \\[5ex] = \dfrac{11}{15} \\[5ex] Integers:\:\: 2 - 2 = 0 \\[3ex] Difference = 0 + \dfrac{11}{15} = \dfrac{11}{15} \\[5ex] \underline{Second\:\:Method} \\[3ex] 3\dfrac{1}{3} = \dfrac{3 * 3 + 1}{3} = \dfrac{9 + 1}{3} = \dfrac{10}{3} \\[5ex] 2\dfrac{3}{5} = \dfrac{5 * 2 + 3}{5} = \dfrac{10 + 3}{5} = \dfrac{13}{5} \\[5ex] \dfrac{10}{3} - \dfrac{13}{5} \\[5ex] LCD = 15 \\[3ex] = \dfrac{50}{15} - \dfrac{39}{15} \\[5ex] = \dfrac{50 - 39}{15} \\[5ex] = \dfrac{11}{15} \\[5ex] \underline{Denominator} \\[3ex] 2\dfrac{1}{5} = \dfrac{5 * 2 + 1}{5} = \dfrac{10 + 1}{5} = \dfrac{11}{5} \\[5ex] \underline{Entire\:\:Question} \\[3ex] Quotient = \dfrac{11}{15} \div \dfrac{11}{5} \\[5ex] = \dfrac{11}{15} * \dfrac{5}{11} \\[5ex] = \dfrac{1}{3}$
(8.) CSEC Using a calculator, or otherwise, calculate the exact value of

$\dfrac{2\dfrac{1}{4} * \dfrac{4}{5}}{\dfrac{3}{5} - \dfrac{1}{2}} \\[5ex]$

$\dfrac{2\dfrac{1}{4} * \dfrac{4}{5}}{\dfrac{3}{5} - \dfrac{1}{2}} \\[10ex] \underline{Numerator} \\[3ex] 2\dfrac{1}{4} = \dfrac{4 * 2 + 1}{4} = \dfrac{8 + 1}{4} = \dfrac{9}{4} \\[5ex] \dfrac{9}{4} * \dfrac{4}{5} = \dfrac{9}{5} \\[5ex] \underline{Denominator} \\[3ex] \dfrac{3}{5} - \dfrac{1}{2} \\[5ex] = \dfrac{6}{10} - \dfrac{5}{10} \\[5ex] = \dfrac{6 - 5}{10} \\[5ex] = \dfrac{1}{10} \\[5ex] \underline{Entire\:\:Question} \\[3ex] \dfrac{9}{5} \div \dfrac{1}{10} \\[5ex] = \dfrac{9}{5} * \dfrac{10}{1} \\[5ex] = \dfrac{9}{1} * \dfrac{2}{1} \\[5ex] = 9 * 2 \\[3ex] = 18$
(9.) WASSCE Simplify:

$\dfrac{1\dfrac{7}{8} * 2\dfrac{2}{5}}{6\dfrac{3}{4} \div \dfrac{3}{4}} \\[7ex] A.\:\: 9 \\[3ex] B.\:\: 4\dfrac{1}{2} \\[5ex] C.\:\: 2 \\[3ex] D.\:\: \dfrac{1}{2} \\[5ex]$

$\dfrac{1\dfrac{7}{8} * 2\dfrac{2}{5}}{6\dfrac{3}{4} \div \dfrac{3}{4}} \\[10ex] \underline{Numerator} \\[3ex] 1\dfrac{7}{8} = \dfrac{8 * 1 + 7}{8} = \dfrac{8 + 7}{8} = \dfrac{15}{8} \\[5ex] 2\dfrac{2}{5} = \dfrac{5 * 2 + 2}{5} = \dfrac{10 + 2}{5} = \dfrac{12}{5} \\[5ex] \dfrac{15}{8} * \dfrac{12}{5} \\[5ex] = \dfrac{3}{2} * \dfrac{3}{1} \\[5ex] = \dfrac{3 * 3}{2 * 1} \\[5ex] = \dfrac{9}{2} \\[5ex] \underline{Denominator} \\[3ex] 6\dfrac{3}{4} = \dfrac{4 * 6 + 3}{4} = \dfrac{24 + 3}{4} = \dfrac{27}{4} \\[5ex] \dfrac{27}{4} \div \dfrac{3}{4} \\[5ex] = \dfrac{27}{4} * \dfrac{4}{3} \\[5ex] = \dfrac{9}{1} * \dfrac{1}{1} \\[5ex] = 9 * 1 \\[3ex] = 9 \\[3ex] \underline{Entire\:\:Question} \\[3ex] \dfrac{9}{2} \div 9 \\[5ex] = \dfrac{9}{2} \div \dfrac{9}{1} \\[5ex] =\dfrac{9}{2} * \dfrac{1}{9} \\[5ex] = \dfrac{1}{2} * \dfrac{1}{1} \\[5ex] = \dfrac{1}{2}$
(10.) ACT For all real numbers $x$ such that $x \ne 0$, $\dfrac{4}{5} + \dfrac{7}{x} = ?$

$A.\:\: \dfrac{11}{5x} \\[5ex] B.\:\: \dfrac{28}{5x} \\[5ex] C.\:\: \dfrac{11}{5 + x} \\[5ex] D.\:\: \dfrac{7x + 20}{5 + x} \\[5ex] E.\:\: \dfrac{4x + 35}{5x} \\[5ex]$

$\dfrac{4}{5} + \dfrac{7}{x} \\[5ex] LCD\:\:of\:\:5\:\:and\:\:x = 5 * x = 5x \\[3ex] = \dfrac{4x}{5x} + \dfrac{35}{5x} \\[5ex] = \dfrac{4x + 35}{5x}$
(11.) CSEC Using a calculator, or otherwise, determine the EXACT value of:

$2\dfrac{2}{5} - 1\dfrac{1}{3} + 3\dfrac{1}{2} \\[5ex]$

We can solve this question in two ways.
Use any method you prefer.

$2\dfrac{2}{5} - 1\dfrac{1}{3} + 3\dfrac{1}{2} \\[7ex] PEMDAS \\[3ex] \underline{First\:\:Method} \\[3ex] Fractions:\:\: \dfrac{2}{5} - \dfrac{1}{3} + \dfrac{1}{2} \\[5ex] LCD = 30 \\[3ex] = \dfrac{12}{30} - \dfrac{10}{30} + \dfrac{15}{30} \\[5ex] = \dfrac{12 - 10 + 15}{30} \\[5ex] = \dfrac{17}{30} \\[5ex] Integers:\:\: 2 - 1 + 3 = 4 \\[3ex] Answer:\:\: = 4 + \dfrac{17}{30} = 4\dfrac{17}{30} \\[5ex] \therefore 2\dfrac{2}{5} - 1\dfrac{1}{3} + 3\dfrac{1}{2} = 4\dfrac{17}{30} \\[5ex] \underline{Second\:\:Method} \\[3ex] 2\dfrac{2}{5} = \dfrac{5 * 2 + 2}{5} = \dfrac{10 + 2}{5} = \dfrac{12}{5} \\[5ex] 1\dfrac{1}{3} = \dfrac{3 * 1 + 1}{3} = \dfrac{3 + 1}{3} = \dfrac{4}{3} \\[5ex] 3\dfrac{1}{2} = \dfrac{2 * 3 + 1}{2} = \dfrac{6 + 1}{2} = \dfrac{7}{2} \\[5ex] \dfrac{12}{5} - \dfrac{4}{3} + \dfrac{7}{2} \\[5ex] LCD = 30 \\[3ex] = \dfrac{72}{30} - \dfrac{40}{30} + \dfrac{105}{30} \\[5ex] = \dfrac{72 - 40 + 105}{30} \\[5ex] = \dfrac{137}{30} \\[5ex] = 4\dfrac{17}{30} \\[5ex] \therefore 2\dfrac{2}{5} - 1\dfrac{1}{3} + 3\dfrac{1}{2} = 4\dfrac{17}{30}$
(12.) CSEC Evaluate $\dfrac{\dfrac{1}{2} * \dfrac{3}{5}}{3\dfrac{1}{2}}$, giving your answer as fraction in its lowest terms.

$\dfrac{\dfrac{1}{2} * \dfrac{3}{5}}{3\dfrac{1}{2}} \\[10ex] \underline{Numerator} \\[3ex] \dfrac{1}{2} * \dfrac{3}{5} \\[5ex] = \dfrac{1 * 3}{2 * 5} \\[5ex] = \dfrac{3}{10} \\[5ex] \underline{Denominator} \\[3ex] 3\dfrac{1}{2} = \dfrac{2 * 3 + 1}{2} = \dfrac{6 + 1}{2} = \dfrac{7}{2} \\[5ex] \underline{Entire\:\:Question} \\[3ex] Quotient = \dfrac{3}{10} \div \dfrac{7}{2} \\[5ex] = \dfrac{3}{10} * \dfrac{2}{7} \\[5ex] = \dfrac{3}{5} * \dfrac{1}{7} \\[5ex] = \dfrac{3 * 1}{5 * 7} \\[5ex] = \dfrac{3}{35}$
(13.) CSEC Calculate the EXACT value of

$\left(1\dfrac{3}{4} - \dfrac{1}{8}\right) + \left(\dfrac{5}{6} \div \dfrac{2}{3}\right) \\[5ex]$

$PEMDAS \\[3ex] \underline{First\:\:Part} \\[3ex] \left(1\dfrac{3}{4} - \dfrac{1}{8}\right) \\[5ex] 1\dfrac{3}{4} = \dfrac{4 * 1 + 3}{4} = \dfrac{4 + 3}{4} = \dfrac{7}{4} \\[5ex] = \dfrac{7}{4} - \dfrac{1}{8} \\[5ex] LCD = 8 \\[3ex] = \dfrac{14}{8} - \dfrac{1}{8} \\[5ex] = \dfrac{14 - 1}{8} \\[5ex] = \dfrac{13}{8} \\[5ex] \underline{Second\:\:Part} \\[3ex] \dfrac{5}{6} \div \dfrac{2}{3} \\[5ex] = \dfrac{5}{6} * \dfrac{3}{2} \\[5ex] = \dfrac{5}{2} * \dfrac{1}{2} \\[5ex] = \dfrac{5 * 1}{2 * 2} \\[5ex] = \dfrac{5}{4} \\[5ex] \underline{First\:\:Part + Second\:\:Part} \\[3ex] \dfrac{13}{8} + \dfrac{5}{4} \\[5ex] LCD = 8 \\[3ex] = \dfrac{13}{8} + \dfrac{10}{8} \\[5ex] = \dfrac{13 + 10}{8} \\[5ex] = \dfrac{23}{8} \\[5ex] = 2\dfrac{7}{8}$
(14.) ACT $8\%$ of $60$ is $\dfrac{1}{5}$ of what number?

$A.\:\: 0.96 \\[3ex] B.\:\: 12 \\[3ex] C.\:\: 24 \\[3ex] D.\:\: 240 \\[3ex] E.\:\: 3,750 \\[3ex]$

$8\%\:\:of\:\:60 \\[3ex] = \dfrac{8}{100} * 60 \\[5ex] = \dfrac{4}{5} * 6 \\[5ex] = \dfrac{24}{5} \\[5ex] \rightarrow \dfrac{24}{5}\:\:is\:\:\dfrac{1}{5}\:\:of\:\:what\:\:number \\[5ex] Let\:\:the\:\:number = n \\[3ex] \dfrac{24}{5} = \dfrac{1}{5} * n \\[5ex] Denominators\:\:are\:\:the\:\:same \\[3ex] Equate\:\:the\:\:numerators \\[3ex] 24 = 1n \\[3ex] n = 24$
(15.) ACT What is the least common denominator of the fractions $\dfrac{4}{35}$, $\dfrac{1}{77}$, and $\dfrac{3}{22}$

$A.\:\: 110 \\[3ex] B.\:\: 770 \\[3ex] C.\:\: 2,695 \\[3ex] D.\:\: 8,470 \\[3ex] E.\:\: 59,290 \\[3ex]$

The colors besides red indicate the common factors that should be counted only one time.
Begin with them in the multiplication for the LCD.
Then, include the rest.

$Denominators = 35, 77, 22 \\[3ex] 35 = 5 * \color{black}{7} \\[3ex] 77 = \color{black}{7} * \color{darkblue}{11} \\[3ex] 22 = 2 * \color{darkblue}{11} \\[3ex] LCD = \color{black}{7} * \color{darkblue}{11} * 5 * 2 \\[3ex] LCD = 770$
(16.) ACT What is the least common multiple of $50$, $30$, and $70?$

$F.\:\: 50 \\[3ex] G.\:\: 105 \\[3ex] H.\:\: 150 \\[3ex] J.\:\: 1,050 \\[3ex] K.\:\: 105,000 \\[3ex]$

The colors besides red indicate the common factors that should be counted only one time.
Begin with them in the multiplication for the LCD.
Then, include the rest.

$Numbers = 50, 30, 70 \\[3ex] 50 = \color{black}{2} * \color{darkblue}{5} * 5 \\[3ex] 30 = \color{black}{2} * 3 * \color{darkblue}{5} \\[3ex] 70 = \color{black}{2} * \color{darkblue}{5} * 7 \\[3ex] LCM = \color{black}{2} * \color{darkblue}{5} * 5 * 3 * 7 \\[3ex] LCM = 1,050$
(17.) JAMB Simplify $3\dfrac{1}{2} - \left(2\dfrac{1}{3} * 1\dfrac{1}{4}\right) + \dfrac{3}{5}$

$A.\:\: 2\dfrac{11}{60} \\[5ex] B.\:\: 2\dfrac{1}{60} \\[5ex] C.\:\: 1\dfrac{11}{60} \\[5ex] D.\:\: 1\dfrac{1}{60} \\[5ex]$

$PEMDAS \\[3ex] 2\dfrac{1}{3} = \dfrac{3 * 2 + 1}{3} = \dfrac{6 + 1}{3} = \dfrac{7}{3} \\[5ex] 1\dfrac{1}{4} = \dfrac{4 * 1 + 1}{4} = \dfrac{4 + 1}{4} = \dfrac{5}{4} \\[5ex] 2\dfrac{1}{3} * 1\dfrac{1}{4} \\[5ex] = \dfrac{7}{3} * \dfrac{5}{4} \\[5ex] = \dfrac{35}{12} \\[5ex] 3\dfrac{1}{2} = \dfrac{2 * 3 + 1}{2} = \dfrac{6 + 1}{2} = \dfrac{7}{2} \\[5ex] 3\dfrac{1}{2} - \left(2\dfrac{1}{3} * 1\dfrac{1}{4}\right) + \dfrac{3}{5} \\[5ex] = \dfrac{7}{2} - \dfrac{35}{12} + \dfrac{3}{5} \\[5ex] LCD\:\:of\:\:2,12,5 = 60 \\[3ex] = \dfrac{210}{60} - \dfrac{175}{60} + \dfrac{36}{60} \\[5ex] = \dfrac{210 - 175 + 36}{60} \\[5ex] = \dfrac{71}{60} \\[5ex] = 1\dfrac{11}{60}$
(18.) ACT If the positive integers $x$ and $y$ are relatively prime (their greatest common factor is $1$) and $\dfrac{1}{2} + \dfrac{1}{3} * \dfrac{1}{4} \div \dfrac{1}{5} = \dfrac{x}{y}$, then $x + y = ?$

$A.\:\: 23 \\[3ex] B.\:\: 25 \\[3ex] C.\:\: 49 \\[3ex] D.\:\: 91 \\[3ex] E.\:\: 132 \\[3ex]$

$\dfrac{1}{2} + \dfrac{1}{3} * \dfrac{1}{4} \div \dfrac{1}{5} \\[5ex] PEMDAS \\[3ex] \dfrac{1}{2} + \dfrac{1 * 1}{3 * 4} \div \dfrac{1}{5} \\[5ex] = \dfrac{1}{2} + \dfrac{1}{12} \div \dfrac{1}{5} \\[5ex] = \dfrac{1}{2} + \dfrac{1}{12} * \dfrac{5}{1} \\[5ex] = \dfrac{1}{2} + \dfrac{1 * 5}{12 * 1} \\[5ex] = \dfrac{1}{2} + \dfrac{5}{12} \\[5ex] LCD = 12 \\[3ex] = \dfrac{6}{12} + \dfrac{5}{12} \\[5ex] = \dfrac{6 + 5}{12} \\[5ex] = \dfrac{11}{12} = \dfrac{x}{y} \\[5ex] \implies x = 11,\:\: y = 12 \\[3ex] x + y = 11 + 12 = 23$


text:
# Calculating Uncertainties with linear combinations

## Homework Statement

I am having trouble determining the error for a set of linear equations that represent a simple circuit with two voltage sources. I have found two possible uncertainties by solving using substitution, detailed below.

The circuit is shown below:
http://img233.imageshack.us/img233/9165/circuit1small.jpg [Broken]

## Homework Equations

I am solving the circuit using loop analysis and the two equations found are:

1. I1R1 + R2(I1+I2) = V1
2. I2R3 + R2(I1+I2) = V2

## The Attempt at a Solution

Solving 2. for I2 and subbing into 1. gives:
I1 = 25.8 mA +- 17.2%

Solving by back subbing into 2. gives:
I2 = 128.5 mA +- 6.1%

or subbing I1 into 1. gives:
I2 = 128.5 mA +- 25.8%

So which one is correct 25% or 6%?

Last edited by a moderator:

## Answers and Replies

What rule are you using?

What rule are you using?
I'm sorry, I do not understand what you mean by rule. As far as I can tell I have not violated any rules?
I'm really just curious to know if anyone has an idea why the uncertainty would be different depending on which equation is used to solve for I2.

I mean that there are different "rules" for calculating uncertainties whether you are adding, or multiplying, etc. There is a "master" rule that goes as

given function f(x,y,...)
$$\sigma_f = \sqrt{(\frac{\partial f}{\partial x} \sigma_x)^2 + (\frac{\partial f}{\partial y} \sigma_y)^2+...}$$

I mean that there are different "rules" for calculating uncertainties whether you are adding, or multiplying, etc. There is a "master" rule that goes as

given function f(x,y,...)
$$\sigma_f = \sqrt{(\frac{\partial f}{\partial x} \sigma_x)^2 + (\frac{\partial f}{\partial y} \sigma_y)^2+...}$$
Oh interesting, I have not seen the Partial method of calculating uncertainties.
We are using the standard method most people learn in first year physics, addition/subtraction is adding absolute error; multiplication/division is adding of relative errors.

I showed it to my prof relatively quickly and even she was dumbfounded as to why the uncertainties are different.

Well, they should be the same. Maybe we can figure it out. I don't know the value and uncertainty of R2 though.

How did you calculate this uncertainty if all you've covered is addition/subtraction? This is a problem for mathematica.

R1= 370+- 10 Ohm
R2= 100+- 3 Ohm
R3= 220+- 6 Ohm
V1= 25V+- 2%
V2= 45V+- 2%

The uncertainty that I ended with was a result of manually calculating each operation with each absolute or relative uncertainty. Our lab fell on a holiday last week, so the prof assigned this 'simple' question as a replacement, I suppose to keep us busy.

The uncertainty for each component is a given in the question.

Last edited:
I hate to say it, but your values are probably just not right. According to matlab, using the master rule, the uncertainty in I1 is

$$\Delta I_1 = \sqrt{\Delta V1^2 + \Delta V2^2 + (\frac{V2R1+V1R3)R3}{R1R3+R1R2+R2R3}\Delta R2)^2 + (\frac{V1-R2V2/(R3+R2)}{R1+R2-R1^2/(R1+R2)}\Delta R1)^2 + (\frac{V2R1+R2V2-V1R2)R3}{R1R3+R1R2+R2R3)^2}\Delta R3)^2}$$

It is entirely likely that I made an error even though I checked the work multiple times to be sure; but, I did end with the same current for both equations.

Is there another name for the Master rule? I cannot seem to find much on it.

format: plain


text:
# latexdiff - Man Page

determine and markup differences between two latex files

## Synopsis

latexdiff [ Options ] old.tex new.tex > diff.tex

## Description

Briefly, latexdiff is a utility program to aid in the management of revisions of latex documents. It compares two valid latex files, here called old.tex and new.tex, finds significant differences between them (i.e., ignoring the number of white spaces and position of line breaks), and adds special commands to highlight the differences.  Where visual highlighting is not possible, e.g. for changes in the formatting, the differences are nevertheless marked up in the source. Note that old.tex and new.tex need to be real files (not pipes or similar) as they are opened twice (unless --encoding option is used)

The program treats the preamble differently from the main document. Differences between the preambles are found using line-based differencing (similarly to the Unix diff command, but ignoring white spaces).  A comment, "%DIF >" is appended to each added line, i.e. a  line present in new.tex but not in old.tex.  Discarded lines
are deactivated by prepending "%DIF <". Changed blocks are preceded  by comment lines giving information about line numbers in the original files.  Where there are insignificant differences, the resulting file diff.tex will be similar to new.tex.  At the end of the preamble, the definitions for latexdiff markup commands are inserted. In differencing the main body of the text, latexdiff attempts to satisfy the following guidelines (in order of priority):

1. If both old.tex and new.tex are valid LaTeX, then the resulting diff.tex should also be valid LateX. (NB If a few plain TeX commands are used within old.tex or new.tex then diff.tex is not guaranteed to work but usually will).
2. Significant differences are determined on the level of individual words. All significant differences, including differences between comments should be clearly marked in the resulting source code diff.tex.
3. If a changed passage contains text or text-producing commands, then running diff.tex through LateX should produce output where added and discarded passages are highlighted.
4. Where there are insignificant differences, e.g. in the positioning of line breaks, diff.tex should follow the formatting of new.tex

For differencing the same algorithm as diff is used but words instead of lines are compared.  An attempt is made to recognize blocks which are completely changed such that they can be marked up as a unit. Comments are differenced line by line but the number of spaces within comments is ignored. Commands including all their arguments are generally compared as one unit, i.e., no mark-up is inserted into the arguments of commands.  However, for a selected number of commands (for example, \caption and all sectioning commands) the last argument is known to be text. This text is split into words and differenced just as ordinary text (use options to show and change the list of text commands, see below). As the algorithm has no detailed knowledge of LaTeX, it assumes all pairs of curly braces immediately following a command (i.e. a sequence of letters beginning with a backslash) are arguments for that command. As a restriction to condition 1 above it is thus necessary to surround all arguments with curly braces, and to not insert extraneous spaces.  For example, write

  \section{\textem{This is an emphasized section title}}

and not

  \section {\textem{This is an emphasized section title}}

or

  \section\textem{This is an emphasized section title}

even though all varieties are the same to LaTeX (but see --allow-spaces option which allows the second variety).

For environments whose content does not conform to standard LaTeX or where graphical markup does not make sense all markup commands can be removed by setting the PICTUREENV configuration variable, set by default to picture and DIFnomarkup environments; see --config option).  The latter environment (DIFnomarkup) can be used to protect parts of the latex file where the markup results in illegal markup. You have to surround the offending passage in both the old and new file by \begin{DIFnomarkup} and \end{DIFnomarkup}. You must define the environment in the preambles of both old and new documents. I prefer to define it as a null-environment,

\newenvironment{DIFnomarkup}{}{}

but the choice is yours.  Any markup within the environment will be removed, and generally everything within the environment will just be taken from the new file.

It is also possible to difference files which do not have a preamble.
In this case, the file is processed in the main document mode, but the definitions of the markup commands are not inserted.

All markup commands inserted by latexdiff begin with "\DIF".  Added blocks containing words, commands or comments which are in new.tex but not in old.tex are marked by \DIFaddbegin and \DIFaddend. Discarded blocks are marked by \DIFdelbegin and \DIFdelend. Within added blocks all text is highlighted with \DIFadd like this: \DIFadd{Added text block} Selected safe' commands can be contained in these text blocks as well (use options to show and change the list of safe commands, see below). All other commands as well as braces “{” and “}” are never put within the scope of \DIFadd.  Added comments are marked by prepending "%DIF > ".

Within deleted blocks text is highlighted with \DIFdel.  Deleted comments are marked by prepending "%DIF < “.  Non-safe command and curly braces within deleted blocks are commented out with  ”%DIFDELCMD < ".

## Options

### Preamble

The following options determine the visual markup style by adding the appropriate command definitions to the preamble. See the end of this section for a description of  available styles.

--type=markupstyle or -t markupstyle

Add code to preamble for selected markup style. This option defines \DIFadd and \DIFdel commands. Available styles:

UNDERLINE CTRADITIONAL TRADITIONAL CFONT FONTSTRIKE INVISIBLE  CHANGEBAR CCHANGEBAR CULINECHBAR CFONTCHBAR BOLD PDFCOMMENT

[ Default: UNDERLINE ]

--subtype=markstyle or -s markstyle

Add code to preamble for selected style for bracketing commands (e.g. to mark changes in  margin). This option defines \DIFaddbegin, \DIFaddend, \DIFdelbegin and \DIFdelend commands. Available styles: SAFE MARGIN COLOR DVIPSCOL  ZLABEL ONLYCHANGEDPAGE (LABEL)*

[ Default: SAFE ] * Subtype LABEL is deprecated

--floattype=markstyle or -f markstyle

Add code to preamble for selected style which  replace standard marking and markup commands within floats (e.g., marginal remarks cause an error within floats so marginal marking can be disabled thus). This option defines all  \DIF...FL commands. Available styles: FLOATSAFE TRADITIONALSAFE IDENTICAL

[ Default: FLOATSAFE ]

--encoding=enc or -e enc

Specify encoding of old.tex and new.tex. Typical encodings are ascii, utf8, latin1, latin9.  A list of available encodings can be  obtained by executing

perl -MEncode -e 'print join ("\n",Encode-encodings( “:all” )) ;' >

If this option is used, then old.tex, new.tex are only opened once. [Default encoding is utf8 unless the first few lines of the preamble contain an invocation \usepackage[..]{inputenc} in which case the  encoding chosen by this command is asssumed. Note that ASCII (standard latex) is a subset of utf8]

--preamble=file or -p file

Insert file at end of preamble instead of generating preamble.  The preamble must define the following commands \DIFaddbegin, \DIFaddend, \DIFadd{..}, \DIFdelbegin,\DIFdelend,\DIFdel{..}, and varieties for use within floats \DIFaddbeginFL, \DIFaddendFL, \DIFaddFL{..}, \DIFdelbeginFL, \DIFdelendFL, \DIFdelFL{..} (If this option is set -t, -s, and -f options are ignored.)

--packages=pkg1,pkg2,..

Tell latexdiff that .tex file is processed with the packages in list loaded.  This is normally not necessary if the .tex file includes the preamble, as the preamble is automatically scanned for \usepackage commands. Use of the --packages option disables automatic scanning, so if for any reason package specific parsing needs to be switched off, use --packages=none. The following packages trigger special behaviour:

amsmath

Configuration variable MATHARRREPL is set to align* (Default: eqnarray*). (Note that many of the  amsmath array environments are already recognised by default as such)

endfloat

Ensure that \begin{figure} and \end{figure} always appear by themselves on a line.

hyperref

Change name of \DIFadd and \DIFdel commands to \DIFaddtex and \DIFdeltex and  define new \DIFadd and \DIFdel commands, which provide a wrapper for these commands, using them for the text but not for the link defining command (where any markup would cause errors).

apacite

Redefine the commands recognised as citation commands.

siunitx

Treat \SI as equivalent to citation commands (i.e. protect with \mbox if markup style uses ulem package.

cleveref

Treat \cref,\Cref, etc as equivalent to citation commands (i.e. protect with \mbox if markup style uses ulem package.

glossaries

Define most of the glossaries commands as safe, protecting them with \mbox'es where needed

mhchem

Treat \ce as a safe command, i.e. it will be highlighted (note that \cee will not be highlighted in equations as this leads to processing errors)

chemformula or chemmacros

Treat \ch as a safe command outside equations, i.e. it will be highlighted (note that \ch will not be highlighted in equations as this leads to processing errors)

[ Default: scan the preamble for \usepackage commands to determine

--show-preamble

Print generated or included preamble commands to stdout.

### Configuration

--exclude-safecmd=exclude-file or -A exclude-file or  --exclude-safecmd=“cmd1,cmd2,...”
--replace-safecmd=replace-file
--append-safecmd=append-file or -a append-file or --append-safecmd=“cmd1,cmd2,...”

Exclude from, replace or append to the list of regular expressions (RegEx) matching commands which are safe to use within the  scope of a \DIFadd or \DIFdel command.  The file must contain one Perl-RegEx per line (Comment lines beginning with # or % are ignored).  Note that the RegEx needs to match the whole of  the token, i.e., /^regex\$/ is implied and that the initial “\” of the command is not included.  The --exclude-safecmd and --append-safecmd options can be combined with the ---replace-safecmd  option and can be used repeatedly to add cumulatively to the lists.
--exclude-safecmd and --append-safecmd can also take a comma separated list as input. If a comma for one of the regex is required, escape it thus “\,”. In most cases it will be necessary to protect the comma-separated list from the shell by putting it in quotation marks.

--exclude-textcmd=exclude-file or -X exclude-file or --exclude-textcmd=“cmd1,cmd2,...”
--replace-textcmd=replace-file
--append-textcmd=append-file or -x append-file or --append-textcmd=“cmd1,cmd2,...”

Exclude from, replace or append to the list of regular expressions matching commands whose last argument is text.  See entry for --exclude-safecmd directly above for further details.

--replace-context1cmd=replace-file
--append-context1cmd=append-file or
--append-context1cmd=“cmd1,cmd2,...”

Replace or append to the list of regex matching commands whose last argument is text but which require a particular context to work, e.g. \caption will only work within a figure or table.  These commands behave like text commands, except when  they occur in a deleted section, when they are disabled, but their argument is shown as deleted text.

--replace-context2cmd=replace-file
--append-context2cmd=append-file or
--append-context2cmd=“cmd1,cmd2,...”

As corresponding commands for context1.  The only difference is that context2 commands are completely disabled in deleted sections, including their arguments.

context2 commands are also the only commands in the preamble, whose argument will be processed in  word-by-word mode (which only works, if they occur no more than once in the preamble). The algorithm currently cannot cope with repeated context2 commands in the preamble, as they occur e.g. for the \author argument in some journal styles (not in the standard styles, though If such a repetition is detected, the whole preamble will be processed in line-by-line mode. In such a case, use --replace-context2cmd option to just select the commands, which should be processed and are not used repeatedly in the preamble.

--exclude-mboxsafecmd=exclude-file or --exclude-mboxsafecmd=“cmd1,cmd2,...”
--append-mboxsafecmd=append-file or --append-mboxsafecmd=“cmd1,cmd2,...”

Define safe commands, which additionally need to be protected by encapsulating in an \mbox{..}. This is sometimes needed to get around incompatibilities  between external packages and the ulem package, which is  used for highlighting in the default style UNDERLINE as well as CULINECHBAR CFONTSTRIKE

--config var1=val1,var2=val2,... or -c var1=val1,..
-c configfile

Set configuration variables.  The option can be repeated to set different variables (as an alternative to the comma-separated list). Available variables (see below for further explanations):

ARRENV (RegEx)

COUNTERCMD (RegEx)

CUSTODIFCMD (RegEx)

FLOATENV (RegEx)

ITEMCMD (RegEx)

LISTENV  (RegEx)

MATHARRENV (RegEx)

MATHARRREPL (String)

MATHENV (RegEx)

MATHREPL (String)

MINWORDSBLOCK (Integer)

PICTUREENV (RegEx)

SCALEDELGRAPHICS (Float)

For configuration variables, which are a regular expression (essentially those ending in ENV, COUNTERCMD and CUSTOMDIFCMD, see list above) this option provides an alternative way to modify the configuration  variables. Instead of setting the complete pattern, with this option it is possible to add an alternative pattern. varenv must be one of the variables listed above that take a regular expression as argument, and pattern is any regular expression (which might need to be  protected from the shell by quotation). Several patterns can be added at once by using semi-colons to separate them, e.g. --add-to-config "LISTENV=myitemize;myenumerate,COUNTERCMD=endnote"

--show-safecmd

Print list of RegEx matching and excluding safe commands.

--show-textcmd

Print list of RegEx matching and excluding commands with text argument.

--show-config

Show values of configuration variables.

--show-all

Combine all --show commands.

NB For all --show commands, no old.tex or new.tex file needs to be specified, and no  differencing takes place.

### Other configuration options

--allow-spaces

Allow spaces between bracketed or braced arguments to commands.  Note that this option might have undesirable side effects (unrelated scope might get lumpeded with preceding commands) so should only be used if the default produces erroneous results.  (Default requires arguments to directly follow each other without intervening spaces).

--math-markup=level

Determine granularity of markup in displayed math environments:                Possible values for level are (both numerical and text labels are acceptable):

off or 0: suppress markup for math environments.  Deleted equations will not  appear in diff file. This mode can be used if all the other modes  cause invalid latex code.

whole or 1: Differencing on the level of whole equations. Even trivial changes to equations cause the whole equation to be marked changed.  This  mode can be used if processing in coarse or fine mode results in  invalid latex code.

coarse or 2: Detect changes within equations marked up with a coarse granularity; changes in equation type (e.g.displaymath to equation)  appear as a change to the complete equation. This mode is recommended for situations where the content and order of some equations are still being changed. [Default]

fine or 3: Detect small change in equations and mark up at fine granularity. This mode is most suitable, if only minor changes to equations are expected, e.g. correction of typos.

--graphics-markup=level
 Change highlight style for graphics embedded with C<\includegraphics> commands.

Possible values for level:

none, off or 0: no highlighting for figures

new-only or 1: surround newly added or changed figures with a blue frame [Default if graphicx package loaded]

both or 2:     highlight new figures with a blue frame and show deleted figures at reduced  scale, and crossed out with a red diagonal cross. Use configuration variable SCALEDELGRAPHICS to set size of deleted figures.

Note that changes to the optional parameters will make the figure appear as changed  to latexdiff, and this figure will thus be highlighted

--disable-citation-markup or --disable-auto-mbox

Suppress citation markup and markup of other vulnerable commands in styles  using ulem (UNDERLINE,FONTSTRIKE, CULINECHBAR) (the two options are identical and are simply aliases)

--enable-citation-markup or --enforce-auto-mbox

Protect citation commands and other vulnerable commands in changed sections  with \mbox command, i.e. use default behaviour for ulem package for other packages (the two options are identical and are simply aliases)

### Miscellaneous

--verbose or -V

Output various status information to stderr during processing. Default is to work silently.

--driver=type

Choose driver for changebar package (only relevant for styles using
changebar: CCHANGEBAR CFONTCHBAR CULINECHBAR CHANGEBAR). Possible drivers are listed in changebar manual, e.g. pdftex,dvips,dvitops
[Default: dvips]

--ignore-warnings

Suppress warnings about inconsistencies in length between input and parsed strings and missing characters.  These warning messages are often related to non-standard latex or latex constructions with a syntax unknown to latexdiff but the resulting difference argument is often fully functional anyway, particularly if the non-standard latex only occurs in parts of the text which have not changed.

--label=label or -L label

Sets the labels used to describe the old and new files.  The first use of this option sets the label describing the old file and the second use of the option sets the label for the new file, i.e. set both labels like this -L labelold -L labelnew. [Default: use the filename and modification dates for the label]

--no-label

Suppress inclusion of old and new file names as comment in output file

--visible-label

Include old and new filenames (or labels set with --label option) as  visible output.

--flatten

Replace \input and \include commands within body by the content of the files in their argument.  If \includeonly is present in the preamble, only those files are expanded into the document. However,  no recursion is done, i.e. \input and \include commands within  included sections are not expanded.  The included files are assumed to
be located in the same directories as the old and new master files, respectively, making it possible to organise files into old and new directories.  --flatten is applied recursively, so inputted files can contain further \input statements.

Use of this option might result in prohibitive processing times for larger documents, and the resulting difference document no longer reflects the structure of the input documents.

--help or -h

Show help text

--version

Show version number

### Internal options

These options are mostly for automated use by latexdiff-vc. They can be used directly, but the API should be considered less stable than for the other options.

Suppress generation of hyperreferences, used for minimal diffs (option --only-changes of latexdiff-vc)

### Major types

The major type determine the markup of plain text and some selected latex commands outside floats by defining the markup commands \DIFadd{...} and \DIFdel{...} .

UNDERLINE

Added text is wavy-underlined and blue, discarded text is struck out and red (Requires color and ulem packages).  Overstriking does not work in displayed math equations such that deleted parts of equation are underlined, not struck out (this is a shortcoming inherent to the ulem package).

Added text is blue and set in sans-serif, and a red footnote is created for each discarded  piece of text. (Requires color package)

Like CTRADITIONAL but without the use of color.

CFONT

Added text is blue and set in sans-serif, and discarded text is red and very small size.

FONTSTRIKE

Added tex is set in sans-serif, discarded text small and struck out

CCHANGEBAR

Added text is blue, and discarded text is red.  Additionally, the changed text is marked with a bar in the margin (Requires color and changebar packages).

CFONTCHBAR

Like CFONT but with additional changebars (Requires color and changebar packages).

CULINECHBAR

Like UNDERLINE but with additional changebars (Requires color, ulem and changebar packages).

CHANGEBAR

No mark up of text, but mark margins with changebars (Requires changebar package).

INVISIBLE

No visible markup (but generic markup commands will still be inserted.

BOLD

PDFCOMMENT

The pdfcomment package is used to underline new text, and mark deletions with a PDF comment. Note that this markup might appear differently or not at all based on the pdf viewer used. The viewer with best support for pdf markup is probably acroread. This style is only recommended if the number of differences is small.

### Subtypes

The subtype defines the commands that are inserted at the begin and end of added or discarded blocks, irrespectively of whether these blocks contain text or commands (Defined commands: \DIFaddbegin, \DIFaddend, \DIFdelbegin, \DIFdelend)

SAFE

MARGIN

Mark beginning and end of changed blocks with symbols in the margin nearby (using the standard \marginpar command - note that this sometimes moves somewhat from the intended position.

COLOR

An alternative way of marking added passages in blue, and deleted ones in red. (It is recommeneded to use instead the main types to effect colored markup, although in some cases coloring with dvipscol can be more complete, for example  with citation commands).

DVIPSCOL

An alternative way of marking added passages in blue, and deleted ones in red. Note that DVIPSCOL only works with the dvips converter, e.g. not pdflatex. (it is recommeneded to use instead the main types to effect colored markup, although in some cases coloring with dvipscol can be more complete).

ZLABEL

can be used to highlight only changed pages, but requires post-processing. It is recommend to not call this option manually but use latexdiff-vc with --only-changes option. Alternatively, use the script given within preamble of diff files made using this style.

ONLYCHANGEDPAGE

also highlights changed pages, without the need for post-processing, but might not work reliably if there is floating material (figures, tables).

LABEL

is similar to ZLABEL, but does not need the zref package and works less reliably (deprecated).

### Float Types

Some of the markup used in the main text might cause problems when used within  floats (e.g. figures or tables).  For this reason alternative versions of all markup commands are used within floats. The float type defines these alternative commands.

FLOATSAFE

Use identical markup for text as in the main body, but set all commands marking the begin and end of changed blocks to null-commands.  You have to choose this float type if your subtype is MARGIN as \marginpar does not work properly within floats.

Mark additions the same way as in the main text.  Deleted environments are marked by angular brackets $and$ and the deleted text is set in scriptscript size. This float type should always be used with the TRADITIONAL and  CTRADITIONAL markup types as the \footnote command does not work properly in floating environments.

IDENTICAL

Make no difference between the main text and floats.

### Configuration Variables

ARRENV

If a match to ARRENV is found within an inline math environment within a deleted or added block, then the inlined math  is surrounded by \mbox{...}.  This is necessary as underlining does not work within inlined array environments.

[ Default: ARRENV=(?:array|[pbvBV]matrix)

COUNTERCMD

If a command in a deleted block which is also in the textcmd list matches COUNTERCMD then an additional command \addtocounter{cntcmd}{-1}, where cntcmd is the matching command, is appended in the diff file such that the numbering in the diff file remains synchronized with the numbering in the new file.

[ Default: COUNTERCMD=(?:footnote|part|section|subsection ...

|subsubsection|paragraph|subparagraph)  ]

CUSTOMDIFCMD

This option is for advanced users and allows definition of special versions of commands, which do not work as safe commands.

Commands in CUSTOMDIFCMD that occur in added or deleted blocks will be given an ADD or DEL prefix. The prefixed versions of the command must be defined in the preamble, either by putting them  in the preamble of at least the new file, or by creating a custom preamble file (Option --preamble). For example the command \blindtext (from package blindtext) does not interact well with underlining, so that  for the standard markup type, it is not satisfactory to define it as a safe command. Instead, a customised versions without underlining can be defined in the preamble:

\newcommand{\DELblindtext}{{\color{red}\blindtext}}

\newcommand{\ADDblindtext}{{\color{blue}\blindtext}}

and then latexdiff should be invoked with the option -c CUSTOMDIFCMD=blindtext.

[ Default: none ]

FLOATENV

Environments whose name matches the regular expression in FLOATENV are  considered floats.  Within these environments, the latexdiff markup commands are replaced by their FL variaties.

[ Default: (?:figure|table|plate)[\w\d*@]* ]

ITEMCMD

Commands representing new item line with list environments.

[ Default: \item ]

LISTENV

Environments whose name matches the regular expression in LISTENV are list environments.

[ Default: (?:itemize|enumerate|description) ]

MATHENV,MATHREPL

If both \begin and \end for a math environment (environment name matching MATHENV or $and$) are within the same deleted block, they are replaced by a \begin and \end commands for MATHREPL rather than being commented out.

[ Default: MATHENV=(?:displaymath|equation) , MATHREPL=displaymath ]

MATHARRENV,MATHARRREPL

as MATHENV,MATHREPL but for equation arrays

[ Default: MATHARRENV=eqnarray\*? , MATHREPL=eqnarray ]

MINWORDSBLOCK

Minimum number of tokens required to form an independent block. This value is used in the algorithm to detect changes of complete blocks by merging identical text parts of less than MINWORDSBLOCK to the preceding added and discarded parts.

[ Default: 3 ]

PICTUREENV

Within environments whose name matches the regular expression in PICTUREENV all latexdiff markup is removed (in pathologic cases this might lead to inconsistent markup but this situation should be rare).

[ Default: (?:picture|DIFnomarkup)[\w\d*@]* ]

SCALEDELGRAPHICS

If --graphics-markup=both is chosen, SCALEDELGRAPHICS is the factor, by which deleted figures will be scaled (i.e. 0.5 implies they are shown at half linear size).

[ Default: 0.5 ]

VERBATIMENV

RegEx describing environments like verbatim, whose contents should be taken verbatim. The content of these environments will not be processed in any way:  deleted content is commented out, new content is not marked up

[ Default:  comment  ]

VERBATIMLINEENV

RegEx describing environments like verbatim, whose contents should be taken verbatim. The content of environments described by VERBATIMLINEENV are compared in  line mode, and changes are marked up using the listings package. The markup style is set based on the chosen mains markup type (Option -t), or on an analysis of the preamble. Note that “listings.sty” must be installed. If this file is not found the fallback solution is to  treat VERBATIMLINEENV environments treated exactly the same way as VERBATIMENV environments.

[ Default:  (?:verbatim[*]?|lstlisting  ]

## Common Problems and FAQ

Citations result in overfull boxes

There is an incompatibility between the ulem package, which latexdiff uses for underlining and striking out in the UNDERLINE style, the default style, and the way citations are generated. In order to be able to mark up citations properly, they are enclosed with an \mbox  command. As mboxes cannot be broken across lines, this procedure frequently results in overfull boxes, possibly obscuring the content as it extends beyond the right margin.  The same occurs for some other packages (e.g., siunitx). If this is a problem, you have two possibilities.

1. Use CFONT type markup (option -t CFONT): If this markup is chosen, then changed citations are no longer marked up with the wavy line (additions) or struck out (deletions), but are still highlighted in the appropriate color, and deleted text is shown with a different font. Other styles not using the ulem package will also work.

2. Choose option --disable-citation-markup which turns off the marking up of citations: deleted citations are no longer shown, and added citations are shown without markup. (This was the default behaviour of latexdiff at versions 0.6 and older)

For custom packages you can define the commands which need to be protected by \mbox with --append-mboxsafecmd and --excludemboxsafecmd options (submit your lists of command as feature request at github page to set the default behaviour of future versions, see section 6)

Changes in complicated mathematical equations result in latex processing errors

Try options --math-markup=whole.   If even that fails, you can turn off mark up for equations with --math-markup=off.

How can I just show the pages where changes had been made

Use options --s ZLABEL  (some postprocessing required) or -s ONLYCHANGEDPAGE. latexdiff-vc --ps|--pdf with --only-changes option takes care of the post-processing for you (requires zref package to be installed).

## Bugs

Option allow-spaces not implemented entirely consistently. It breaks the rules that number and type of white space does not matter, as different numbers of inter-argument spaces are treated as significant.

Please submit bug reports using the issue tracker of the github repository page https://github.com/ftilmann/latexdiff.git,  or send them to tilmann — AT — gfz-potsdam.de.  Include the version number of latexdiff (from comments at the top of the source or use --version).  If you come across latex files that are error-free and conform to the specifications set out above, and whose differencing still does not result in error-free latex, please send me those files, ideally edited to only contain the offending passage as long as that still reproduces the problem. If your  file relies on non-standard class files, you must include those.  I will not look at examples where I have trouble to latex the original files.

latexrevise, latexdiff-vc

## Portability

latexdiff does not make use of external commands and thus should run on any platform  supporting Perl 5.6 or higher.  If files with encodings  other than ASCII or UTF-8 are processed, Perl 5.8 or higher is required.

The standard version of latexdiff requires installation of the Perl package Algorithm::Diff` (available from www.cpan.org -  http://search.cpan.org/~nedkonz/Algorithm-Diff-1.15) but a stand-alone version, latexdiff-so, which has this package inlined, is available, too. latexdiff-fast requires the diff command to be present.

## Author

Version 1.3.0 Copyright (C) 2004-2018 Frederik Tilmann

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3

Contributors of fixes and additions: V. Kuhlmann, J. Paisley, N. Becker, T. Doerges, K. Huebner,  T. Connors, Sebastian Gouezel and many others. Thanks to the many people who sent in bug reports, feature suggestions, and other feedback.

## Info

2018-10-07 perl v5.22.1


text:
# Bayes, three tests, probability patient has disease if exactly two come out positive

I know how to apply Bayes Theorem to determine the likelihood a patient has a given disease if multiple trials return a positive result. In this case, if two trials both return positive:

$$P(\text{User}\mid++) = \frac{P(\text{User})P(+\mid\text{User})^2}{P(\text{User})P(+\mid\text{User})^2+(1 − P(\text{User})) P(+\mid\neg\text{User})^2}$$

However, how could I modify the above formula if one conducts three trials, and exactly two tests come out positive? What would be the likelihood that the patient has the disease then?

I would assume that $_3C_2$ comes into play as well, but I'm lost as to how to incorporate the negative result into the probability calculation.

• So "User" means a patient who has a given disease? – Michael Hardy Sep 18 '18 at 0:28

I would assume that $^3\mathrm C_2$ comes into play as well,
To shorten typesetting, let $U$ be the event of the subject being a user (???), $S$ be the count of positive test results among three tests (which are presumed to be conditionally iid for a given subject, each with conditional probabilities $P(T\mid U)$ and $P(T\mid \neg U)$ ).
\begin{align}\mathsf P(U\mid S=2) &=\dfrac{\mathsf P(S=2\mid U)~\mathsf P(U)}{\mathsf P(S=2\mid U)~\mathsf P(U)+\mathsf P(S=2\mid \neg U)~\mathsf P(\neg U)}\\[1ex]&= \dfrac{^3\mathrm C_2\mathsf P(T\mid U)^2~\mathsf P(\neg T\mid U)~\mathsf P(U)}{^3\mathrm C_2\mathsf P(T\mid U)^2~\mathsf P(\neg T\mid U)~\mathsf P(U)+^3\mathrm C_2\mathsf P(T\mid \neg U)^2~\mathsf P(\neg T\mid\neg U)~\mathsf P(\neg U)}\\[1ex]&= \dfrac{\mathsf P(T\mid U)^2(1-\mathsf P(T\mid U))~\mathsf P(U)}{\mathsf P(T\mid U)^2(1-\mathsf P(T\mid U))~\mathsf P(U)+\mathsf P(T\mid \neg U)^2(1-\mathsf P(T\mid\neg U))(1-\mathsf P(\neg U))}\end{align}


text:
Change the chapter
Question
The electric field created by two parallel metal plates is shown above. Where will the electric field be strongest?
1. Point A
2. Point B
3. Point C
4. Same at all points
Question Image
Solution Video


text:
# The pH of a solution of Mg(OHJz is measured as 10.0 and the Ksp of Mg(OH)z is 5.6x 10-12 moles?/L3,

###### Question:

The pH of a solution of Mg(OHJz is measured as 10.0 and the Ksp of Mg(OH)z is 5.6x 10-12 moles?/L3, Calculate the concentration of Mg2+ millimoles/L. Note that mole 1000 millimoles

#### Similar Solved Questions

##### 21 +41 = /" +3e +)=te' +2
21 +41 = /" +3e +)=te' + 2...
##### Evaluate $\int_{0}^{\infty} \frac{\sqrt{x} \ln x d x}{(1+x)^{2}}$ by using the contour of Figure 7.4 Hint: Along $D E, z=r e^{2 \pi i}$ so $\ln z=\ln r+2 \pi i$
Evaluate $\int_{0}^{\infty} \frac{\sqrt{x} \ln x d x}{(1+x)^{2}}$ by using the contour of Figure 7.4 Hint: Along $D E, z=r e^{2 \pi i}$ so $\ln z=\ln r+2 \pi i$...
##### You are interested in seeing whether gender andplaying a sport in high school are independent. You collect thefollowing data from a random sample of high schoolstudents:Plays sport in schoolPlays sport not in schoolDoes not play a sportMale251345Female18842Test an appropriate hypothesis to decide whether thevalues are indeed independent.
You are interested in seeing whether gender and playing a sport in high school are independent. You collect the following data from a random sample of high school students: Plays sport in school Plays sport not in school Does not play a sport Male 25 13 45 Female 18 8 42 Test an appropriate hypothes...
##### Fluid in Motion 8th edition Serway and Uville Assignment Submission For this assignment, you submit answers...
Fluid in Motion 8th edition Serway and Uville Assignment Submission For this assignment, you submit answers by question parts. The number of submissions remaining for each question part only changes if you submit or change the answer. Assignment Scoring Your best submission for each question part is...
##### A $p$ value indicatesa. the number of individuals in the control group.b. the probability that the same results in the experiment would occur by chance.c. the amount of variation in the data.d. the importance of the hypothesis.
A $p$ value indicates a. the number of individuals in the control group. b. the probability that the same results in the experiment would occur by chance. c. the amount of variation in the data. d. the importance of the hypothesis....
##### PlanResourceEvaluate the following integral.ble Resour5 cos sin 1/2doe Options5 cos 1 + sin 2 0 d0-LN 1/2 (Type an exact answer: Use parentheses to clearly denote the argument of each functiornication
Plan Resource Evaluate the following integral. ble Resour 5 cos sin 1/2 do e Options 5 cos 1 + sin 2 0 d0-LN 1/2 (Type an exact answer: Use parentheses to clearly denote the argument of each functior nication...
##### If the energy of 4.00 mole of photons is 475 kJ, what is the wavelength of each photon(in = h =6.626 x 10 "Js photon
If the energy of 4.00 mole of photons is 475 kJ, what is the wavelength of each photon(in = h =6.626 x 10 "Js photon...
##### Question 0f 6 (4 poants) AlemplVcwqucstlonRopup6,3 Section ExeraPer Capita Income of Delaware Residents In rccent year Delaware had the highest per capita annua ncome with 551,803. 54850, answer the fcllowing questions_ Assume that the sample taken from large populatlon and the correction (actor con be Ignored Rovng Intemmedlate valuc calculatlons declmal places and thc fInal answers to at Icast four decimal places-Part: 0 / 2Part Lol 2Uhatthe probability that Fandom sample 0 34 state [0"cc
Question 0f 6 (4 poants) Alempl Vcwqucstlon Ropup 6,3 Section Exera Per Capita Income of Delaware Residents In rccent year Delaware had the highest per capita annua ncome with 551,803. 54850, answer the fcllowing questions_ Assume that the sample taken from large populatlon and the correction (actor...
##### Use the power reduction formulasNetfinaexortsslor (Hint: Your Hns er shovldcontain any exponents greater than 1 )sin" (4x)Recall the powrer re ducton rarmulisin?(0) and that sin"(0) sin (0)
Use the power reduction formulas Netfina exortsslor (Hint: Your Hns er shovld contain any exponents greater than 1 ) sin" (4x) Recall the powrer re ducton rarmuli sin?(0) and that sin"(0) sin (0)...
##### Formula forifilka) at anyl pointi 01 IIndeed the process ofiltaking the derivativell generates a new function; denoted by f' (r) derived from the original function f(c)Preview Activity 1.4.1. Consider the function f(c) 4c T2 Use the limit definition to compute the derivative values: f' (0). f' (1) f' (2). and f' (3) b Observe that the work to find f' (a) is the same, regardless of the value of a. Based on your work in (a), what do You conjecture is the value of f&
formula forifilka) at anyl pointi 01 IIndeed the process ofiltaking the derivativell generates a new function; denoted by f' (r) derived from the original function f(c) Preview Activity 1.4.1. Consider the function f(c) 4c T2 Use the limit definition to compute the derivative values: f' (...
##### Two uniformly charged nfnite nonccncucbno plancs arc Ferallci indthc pcint thcx aisatx I cm? {Ain: Usc G1u55JY Plarc ard postioned at * -42 cmand * a Cm ATracharondensib @I olhnac SMMc dctcminc the dccbie ficld in 04on Iccon 0lajacc )DaraenOm?, respectively: What is tFe magnitudFFcocrtentia cuicrencc benecn tFc oricnNumbiFCim"
Two uniformly charged nfnite nonccncucbno plancs arc Ferallci indthc pcint thcx aisatx I cm? {Ain: Usc G1u55 JY Plarc ard postioned at * -42 cmand * a Cm ATracharondensib @I olhnac SMMc dctcminc the dccbie ficld in 04on Iccon 0lajacc ) Darae nOm?, respectively: What is tFe magnitud FFcocrtentia cuic...
##### Feolud 5251 - Exam 1 Name: (30 points) For the circuit shown, V,= 0.7 V. (a)...
Feolud 5251 - Exam 1 Name: (30 points) For the circuit shown, V,= 0.7 V. (a) Find Vo and Id. (b) Explain why your assumption about the state of the diode was correct. wwwww olo ww 10 k92...
##### In Exercises $41-48,$ use Theorem 20 to find the series' interval of convergence and, within this interval, the sum of the series as a function of $x .$ $\sum_{n=0}^{\infty}(\ln x)^{n}$
In Exercises $41-48,$ use Theorem 20 to find the series' interval of convergence and, within this interval, the sum of the series as a function of $x .$ $\sum_{n=0}^{\infty}(\ln x)^{n}$...
##### Financial data for Joel de Paris, Inc., for last year follow: Joel de Paris, Inc. Balance...
Financial data for Joel de Paris, Inc., for last year follow: Joel de Paris, Inc. Balance Sheet Beginning Balance Ending Balance Assets Cash $130,000$ 139,000 Accounts receivable 344,000 486,000 Inventory 565,000 473,000 Plant and equipment, net 821,000 802,000 Inv...
##### Point) Which of the following statcments Tre tnuetIf the augmented matrix 1bpivot position eveN' rw then the equation AxinconsisteniThe solution set of linenr syalom whose auqmented matrixE01 42 (3 b | is the same the solution set of Ax = b, IA -[0 0 43the oquatlon AxInconsistont; IhenIne sot spannod by thu columns ofA,The equation Ax =consistent the augmented matrix Ab hnse pivot position every [Ow:Aisan mmatrix whose columns do not span Rm_ Ihen thu equation AxIs inconsistent for some b
point) Which of the following statcments Tre tnuet If the augmented matrix 1b pivot position eveN' rw then the equation Ax inconsisteni The solution set of linenr syalom whose auqmented matrixE 01 42 (3 b | is the same the solution set of Ax = b, IA -[0 0 43 the oquatlon Ax Inconsistont; Ihen ...
##### 11.) (12 pts) A-3.0 nC charge in on the x-axis at x =-9 cm and a...
11.) (12 pts) A-3.0 nC charge in on the x-axis at x =-9 cm and a +4.0 nC charge is at x = 16 cm. B. At what point or points on the x axis is the electric field zero?...
##### 3,oyCondox nubet Uetn snty U alocucu (iculls Mecarinnci 74r z Find Ia vulue Unuen trMtme70 + Fa MAat Fannhutmn Vwn Icruentnt
3,oy Condox nubet Uetn snty U alocucu (iculls Mecarinnci 74r z Find Ia vulue Unuen tr Mtme 70 + Fa MAat Fa nnhutmn Vwn Icru entnt...
##### Two different isosceles triangles with perimeter 4a+b
Two different isosceles triangles with perimeter 4a+b?Is this a right angle isosceles triangle?...
##### A claim put forth by some purveyors of health foods is that vitamins obtained from natural...
A claim put forth by some purveyors of health foods is that vitamins obtained from natural sources are more healthful than those obtained by chemical synthesis. For example, pure L-ascorbic acid (vitamin C) extracted from rose hips is thought to be healthier than pure L-ascorbic acid manufactured in...
Write neat please. Show step by step please. Read instructions carefully. do all problems please. double check your work. Box in answer please. Thank you Question 25 1 pts A volume of air has temperature of O°C. An equal volume of air that is twice as hot has a temperature of O2°C O ...
##### Solve the double inequality $-t_{alpha / 2, n-2}<t<t_{alpha / 2, n-2}$ with $t$ given by the formula of Exercise 25 so that the middle term is $y_{0}$ and the two limits can be calculated without knowledge of $y_{0}$. Note that although the resulting double inequality may be interpreted like a confidence interval, it is not designed to estimate a parameter; instead, it provides limits of prediction for a future observation of $Y$ that corresponds to the (given or observed) value $x_{0}$.
Solve the double inequality $-t_{alpha / 2, n-2}<t<t_{alpha / 2, n-2}$ with $t$ given by the formula of Exercise 25 so that the middle term is $y_{0}$ and the two limits can be calculated without knowledge of $y_{0}$. Note that although the resulting double inequality may be interpreted like a...
##### Required information The following information applies to the questions displayed below.) Starbooks Corporation provides an online...
Required information The following information applies to the questions displayed below.) Starbooks Corporation provides an online bookstore for electronic books. The following is a simplified list of accounts and amounts reported in its accounting records. The accounts have normal debit or credit b...
##### 3. Suppose that X1, X2, , Xn are independent random variables with the same expectation μ...
3. Suppose that X1, X2, , Xn are independent random variables with the same expectation μ and the same variance σ2. Let X--ΣΑι Xi. Find the expectation and variance of...


text:
# NAG Library Routine Document

## 1Purpose

f08yxf (ztgevc) computes some or all of the right and/or left generalized eigenvectors of a pair of complex upper triangular matrices $\left(A,B\right)$.

## 2Specification

Fortran Interface
 Subroutine f08yxf ( side, n, a, lda, b, ldb, vl, ldvl, vr, ldvr, mm, m, work, info)
 Integer, Intent (In) :: n, lda, ldb, ldvl, ldvr, mm Integer, Intent (Out) :: m, info Real (Kind=nag_wp), Intent (Out) :: rwork(2*n) Complex (Kind=nag_wp), Intent (In) :: a(lda,*), b(ldb,*) Complex (Kind=nag_wp), Intent (Inout) :: vl(ldvl,*), vr(ldvr,*) Complex (Kind=nag_wp), Intent (Out) :: work(2*n) Logical, Intent (In) :: select(*) Character (1), Intent (In) :: side, howmny
#include nagmk26.h
 void f08yxf_ (const char *side, const char *howmny, const logical sel[], const Integer *n, const Complex a[], const Integer *lda, const Complex b[], const Integer *ldb, Complex vl[], const Integer *ldvl, Complex vr[], const Integer *ldvr, const Integer *mm, Integer *m, Complex work[], double rwork[], Integer *info, const Charlen length_side, const Charlen length_howmny)
The routine may be called by its LAPACK name ztgevc.

## 3Description

f08yxf (ztgevc) computes some or all of the right and/or left generalized eigenvectors of the matrix pair $\left(A,B\right)$ which is assumed to be in upper triangular form. If the matrix pair $\left(A,B\right)$ is not upper triangular then the routine f08xsf (zhgeqz) should be called before invoking f08yxf (ztgevc).
The right generalized eigenvector $x$ and the left generalized eigenvector $y$ of $\left(A,B\right)$ corresponding to a generalized eigenvalue $\lambda$ are defined by
 $A-λBx=0$
and
 $yH A-λ B=0.$
If a generalized eigenvalue is determined as $0/0$, which is due to zero diagonal elements at the same locations in both $A$ and $B$, a unit vector is returned as the corresponding eigenvector.
Note that the generalized eigenvalues are computed using f08xsf (zhgeqz) but f08yxf (ztgevc) does not explicitly require the generalized eigenvalues to compute eigenvectors. The ordering of the eigenvectors is based on the ordering of the eigenvalues as computed by f08yxf (ztgevc).
If all eigenvectors are requested, the routine may either return the matrices $X$ and/or $Y$ of right or left eigenvectors of $\left(A,B\right)$, or the products $ZX$ and/or $QY$, where $Z$ and $Q$ are two matrices supplied by you. Usually, $Q$ and $Z$ are chosen as the unitary matrices returned by f08xsf (zhgeqz). Equivalently, $Q$ and $Z$ are the left and right Schur vectors of the matrix pair supplied to f08xsf (zhgeqz). In that case, $QY$ and $ZX$ are the left and right generalized eigenvectors, respectively, of the matrix pair supplied to f08xsf (zhgeqz).

## 4References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Moler C B and Stewart G W (1973) An algorithm for generalized matrix eigenproblems SIAM J. Numer. Anal. 10 241–256
Stewart G W and Sun J-G (1990) Matrix Perturbation Theory Academic Press, London

## 5Arguments

1:     $\mathbf{side}$ – Character(1)Input
On entry: specifies the required sets of generalized eigenvectors.
${\mathbf{side}}=\text{'R'}$
Only right eigenvectors are computed.
${\mathbf{side}}=\text{'L'}$
Only left eigenvectors are computed.
${\mathbf{side}}=\text{'B'}$
Both left and right eigenvectors are computed.
Constraint: ${\mathbf{side}}=\text{'B'}$, $\text{'L'}$ or $\text{'R'}$.
2:     $\mathbf{howmny}$ – Character(1)Input
On entry: specifies further details of the required generalized eigenvectors.
${\mathbf{howmny}}=\text{'A'}$
All right and/or left eigenvectors are computed.
${\mathbf{howmny}}=\text{'B'}$
All right and/or left eigenvectors are computed; they are backtransformed using the input matrices supplied in arrays vr and/or vl.
${\mathbf{howmny}}=\text{'S'}$
Selected right and/or left eigenvectors, defined by the array select, are computed.
Constraint: ${\mathbf{howmny}}=\text{'A'}$, $\text{'B'}$ or $\text{'S'}$.
3:     $\mathbf{select}\left(*\right)$ – Logical arrayInput
Note: the dimension of the array select must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{howmny}}=\text{'S'}$, and at least $1$ otherwise.
On entry: specifies the eigenvectors to be computed if ${\mathbf{howmny}}=\text{'S'}$. To select the generalized eigenvector corresponding to the $j$th generalized eigenvalue, the $j$th element of select should be set to .TRUE..
Constraint: if ${\mathbf{howmny}}=\text{'S'}$, ${\mathbf{select}}\left(\mathit{j}\right)=\mathrm{.TRUE.}$ or $\mathrm{.FALSE.}$, for $\mathit{j}=1,2,\dots ,n$.
4:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrices $A$ and $B$.
Constraint: ${\mathbf{n}}\ge 0$.
5:     $\mathbf{a}\left({\mathbf{lda}},*\right)$ – Complex (Kind=nag_wp) arrayInput
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the matrix $A$ must be in upper triangular form. Usually, this is the matrix $A$ returned by f08xsf (zhgeqz).
6:     $\mathbf{lda}$ – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f08yxf (ztgevc) is called.
Constraint: ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
7:     $\mathbf{b}\left({\mathbf{ldb}},*\right)$ – Complex (Kind=nag_wp) arrayInput
Note: the second dimension of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the matrix $B$ must be in upper triangular form with non-negative real diagonal elements. Usually, this is the matrix $B$ returned by f08xsf (zhgeqz).
8:     $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f08yxf (ztgevc) is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
9:     $\mathbf{vl}\left({\mathbf{ldvl}},*\right)$ – Complex (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array vl must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{side}}=\text{'R'}$.
On entry: if ${\mathbf{howmny}}=\text{'B'}$ and ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, vl must be initialized to an $n$ by $n$ matrix $Q$. Usually, this is the unitary matrix $Q$ of left Schur vectors returned by f08xsf (zhgeqz).
On exit: if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, vl contains:
• if ${\mathbf{howmny}}=\text{'A'}$, the matrix $Y$ of left eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{howmny}}=\text{'B'}$, the matrix $QY$;
• if ${\mathbf{howmny}}=\text{'S'}$, the left eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the columns of the array vl, in the same order as their corresponding eigenvalues.
10:   $\mathbf{ldvl}$ – IntegerInput
On entry: the first dimension of the array vl as declared in the (sub)program from which f08yxf (ztgevc) is called.
Constraints:
• if ${\mathbf{side}}=\text{'L'}$ or $\text{'B'}$, ${\mathbf{ldvl}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{side}}=\text{'R'}$, ${\mathbf{ldvl}}\ge 1$.
11:   $\mathbf{vr}\left({\mathbf{ldvr}},*\right)$ – Complex (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array vr must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{mm}}\right)$ if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$ and at least $1$ if ${\mathbf{side}}=\text{'L'}$.
On entry: if ${\mathbf{howmny}}=\text{'B'}$ and ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, vr must be initialized to an $n$ by $n$ matrix $Z$. Usually, this is the unitary matrix $Z$ of right Schur vectors returned by f08xef (dhgeqz).
On exit: if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, vr contains:
• if ${\mathbf{howmny}}=\text{'A'}$, the matrix $X$ of right eigenvectors of $\left(A,B\right)$;
• if ${\mathbf{howmny}}=\text{'B'}$, the matrix $ZX$;
• if ${\mathbf{howmny}}=\text{'S'}$, the right eigenvectors of $\left(A,B\right)$ specified by select, stored consecutively in the columns of the array vr, in the same order as their corresponding eigenvalues.
12:   $\mathbf{ldvr}$ – IntegerInput
On entry: the first dimension of the array vr as declared in the (sub)program from which f08yxf (ztgevc) is called.
Constraints:
• if ${\mathbf{side}}=\text{'R'}$ or $\text{'B'}$, ${\mathbf{ldvr}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{side}}=\text{'L'}$, ${\mathbf{ldvr}}\ge 1$.
13:   $\mathbf{mm}$ – IntegerInput
On entry: the number of columns in the arrays vl and/or vr.
Constraints:
• if ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, ${\mathbf{mm}}\ge {\mathbf{n}}$;
• if ${\mathbf{howmny}}=\text{'S'}$, mm must not be less than the number of requested eigenvectors.
14:   $\mathbf{m}$ – IntegerOutput
On exit: the number of columns in the arrays vl and/or vr actually used to store the eigenvectors. If ${\mathbf{howmny}}=\text{'A'}$ or $\text{'B'}$, m is set to n. Each selected eigenvector occupies one column.
15:   $\mathbf{work}\left(2×{\mathbf{n}}\right)$ – Complex (Kind=nag_wp) arrayWorkspace
16:   $\mathbf{rwork}\left(2×{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
17:   $\mathbf{info}$ – IntegerOutput
On exit: ${\mathbf{info}}=0$ unless the routine detects an error (see Section 6).

## 6Error Indicators and Warnings

${\mathbf{info}}<0$
If ${\mathbf{info}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.

## 7Accuracy

It is beyond the scope of this manual to summarise the accuracy of the solution of the generalized eigenvalue problem. Interested readers should consult Section 4.11 of the LAPACK Users' Guide (see Anderson et al. (1999)) and Chapter 6 of Stewart and Sun (1990).

## 8Parallelism and Performance

f08yxf (ztgevc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

f08yxf (ztgevc) is the sixth step in the solution of the complex generalized eigenvalue problem and is usually called after f08xsf (zhgeqz).
The real analogue of this routine is f08ykf (dtgevc).

## 10Example

This example computes the $\alpha$ and $\beta$ arguments, which defines the generalized eigenvalues and the corresponding left and right eigenvectors, of the matrix pair $\left(A,B\right)$ given by
 $A = 1.0+3.0i 1.0+4.0i 1.0+5.0i 1.0+6.0i 2.0+2.0i 4.0+3.0i 8.0+4.0i 16.0+5.0i 3.0+1.0i 9.0+2.0i 27.0+3.0i 81.0+4.0i 4.0+0.0i 16.0+1.0i 64.0+2.0i 256.0+3.0i$
and
 $B = 1.0+0.0i 2.0+1.0i 3.0+2.0i 4.0+3.0i 1.0+1.0i 4.0+2.0i 9.0+3.0i 16.0+4.0i 1.0+2.0i 8.0+3.0i 27.0+4.0i 64.0+5.0i 1.0+3.0i 16.0+4.0i 81.0+5.0i 256.0+6.0i .$
To compute generalized eigenvalues, it is required to call five routines: f08wvf (zggbal) to balance the matrix, f08asf (zgeqrf) to perform the $QR$ factorization of $B$, f08auf (zunmqr) to apply $Q$ to $A$, f08wsf (zgghrd) to reduce the matrix pair to the generalized Hessenberg form and f08xsf (zhgeqz) to compute the eigenvalues via the $QZ$ algorithm.
The computation of generalized eigenvectors is done by calling f08yxf (ztgevc) to compute the eigenvectors of the balanced matrix pair. The routine f08wwf (zggbak) is called to backward transform the eigenvectors to the user-supplied matrix pair. If both left and right eigenvectors are required then f08wwf (zggbak) must be called twice.

### 10.1Program Text

Program Text (f08yxfe.f90)

### 10.2Program Data

Program Data (f08yxfe.d)

### 10.3Program Results

Program Results (f08yxfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017


text:
# Experimental Probability Worksheets

Experimental Probability Worksheets
• Page 1
1.
A pair of dice is cast 20 times, and on 2 of these occasions, the sum of the numbers facing up is 5. What is the experimental probability of the outcome 5?
 a. 1 b. 0.1 c. 0.01 d. 10

#### Solution:

P(event) = Number of times an event happensNumber of trials made

P(outcome 5) = number of times sum 5 occuredtotal number of times dice thrown

= 220 = 110
[Simplify.]

The experimental probability of the outcome 5 is 110. .

2.
In a blub factory, 1000 bulbs were checked. Out of which 50 were found to be defective. What is the experimental probability a blub is defective?
 a. 6% b. 5% c. 15% d. 2%

#### Solution:

P(event) = Number of times an event happensNumber of trials made

P(defective bulb) = number of times "defective blub" occurstotal number of bulbs checked = 501000 = 5%.
[Simplify.]

The probability of a defective bulb is 5%.

3.
Annie planted 85 seeds out of which 17 were lemon seeds. Find the experimental probability of not choosing a lemon seed.
 a. $\frac{1}{85}$ b. $\frac{1}{9}$ c. $\frac{1}{5}$ d. $\frac{4}{5}$

#### Solution:

P(lemon seed) = Number of lemon seeds plantedTotal number of seeds planted

= 17 / 85 = 1 / 5
[Substitute and simplify.]

P(no lemon seed) = 1 - P(lemon seed)

= 1 - 1 / 5 = 4 / 5
[Substitute and simplify.]

Experimental probability of not choosing a lemon seed is 4 / 5.

4.
The table shows the data of the books sold by a bookstore on different subjects during the first week of June. Find the probability of selling a math book.

 a. 8 out of 43 b. 25 out of 129 c. 44 out of 129 d. 12 out of 129

#### Solution:

Total number of books sold during the week = 44 + 36 + 24 + 25 = 129
[Add the number of books in each subject.]

Number of math books sold = 44

P(math book) = Number of math books sold Total number of books sold = 44 / 129
[Substitute the values.]

The probability of selling a math book is 44 out of 129 .

5.
Find the probability of getting an odd number, when a number cube is rolled.
 a. 0.6 b. 0.5 c. 0.4 d. 0.71

#### Solution:

Number of favorable outcomes = number of odd numbers = 3.

Total number of possible outcomes = numbers on the cube = 6

Probability (getting an odd number) = Number of favorable outcomesTotal number of possible outcomes

= 36
[Simplify.]

= 12
[Convert fraction to decimal.]

= 0.5.
[Convert fraction to decimal.]

6.
Mary rolls a number cube. What is the probability of getting an even number?
 a. 0.5 b. 1 c. 1.5 d. 0.75

#### Solution:

Probability of getting an even number = Number of favorable eventsTotal number of events

Total number of events on rolling a number cube = { 1,2,3,4,5,6 } = 6.

Number of favorable events of getting an even number = { 2,4,6 } = 3.

Probability of getting an even number = 36
[Simplify.]

= 12
[Convert fraction to decimal.]

= 0.5

7.
There are 4 blackberries and 5 apples in a bag. If Tom picks a fruit at random from the bag, then what is the probability of the fruit being a blackberry?
 a. 0.25 b. 0.32 c. 0.49 d. 0.44

#### Solution:

Number of favorable outcomes = number of blackberries = 4.

Total number of possible outcomes = number of fruits = 9

Probability (getting a blackberry) = Number of favorable outcomes Total number of possible outcomes.

= 49
[Convert fraction to decimal.]

= 0.44

8.
Use a decimal to express the probability that L is selected from the word UMBRELLA.
 a. 0.75 b. 0.25 c. 0.5 d. 0.65

#### Solution:

Number of favorable outcomes = number of 'L' = 2.

Total number of possible outcomes = number of alphabets = 8

Probability (getting L) = Number of favorable outcomes Total number of possible outcomes

= 28
[Simplify.]

= 14
[Convert fraction to decimal.]

= 0.25

9.
What is the probability of getting a number, which is a multiple of 4 when the spinner is turned?

 a. 0.75 b. 0.5 c. 0.35 d. 0.25

#### Solution:

Number of favorable outcomes = Multiples of 4 = 2.

Total number of possible outcomes = Numbers on spinner = 8

Probability (getting a multiple of 4) = Number of favorable outcomes  Total number of possible outcomes

= 28
[Simplify.]

= 14
[Convert fraction to decimal.]

= 0.25

10.
What are the odds in favor of spinning yellow in the figure?

 a. 1 : 4 b. 1 : 2 c. 3 : 4 d. 1 : 1

#### Solution:

The odds in favor of an event = Number of favorable outcomes / Number of unfavorable outcomes

Number of favorable outcomes = 4
[Since there are 4 yellow colored sections in the spinner.]

Number of unfavorable outcomes = 8
[Since there are 8 sections colored other than yellow in the spinner.]

Odds in favor of spinning yellow = 4 / 8 = 1 : 2
[Substitute and simplify.]

So, the odds in favor of spinning yellow is 1 : 2.


text:
# Implementing a efficient Infix to Postfix using Shunting-yard algorithm

I was trying to implement an efficient (in terms of size of code (such as using one liners) and time and memory-efficient) of Infix to Postfix in python without the use of any external modules i.e using only inbuilt modules and with only necessary addition (such as without class to implement stack probably not needed).

Currently, my code looks like the following

operators={"+":1,"-":1,"*":2,"/":2,"^":3,"**":3,"(":4,")":4}

def InfixtoList(Infix):
NewInfix,tmp=[],""
for i in Infix:
if  i.isdigit() or i.isalpha():tmp+=i
else:NewInfix,tmp=NewInfix+([tmp,i] if tmp else [i]),""
NewInfix.append(tmp)
return NewInfix

def InfixToPostfix(infix):
infix=InfixtoList(infix)
for i in infix:
print(i,infix)
elif i=="(":stack.append(i)
elif i==")":
else:
stack.append(i)

Currently, it uses Shunting-yard algorithm i.e using stacks, without support for functions.

The function InfixtoList separates the operands and operators and put them in a list. The Code above works both for operands as digits or alphabet.

I am currently trying to make a better implementation of converting postfix to infix preferably using the same algorithm.

I was trying to implement an efficient (in terms of size of code and time and memory-efficient) of Infix to Postfix in python without the use of any modules and with only necessary parts (such as without class).

First of all, there is nothing intrinsically bad about classes. You should feel free to decide between object based programming or not based on the problem and your preferences. And I don't understand quite what you mean by "not using modules" - you're using lists and strings and all other types of Python standard library data models and functions.

# Efficiency

There's a saying by Donald Knuth that "about 97% of the time: premature optimization is the root of all evil." You should generally only attempt to optimise something once its performance impacts you (and you can quantify this!). And when you talk about optimisation, you also have to understand that there are trade-offs; optimising for speed/cycles will often mean that the algorithm requires more memory, and vice versa. I'd also argue that if you don't know the time and space complexity of your function you're not ready to optimise. It's also good to recognise that you optimise within a context - doing something in pure Python is only ever going to be so fast (Python is a high-level language with a lot of overhead).

Now, you also mention optimising for "size of code". This is not a good idea. Your script is currently 820 bytes. By shortening your indendations and your variable and function names I can get it down to 542 bytes (or less if I had the energy):

op={"+":1,"-":1,"*":2,"/":2,"^":3,"**":3,"(":4,")":4}
def itl(ix):
nix,t=[],""
for i in ix:
if i.isdigit() or i.isalpha():t+=i
else:nix,t=nix+([t,i] if t else [i]),""
nix.append(t)
return nix
def itpx(ix):
a,s=[],[]
ix=itl(ix)
for i in ix:
print(i,ix)
if i.isdigit() or i.isalpha():a.append(i)
elif i=="(":s.append(i)
elif i==")":
while s!=[] and s[-1]!="(":a.append(s.pop())
else:
while s!=[] and op[i]<=op[s[-1]]:a.append(s.pop())
s.append(i)
while s!=[]:a.append(s.pop())
return "".join(a).replace("(","")

Is this code better? I think you would agree that it isn't. You typically don't have to care about the length of your scripts - some hundred or even 10's of thousands of bytes are not going to matter on a modern computer. And if it did, you surely wouldn't be using Python. But there are a few things that we value very highly in the Python community, which you can summon in the interpreter:

\$ python3 -i
Python 3.7.6 (default, Jan  8 2020, 19:59:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Now, from this text you may be able to infer that we value readability and simplicity in Python. So what consistutes a good function or script is generally by how easily understandable it is. That brings us to the feedback area.

# Conventions and expectations

If I read Python code, I assume that the author is following PEP8 or some other established style convention (e.g. uses black). This typically means that constant (global) variables are uppercase, classes are PascalCase, variables are snake_case, and verbosity is almost exaggerated to guarantee that the code is easily understandable. Your code would look something like this:

from typing import List

OPERATOR_PRIORITY = {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3, "**": 3, "(": 4, ")": 4}

def separate_infixes(equation: str) -> List[str]:
infixes, tmp = [], ""
for symbol in equation:
if symbol.isdigit() or symbol.isalpha():
tmp += symbol
else:
infixes, tmp = infixes + ([tmp, symbol] if tmp else [symbol]), ""
infixes.append(tmp)
return infixes

def convert_infix_to_postfix(equation: str) -> str:
infixes = separate_infixes(equation)
for symbol in infixes:
print(symbol, infixes)
if symbol.isdigit() or symbol.isalpha():
elif symbol == "(":
stack.append(symbol)
elif symbol == ")":
while stack != [] and stack[-1] != "(":
else:
while (
stack != []
and OPERATOR_PRIORITY[symbol] <= OPERATOR_PRIORITY[stack[-1]]
):
stack.append(symbol)
while stack != []:

Now I think (hope?) you will agree that this is far more easily readable than the "length-optimised" version.

Always remember those words - they are, at least in my opinion, the most important part of the Zen of Python (aka PEP20). Write your code with a future reader in mind, because that reader will most of the time be yourself, and you will all too often stop to wonder what the idiotic author (who generally is yourself) had in mind when they wrote something up. Be overly clear with names, and use comments as well as docstrings.

# Other small bits

if i.isdigit() or i.isalpha(): tmp+=i

Although it's not exactly the same check, you can use str.isalnum().

while stack!=[]:answer.append(stack.pop())

Instead of checking if stack != [] you can just check if stack.

print(i,infix)

This looks like a "debugging print", i.e. something you used as an aide during development but which shouldn't be part of the function. You may want to get used to using a debugger in the future.

Now, with all of this done - as well as making the split-function internal just for good grace - we've ended up with something closer to:

from typing import List

OPERATOR_PRIORITY = {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3, "**": 3, "(": 4, ")": 4}

def convert_infix_to_postfix(equation: str) -> str:
"""Converts infix to postfix.

For example:
for infix expression x^y/(5*z)+2
the postfix form is xy^5/z*2+

Considers the operators: +, -, *, /, ^, **, (, and )
"""
def separate_symbols(string: str) -> List[str]:
"""Helper method."""
symbols = []
tmp = ""
for char in string:
if char.isalnum():
# store variables and digits in a string
tmp += char
else:
symbols = symbols + ([tmp, char] if tmp else [char])
tmp = ""
symbols.append(tmp)
return symbols

solution, stack = [], []
for symbol in separate_symbols(equation):
if symbol.isalnum() or symbol == "(":
solution.append(symbol)
elif symbol == ")":
while stack and not stack[-1] == "(":
solution.append(stack.pop())
else:
while stack and OPERATOR_PRIORITY[symbol] <= OPERATOR_PRIORITY[stack[-1]]:
solution.append(stack.pop())
stack.append(symbol)
solution += stack
return "".join(solution).replace("(", "")

There's still a tonne of improvements that can be made, but I hope I've managed to give you at least something to work based off. Now I don't feel like I have more time to spend on this, but the next two improvements that I'd personally look towards if I were you would be to add some basic tests, and to add docstrings that explain what the functions do, and maybe even add some examples.

• @FMc - I just searched for an infix to postfix function on google and took an arbitrary equation, which I arguably shouldn't have done. I don't, however, get any KeyError, but I do get the wrong results (even if they are consistent with the original script - xy^5/z*2+); can you show me where you get the KeyError?
Jan 10 at 16:23
• The main reason I mentioned avoiding the use of classes was that I do not think they are needed here just to create a stack object but they do come useful in certain conditions. by not using any modules I meant not importing external modules however I should have mentioned in the description. I think both time and space complexity are O(n) which probably cannot be changed however I think maybe there are better implementations that are more pythonic such uses one-liners Jan 10 at 18:53
• . This answer and the previous answer by Greedo seem to be focused on readability and style which did not think of but it is necessary. I will add a basic test and output case after some time. Jan 10 at 18:54
• Good code typically avoids one-liners unless they are for trivial operations, or otherwise just are easily understandable. Some of the examples in your link (f = lambda x: [[y for j, y in enumerate(set(x)) if (i >> j) & 1] for i in range(2**len(set(x)))]) are text-book examples of bad code. There are probably good list comprehensions that could be used over your implementation, but that's not what you should focus on, in my opinion.
Jan 10 at 18:58

Quick improvement*: put your code through an automatic formatter. Python has a guideline called PEP8 which gives recommendations on where to put linebreaks, spaces, how to name things consistently. I use black to format code since it is PEP8 compliant and does all the decision making for you so you can focus on more important things (it doesn't do everything - for example it won't change the names of your variables despite PEP8 having recommendations for even this).

Formatting code consistently makes it more readable (and thus maintainable) for you, and following a conventional approach like PEP8 makes it more readable for everyone else.

Formatting with black results in this:

operators = {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3, "**": 3, "(": 4, ")": 4}

def InfixtoList(Infix):
NewInfix, tmp = [], ""
for i in Infix:
if i.isdigit() or i.isalpha():
tmp += i
else:
NewInfix, tmp = NewInfix + ([tmp, i] if tmp else [i]), ""
NewInfix.append(tmp)
return NewInfix

def InfixToPostfix(infix):
infix = InfixtoList(infix)
for i in infix:
print(i, infix)
if i.isdigit() or i.isalpha():
elif i == "(":
stack.append(i)
elif i == ")":
while stack != [] and stack[-1] != "(":
else:
while stack != [] and operators[i] <= operators[stack[-1]]:
stack.append(i)
while stack != []:

Notice in particular:

• more space around the operators and between functions - less of a blob of characters.
• no compressed one-liner if statements: only one "thought" should be on each line.

You may not consider this "efficient (in terms of size of code...)" as it's now spread over more lines, however I would argue size of code isn't the aim, the aim is actually:

• simplicity and not-over engineered with unnecessary helper functions and abstract OOP.
• portable and easy to share in a single file / copy-paste.
• Quick and easy to read the entire thing.

... and re-formatting doesn't change any of those significantly, if at all. Performance is unrelated to formatting and I'm sure others will cover that aspect.

*Not really answer-worthy but too long for a comment

• I'm surprised the PEP8 style doesn't recommend against PascalCasing the variables. Jan 10 at 14:58
• @IEatBagels I said black was PEP8 compliant, but it is not a comprehensive implementation of the PEP8 guidelines, and will not for example re-case variables. I suppose this is because black only changes the appearance of code but not its meaning (enforced by comparing the AST/bytecode pre and post-formatting). Changing variable casing would modify your code's public API. I've updated my answer to clarify. You intuition is correct as PEP8 does in fact suggest snake_case for variables, functions and modules, PascalCase for classes and type aliases, YELLCASE_WITH_UNDERSCORES for constants. Jan 10 at 15:47
• By Size of code I was trying to referencing to better implementation such as list compression instead using For loop adding to empty list which has an impact on , however this is due to me not explain exactly I was trying to achieve small implementiation. I did not think of formatting or even know about PEP8 but I can see it is much beneficial from the past experience.Thanks for the answer it was really helpful Jan 10 at 17:48

First some problems. (1) Your tokenizing function tries to accomplish the task character by character, but that fails if any operators are multi-character. (2) The tokenizer fails if the input string contains spaces, which seems user-unfriendly. (3) Because it returns the hard-earned results as an non-delimited string, the infix-to-postfix conversion function destroys the knowledge gleaned during the tokenizing phase.

# Problem 1: parser mangles the ** operator.
input: 12**6
output: 12*6*

# Problem 2: parser cannot tolerate spaces.
input: 12**6
output: KeyError

# Problem 3: converter destroys information.
input: 12+11-6
output: 1211+6-   # 12 and 11 became 1211. Seems bad.

A more powerful tokenizing strategy that is still simple. One of the easiest ways to build a simple tokenizer is to define a regular expression for each token and then to consume the input string one token at a time. As long as we use basic care in ordering the tokens (for example, we must hunt for ** before *), this strategy is easy to implement and to enhance if requirements evolve. It also has the advantage of performing token-level validation, meaning that it will raise an error if the input string fails to consist entirely of valid tokens. Here's the idea:

import re

# Note that ** must occur before * in the dict.
OPERATORS = {
'(': 4,
')': 4,
'^': 3,
'**': 3,
'*': 2,
'/': 2,
'+': 1,
'-': 1,
}

# Our parser is just a regex defined as a bunch of alternatives:
# first the operators, then numbers/variables, and then whitespace.
PARSER = re.compile('|'.join(
[re.escape(o) for o in OPERATORS] +
[r'\w+', r'\s+']
))

def tokenize(infix):
# Tokenize until the string is exhausted.
# The i index tracks our current parsing location.
i = 0
STOP = len(infix)
while i < STOP:
m = PARSER.match(infix, pos = i)
if m:
tok = m.group(0)
i += len(tok)
# Yield only non-whitespace tokens.
if tok.strip():
yield tok
else:
raise ValueError(f'Invalid expression at position {i}: {infix!r}')

Your converter should be able to report unmatched parentheses. The shunting-yard algorithm is able to report parentheses problems, but you don't do that. In addition, other reviewers have noted a few other simplifications that can be made (eg, when checking for empty an stack) and have emphasized why cramped code is a bad idea. Here's an edited version of your code, with some comments mixed in to emphasize the key points:

def infix_to_postfix(infix):
postfix = []
stack = []
LEFT = '('
RIGHT = ')'
for tok in tokenize(infix):
# A simpler check for non-operator tokens.
if tok not in OPERATORS:
postfix.append(tok)
# Named constants can enhance readability.
elif tok == LEFT:
stack.append(tok)
elif tok == RIGHT:
# Simpler checks for empty stack.
while stack and stack[-1] != LEFT:
postfix.append(stack.pop())
if stack and stack[-1] == LEFT:
stack.pop()
else:
raise ValueError('Unmatched RIGHT')
else:
while stack and stack[-1] != LEFT and OPERATORS[tok] <= OPERATORS[stack[-1]]:
postfix.append(stack.pop())
stack.append(tok)
# An easier way to push the rest of the stack.
postfix.extend(reversed(stack))
# Final check for unmatched parentheses.
if LEFT in postfix:
raise ValueError('Unmatched LEFT')
# Return a list or tuple, not a string.
return postfix

• Thanks for mentioning problems against 1st function I will fix them. The provided infix_to_postfix function seems to be wrong as If you provided an expression with brackets such as (A+B)*C it raises Value error unmatched RIGHT since the stack is empty at if stack and stack[-1] == LEFT. Also, you are using f-strings with ValueError on the if blocks in infix_to_postfix is there a particular reason for it? Jan 11 at 7:30
• @WhoEvenCaresToSeeTheName Fixed: needed an additional check when dealing with operators (stop when hitting LEFT). If I were starting from scratch, I would not model parentheses as operators. They are different, and are treated differently than operators, for example, in the Wikipedia pseudocode.
– FMc
Jan 11 at 18:30