'''
Created on 01-Apr-2021
@author: rishi_priyansh
'''
import os 

import random
import inspect
import traceback
import sympy
from sympy import (simplify, sympify, log, 
                   symbols, Symbol, Function,
                   Add, Mul,
                   Eq, Matrix, latex, 
                   solve, Rational, diag,
                   Derivative, Integral,
                   UnevaluatedExpr as ueval
                   )

from xv.math.formulae import FormulaSet
from xv.util import list_to_str

from ..helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
from xv.km.util import latex_color, latex_fraction

# _additive_property_manager
# AdditivePropertyManager

        
class AdditivePropertyManager(BaseManager):
    '''
    AdditivePropertyManager


    Minimum Grade: 6
    Maximum Grade: 12


    Examples
    --------
    ke = AdditivePropertyManager()
    ke 
    
    ke.printProblemTypes()
    ke.helpProblemType(0)
    
    ke.getRandomProblem()
    ke.getRandomProblem(problem_type = 0)


    ke.printProblem()
    ke.printAnswer()
    ke.printSolution()


    doc_style: xv_doc
    ''' 
    
    def __new__(cls, *args, **kwargs):
        instance = super(AdditivePropertyManager, cls).__new__(cls, *args, **kwargs)
        for base_class in AdditivePropertyManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass
    

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_length',
            '_problem_force',
            '_problem_parallel_tension',
            '_problem_parallel_springs',
            '_problem_series_springs',
            '_problem_series_resistance',
            '_problem_parallel_resistance',
            '_problem_error',
            '_problem_polygon_vector',
            '_problem_position_vectors',
            '_problem_vector_derivatives',
            '_problem_current',
            '_problem_voltage_in_series',
            '_problem_parallel_capacitor',
            '_problem_series_capacitor',
            '_problem_momentum',
            '_problem_moment_of_inertia',
            '_problem_fluid_pressure',
            '_problem_electric_charge',
            '_problem_electric_field',
            '_problem_electric_field_formula',
            '_problem_electric_potential_energy_formula',
            '_problem_electric_potential_energy_formula_external_field',
            '_problem_parallel_inductance',
            '_problem_series_inductance',
            

            ])
        pass

    def _problem_length(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol('l')   
        vec_prop = Symbol(f'\\vec {{l}}')   
        result = ap_helper.get_simple_sum_data(prop, size)
        vec_result = ap_helper.get_simple_sum_data(vec_prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        If sticks of lengths {result['props_latex']} are joined together, 
        what is the resultant length?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html', 
                                    add_html_line_break = False)
        
        soln_stmts = []
        
        
        soln_stmt = f"""
        Assuming that the sticks are joined in a straight line,
        the resultant length when sticks of lengths 
        {result['props_latex']} are joined together:
        <br/>
        <br/>
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$
        <br/>
        see image::/images/physics/additive_property/additive_property_0001_a.png
        """
        soln_stmts.append(soln_stmt.replace("\n", " ").strip())
        
        soln_stmt = f"""
        If they are not joined in a straight line,
        the resultant length will be a vector value:
        <br/>
        <br/>
        $\\displaystyle {latex(vec_prop)} = {latex(vec_result['sum_props'])}$
        <br/>
        see image::/images/physics/additive_property/additive_property_0001_b.png
        <br/>
        In absence of any information, the second result is more appropriate.
        """
        soln_stmts.append(soln_stmt.replace("\n", " ").strip())
        
        
        soln_s = "\n\n".join(soln_stmts)
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(vec_prop)} = {latex(vec_result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_force(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{F}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        If forces {result['props_latex']} are acting on a mass, what will be the resultant force?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        The forces applied on a point follows simple vector addition rule.
        A mass if considered a point mass concentrated at its center of gravity and 
        the forces are acting on this point, we can do vector addition of forces. 
        Therefore, the resultant force 
        <br/>
        <br/>
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$
        <br/>
        see image::/images/physics/additive_property/additive_property_0002.png
        <br/>
        """
        
        problemTemplate.add_solution(soln_s.replace("\n", " ").strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_parallel_tension(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{T}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        If a particle is hanging by strings with tensions {result['props_latex']}, 
        what will be the resultant tension?
        """
        problemTemplate.add_problem(problem_s.replace("\n", " ").strip(), 'text/html')
        
        soln_s = f"""
        The tensions of the strings are forces on the particle. 
        So we can add them as vectors.
        Therefore, the resultant tension acting in parallel
        <br/>
        <br/>
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$
        <br/>
        see image::/images/physics/additive_property/additive_property_0003.png
        <br/>
        """
        
        problemTemplate.add_solution(soln_s.replace("\n", " ").strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    
    def _problem_parallel_springs(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        F = Symbol(f'\\vec {{F}}')   
        x = Symbol(f'\\vec {{x}}')  
        k = Symbol('k')   
        solve_for = random.choice([x, k])

        result = ap_helper.get_propotional_sum_data(F, x, k, size, 
                                                    solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        if solve_for == k:
            solve_for_text = f"What is the resultant spring constant?"
        else:
            solve_for_text = f"What is the resultant displacement?"
            
        
        problem_s =  f"""
        A load is hanging by springs with spring constants {result['add_props_latex']} 
        connected in parallel.
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.replace("\n", " ").strip(), 'text/html')
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The load is connected to all springs, and the total force it experiences 
        is the sum of forces exerted by each spring.
        <br/>
        The force by a spring in given by $\\displaystyle {latex(F)} = {latex(k * x)}$.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the displacement of each spring in parallel is same: 
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        soln_stmt =  f"""
        see image::/images/physics/additive_property/additive_property_0004.png
        """
        soln_stmts.append(soln_stmt)
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_series_springs(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        
        ap_helper = self.base_helper.get_additive_property_helper()
  
        size = random.randint(2, 5)
        F = Symbol('F')   
        x = Symbol('x')   
        k = Symbol('k')   
        solve_for = random.choice([x, k])

        result = ap_helper.get_inverse_sum_data(F, x, k, size,
                                                solve_for = solve_for)
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == k:
            solve_for_text = f"What is the resultant spring constant?"
        else:
            solve_for_text = f"What is the resultant displacement?"
            
        
        problem_s =  f"""
        A series of springs in a series with spring constants 
        {result['add_props_latex']}  are connected to a force 
        $\\displaystyle {latex(F)}$. 
        {solve_for_text} 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total displacement is sum of displacements across each spring in a series.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the force through each of the springs in a series must be same:
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        soln_stmt =  f"""
        see image::/images/physics/additive_property/additive_property_0005.png
        """
        soln_stmts.append(soln_stmt)
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
        
    def _problem_series_resistance(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        V = Symbol('V')   
        I = Symbol('I')   
        R = Symbol('R')   
        solve_for = random.choice([I, R])

        result = ap_helper.get_propotional_sum_data(V, I, R, size,
                                                    solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        if solve_for == I:
            solve_for_text = f"What will be the resultant current?"
        else:
            solve_for_text = f"What will be the resultant resistance? "
        
        problem_s =  f"""
        A circuit has resistances {result['add_props_latex']} in 
        a series connected to a voltage source $\\displaystyle {latex(V)}$. 
        {solve_for_text} 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)

        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_series_resistances(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total voltage is sum of voltages across each resistances in a series.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the current through each of the resistance in a series must be same: 
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_parallel_resistance(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        V = Symbol('V')   #V
        I = Symbol('I')   #I
        R = Symbol('R')   #R
        solve_for = random.choice([I, R])

        result = ap_helper.get_inverse_sum_data(V, I, R, size, 
                                                solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == I:
            solve_for_text = f"What will be the resultant current?"
        else:
            solve_for_text = f"What will be the resultant resistance? "
        
        problem_s =  f"""
        A circuit has resistances {result['add_props_latex']} in 
        parallel connected to a voltage source $\\displaystyle {latex(V)}$. 
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)

        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_parallel_resistances(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total current is sum of currents across each resistances in parallel.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the voltage through each of the resistances in parallel must be same:
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_error(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        measures = symbols('a b')
        measure_devs = [Symbol(f"\\Delta {item}") for item in measures]
        
        
        measures_latex = [f"${latex(item)}$" for item in measures]
        measures_latex = list_to_str(measures_latex, last_sep = ' and ')
        
        measure_devs_latex = [f"${latex(item)}$" for item in measure_devs]
        measure_devs_latex = list_to_str(measure_devs_latex, last_sep = ' and ')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        The measurements {measures_latex} have errors {measure_devs_latex} respectively.
        What could be the error in measure if both are measured together?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        If both are measured together, there could be four scenarios:
        
        $\\displaystyle
        = \\left \\{{
        \\begin{{aligned}}
        
        & + {latex(measure_devs[0])} + {latex(measure_devs[1])} \\\\
        & - {latex(measure_devs[0])} - {latex(measure_devs[1])} \\\\
        & + {latex(measure_devs[0])} - {latex(measure_devs[1])} \\\\
        & - {latex(measure_devs[0])} + {latex(measure_devs[1])} \\\\

        \\end{{aligned}}
        \\right .
        $
        
        $\\displaystyle
        = \\pm {latex(measure_devs[0])} \\pm {latex(measure_devs[1])}
        $
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle
        \\pm {latex(measure_devs[0])} \\pm {latex(measure_devs[1])}
        $
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_polygon_vector(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        size = random.randint(3, 8)
        var_list = list('ABCDEFGHIJKL')[:size]
        vertices = [f"{item}" for item in var_list]
        polygon_name = list_to_str(vertices, sep = '')

        mod_vertices = vertices.copy()
        mod_vertices.extend(vertices)
        
        
        start_idx = random.randint(0, size)
        mod_vertices = mod_vertices[start_idx: start_idx + size]

        vectors = [f"\\vec {{ {(latex(item))} {(latex(mod_vertices[idx+1]))}  }}" 
                   for idx, item in enumerate(mod_vertices[:-1])]

        result_vector = f"\\vec {{ {(latex(mod_vertices[0]))} {(latex(mod_vertices[-1]))}   }}"

        vectors_latex = [f"$\\displaystyle {item} $" for item in vectors]
        shuffle_vectors_latex = random.sample(vectors_latex, size - 1)
        
        vectors_latex = list_to_str(vectors_latex, sep = ' + ')
        shuffle_vectors_latex = list_to_str(shuffle_vectors_latex, sep = ' + ')
        
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        We have a polygon {polygon_name}. Find the expression for 
        
        {shuffle_vectors_latex}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        {shuffle_vectors_latex}

        = {vectors_latex}  &emsp;&emsp; rearranged in order 
        
        $\\displaystyle = {result_vector}$

        see image::/images/physics/additive_property/additive_property_0006.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {result_vector}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_position_vectors(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        
        base_vectors = [Symbol(f"\\hat {item}") for item in list('ijk')]
        i, j, k  = base_vectors
        rows = 2
        cols = len(base_vectors)
        
        r_syms = [Symbol(f"\\vec {{ r_{{{item}}} }}") for item in range(rows)] 
        
        M = sympy.Matrix(rows, cols, lambda item1, item2: sympy.var(f'a_{{{item1}{item2}}}'))
        
        r_vectors = []
        for row_idx in range(M.shape[0]):
            row = list(M.row(row_idx))
            r_vector = [ ueval(coeff) * ueval(base_vector)
                        for coeff, base_vector in zip(row, base_vectors)]
            r_vector = Add(*r_vector)
            r_vectors.append(r_vector)
            pass

        sum_vector = []
        for col_idx in range(M.shape[1]):
            coeff_items = list(M.col(col_idx))
            coeff = Add(*coeff_items)
            base_vector = base_vectors[col_idx]
            sum_vector.append(ueval(coeff) * ueval(base_vector))
            pass
        sum_vector = Add(*sum_vector)
        
        r_vectors_str = [f"$\\displaystyle {latex(r_syms[idx])} = {latex(item)}$" 
                         for idx, item in enumerate(r_vectors)]
        r_vectors_str = list_to_str(r_vectors_str, sep = '\n\n')

        sum_r_syms = Add(*r_syms)
        r_vectors_sum_str = [f"\\left ( {latex(item)} \\right )" for item in r_vectors]
        r_vectors_sum_str = list_to_str(r_vectors_sum_str, sep = ' + ')
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find the resultant vector of the following position vectors:
        
        {r_vectors_str}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle {latex(sum_r_syms)}$

        $\\displaystyle = {r_vectors_sum_str}$
        
        $\\displaystyle = {latex(sum_vector)}$
        
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(sum_vector)}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate


    def _problem_vector_derivatives(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        
        base_vectors = [Symbol(f"\\hat {item}") for item in list('ijk')]
        i, j, k  = base_vectors
        t = Symbol('t')
        x = Function('x')(t)
        y = Function('y')(t)
        z = Function('z')(t)
        r = Function(f"\\vec r")(t)
        v = Function(f"\\vec v")(t)
        a = Function(f"\\vec a")(t)
        
        nabla = Symbol(f"\\nabla")
        
        r_vector = ueval(x) * ueval(i) + ueval(y) * ueval(j) + ueval(z) * ueval(k)
        eq_r = Eq(r, r_vector)
        eq_v_ueval = eq_r.derivative(t)
        eq_v = eq_r.derivative(t).doit()
        
        eq_a_ueval = eq_v.derivative(t)
        eq_a = eq_v.derivative(t).doit()
        
        
        nabla_expr = ueval(x) * ueval(i) + ueval(x) * ueval(j) + ueval(x) * ueval(k)
        nabla_expr = Derivative(nabla_expr, t).doit()
        nabla_sqr_expr = Derivative(nabla_expr, t).doit()
        
        nabla_expr = latex(nabla_expr).replace(latex(x), "") 
        
        nabla_sqr_expr = latex(nabla_sqr_expr).replace(latex(x), "") 
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        The position vectors is given by
        
        $\\displaystyle {latex(eq_r, mul_symbol = 'dot')}$
        
        Find velocity $\\displaystyle {latex(v)}
        $ and acceleration $\\displaystyle {latex(a)} $.
        
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle {latex(eq_r, mul_symbol = 'dot')}$
        
        $\\displaystyle
        \\begin{{aligned}}
        
        \\implies {latex(v)} 
        
        & = {latex(eq_v.lhs, mul_symbol = 'dot')} \\\\ \\\\
        
        & = {latex(eq_v_ueval.rhs, mul_symbol = 'dot')} \\\\ \\\\
        
        & = {latex(eq_v.rhs, mul_symbol = 'dot')} 
        
        \\end{{aligned}}
        $
        
        $\\displaystyle
        \\begin{{aligned}}
        
        \\implies {latex(a)} 
        
        & = {latex(Derivative(v, t))} \\\\ \\\\
        
        & = {latex(eq_a_ueval.rhs, mul_symbol = 'dot')} \\\\ \\\\
        
        & = {latex(eq_a.rhs, mul_symbol = 'dot')}
        
        \\end{{aligned}}
        $
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle
        \\begin{{aligned}}
        
        &  {latex(v)}  = {latex(eq_v.rhs, mul_symbol = 'dot')} \\\\ \\\\

        & {latex(a)} = {latex(eq_a.rhs, mul_symbol = 'dot')}
        
        \\end{{aligned}}
        $
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_current(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{I}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        In a closed circuit, currents {result['props_latex']} flow at a node
        which is not a source or sink of voltage. 
        Find the equation of currents at the node.
        """
        problemTemplate.add_problem(problem_s.replace("\n", " ").strip(), 'text/html')
        
        soln_s = f"""
        In the closed circuit, the charges flow at a node without accumulation
        unless it is a source or sink of voltage.
        Therefore, the sum of all currents must be zero at the node.
        <br/>
        <br/>
        This is called Kirchhoff's Current Law. 
        It states that the algebraic sum of all currents entering 
        and exiting a node, unless it is a source or sink of voltage, must equal zero. Therefore,
        """
        problemTemplate.add_solution(soln_s.replace("\n", " ").strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle {latex(result['sum_props'])} = 0$

        see image::/images/physics/additive_property/additive_property_0007.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])} = 0$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_voltage_in_series(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{V}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        If batteries with voltages {result['props_latex']} 
        are connected in a series, what will be the resultant voltage?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The resultant voltage of batteries connected in a series is sum of all voltages. 
        
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$

        see image::/images/physics/additive_property/additive_property_0008.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_parallel_capacitor(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        q = Symbol('q')   
        V = Symbol('V')   
        C = Symbol('C')  
        solve_for = random.choice([q, V, C])

        result = ap_helper.get_propotional_sum_data(q, V, C, size, 
                                                    solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == q:
            solve_for_text = f"Write expression for the total charge on all capacitors."
        elif solve_for == V:
            solve_for_text = f"Write expression for the voltage."
        else:
            solve_for_text = f"Write expression for the resultant capacitance."
        
        problem_s =  f"""
        The capacitors with capacitances {result['add_props_latex']} 
        are connected in parallel.
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)

        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_parallel_capacitors(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total charge on all capacitors connected in parallel
        is the sum of charges on each capacitor.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the voltage across each capacitor in parallel is same: 
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        drawing_resultant = psd_helper.draw_parallel_capacitors('C')
        svg_str_resultant = psd_helper.drawing_to_svg(drawing_resultant)
        
        problemTemplate.add_solution(svg_str_resultant, 'text/svg')
  
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate


    def _problem_series_capacitor(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        q = Symbol('q')   
        V = Symbol('V')   
        C = Symbol('C')  
        solve_for = random.choice([q, V, C])

        result = ap_helper.get_inverse_sum_data(q, V, C, size, 
                                                solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == q:
            solve_for_text = f"Write expression for the total charge on all capacitors."
        elif solve_for == V:
            solve_for_text = f"Write expression for the voltage."
        else:
            solve_for_text = f"Write expression for the resultant capacitance."
        
        problem_s =  f"""
        The capacitors with capacitances {result['add_props_latex']} 
        are connected in a series.
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
  
        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_series_capacitors(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total voltage on all capacitors connected in a series
        is the sum of voltages across each capacitor.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[0] = soln_stmt.strip()
        
        soln_stmt =  f"""
        As the charge on each capacitor in a series is same: 
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts[2] = soln_stmt.strip()
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        drawing_resultant = psd_helper.draw_parallel_capacitors('C')
        svg_str_resultant = psd_helper.drawing_to_svg(drawing_resultant)
        
        problemTemplate.add_solution(svg_str_resultant, 'text/svg')
  
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate


    def _problem_momentum(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{P}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for momentum of system of particles with 
        momentums {result['props_latex']}.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The resultant momentum is sum of all momentums. 
        
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$

        see image::/images/physics/additive_property/additive_property_0009.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_moment_of_inertia(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'I')
        m = Symbol(f'm')   
        r = Symbol(f'\\vec r')   
        
        func = ap_helper.lambda_moment_of_inertia()
        result = ap_helper.get_function_sum_data(prop, func, m, r, size = size)
        #result = ap_helper.get_function_sum_data(prop, func, m, r, size = size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for moment of inertia 
        ($\\displaystyle {latex(prop)}$) 
        of system of particles with 
        given masses and radius vectors.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The resultant moment of inertia is sum of all moments of inertia. 
        
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$
        
        $\\displaystyle = {latex(result['sum_prop_exprs'])}$
        
        see image::/images/physics/additive_property/additive_property_0010.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_prop_exprs'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate


    def _problem_fluid_pressure(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{P}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for pressure at a point in a static fluid 
        if inlet and outlet pressures {result['props_latex']}.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        A liquid, considered incompressible, will have a net zero pressure at any point
        if it is static.
        Therefore, the resultant pressure, counted as opposite vectors
        for inlets and outlets, shall be zero. 
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        soln_s = f"""
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])} = 0$

        see image::/images/physics/additive_property/additive_property_0011.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])} = 0$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate


    def _problem_electric_charge(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'q')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for net electric charge if it consists of 
        particles with {result['props_latex']} electric charges.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The net electric charge is sum of the electric charges of its
        constituent particles.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        soln_s = f"""
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$

        see image::/images/physics/additive_property/additive_property_0012.png
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_electric_field(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec {{E}}')   
        result = ap_helper.get_simple_sum_data(prop, size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        A point charge is subjected to  {result['props_latex']} electric fields.
        What is the net electric field on the charge?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The net electric field on the charge is sum of individual electric fields. 
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        soln_s = f"""
        $\\displaystyle {latex(prop)} = {latex(result['sum_props'])}$

        see image::/images/physics/additive_property/additive_property_0013.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(result['sum_props'])}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate



    def _problem_electric_field_formula(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        prop = Symbol(f'\\vec E')
        q = Symbol(f'q')   
        r = Symbol(f'\\vec r')   
        
        k = ap_helper.get_electric_field_constant()
        
        func1 = ap_helper.lambda_electric_field(include_k = True)
        func2 = ap_helper.lambda_electric_field(include_k = False)
        
        result1 = ap_helper.get_function_sum_data(prop, func1, q, r, size = size)
        result2 = ap_helper.get_function_sum_data(prop, func2, q, r, size = size)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for net electric field ($\\displaystyle {latex(prop)}$) at a point 
        due to a system of charges with 
        given charges and radius vectors from the point.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        The net electric field is sum of all individual electric fields. 
        
        $\\displaystyle {latex(prop)} = {latex(result1['sum_props'])}$
        
        $\\displaystyle = {latex(result1['sum_prop_exprs'])}$
        
        $\\displaystyle = {latex(k)} \\left( {latex(result2['sum_prop_exprs'])} \\right) $
        
        see image::/images/physics/additive_property/additive_property_0014.png
        """
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {latex(k)} \\left( {latex(result2['sum_prop_exprs'])} \\right) $
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_electric_potential_energy_formula(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        result = ap_helper.get_electric_system_potential_energy(size = size)
        prop = result['prop']

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for potential energy ($\\displaystyle {latex(prop)}$) of 
        an isolated system of charges with 
        given charges and radius vectors from the point.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        Let the charges and their respective radius vectors be:
        {result['charge_radius_vectors_latex']}
        
        The potential energy due to two charges is:
        $\\displaystyle {result['prop_ij']} = {result['prop_expr_ij']}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        soln_s = f"""
        The net potential energy of the system is is sum of potential energy 
        of each pair of charges. Make sure not to count a pair twice,
        due to change in the order of charges in the pair. 
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)

        
        soln_s = f"""
        $\\displaystyle {result['prop']} = {result['sum_props']}$

        $\\displaystyle = {result['sum_prop_exprs']}$
        
        $\\displaystyle = {result['sum_prop_exprs_common_const']}$
        
        see image::/images/physics/additive_property/additive_property_0015.png
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle {result['sum_prop_exprs_common_const']}$
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_electric_potential_energy_formula_external_field(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        V = Function('V')
        result = ap_helper.get_electric_system_potential_energy(size = size,
                                                                external_field = V)
        prop = result['prop']

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Find expression for potential energy ($\\displaystyle {latex(prop)}$) of 
        a system of charges under influence of an external field, with 
        given charges and radius vectors from the point.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)
        
        soln_s = f"""
        Let the charges and their respective radius vectors be:
        {result['charge_radius_vectors_latex']}
        
        The potential energy of a charge due to the external field is:
        $\\displaystyle 
        {latex(result['ef_prop_i'])}
        = {latex(result['ef_prop_expr_i'])} 
        \\qquad \\qquad \\cdots (i)
        $
        
        
        The potential energy due to two charges mutually is:
        $\\displaystyle 
        {latex(result['prop_ij'])}
        = {latex(result['prop_expr_ij'])}
        \\qquad \\qquad \\cdots (ii)
        $
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        soln_s = f"""
        The net potential energy of the system is total of the followings:
        <br/>
        1. the sum of potential energy, (i) above, of each charg due to the external field.
        <br/>
        2. the sum of potential energy of each pair of charges, (ii) above.
        Make sure not to count a pair twice,
        due to change in the order of charges in the pair. 
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)

        
        soln_s = f"""

        $\\displaystyle
        \\begin{{aligned}}
        {result['prop']} 

        & = {latex(result['sum_ef_props'])} \\\\
        & + {latex(result['sum_props'])} \\\\
        
        \\\\
        & = {latex(result['sum_ef_prop_exprs'])} \\\\
        & + {latex(result['sum_prop_exprs'])} \\\\
        
        \\\\
        & = {latex(result['sum_ef_prop_exprs'])} \\\\
        & + {result['sum_prop_exprs_common_const']} \\\\
        
        \\end{{aligned}}
        $
        
        see image::/images/physics/additive_property/additive_property_0016.png
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        $\\displaystyle
        \\begin{{aligned}}
        & {latex(result['sum_ef_prop_exprs'])} \\\\
        & + {result['sum_prop_exprs_common_const']} \\\\
        \\end{{aligned}}
        $
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_parallel_inductance(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()
        
        size = random.randint(2, 5)
        V = Symbol('V')   #V
        I = Symbol('I')   #I
        L = Symbol('L')   #R
        solve_for = random.choice([V, I, L])

        result = ap_helper.get_parallel_inductance_data(V, I, L, size, 
                                                        solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == V:
            solve_for_text = f"Find an expression for voltage."
        elif solve_for == I:
            solve_for_text = f"Find an expression for the net current."
        else:
            solve_for_text = f"What will be the resultant inductance? "
        
        problem_s =  f"""
        A circuit has inductances {result['add_props_latex']} in 
        parallel connected to a voltage source $\\displaystyle {latex(V)}$. 
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)

        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_parallel_inductances(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total current is sum of currents across each inductances in parallel.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts.insert(0, soln_stmt.strip())
        
        soln_stmt =  f"""
        As the voltage through each of the inductance in parallel must be same:
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts.insert(5, soln_stmt.strip())
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _problem_series_inductance(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        ap_helper = self.base_helper.get_additive_property_helper()

        
        size = random.randint(2, 5)
        V = Symbol('V')   #V
        I = Symbol('I')   #I
        L = Symbol('L')   #R
        solve_for = random.choice([V, I, L])

        result = ap_helper.get_series_inductance_data(V, I, L, size, 
                                                      solve_for = solve_for)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if solve_for == V:
            solve_for_text = f"Find an expression for voltage."
        elif solve_for == I:
            solve_for_text = f"Find an expression for the net current."
        else:
            solve_for_text = f"What will be the resultant inductance? "
        
        problem_s =  f"""
        A circuit has inductances {result['add_props_latex']} in 
        series connected to a voltage source $\\displaystyle {latex(V)}$. 
        {solve_for_text}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html',
                                    add_html_line_break = False)

        psd_helper = self.base_helper.get_physics_schem_draw_helper()
        drawing = psd_helper.draw_series_inductances(*result['add_props'])
        svg_str = psd_helper.drawing_to_svg(drawing)
        
        problemTemplate.add_problem(svg_str, 'text/svg')
        
  
        soln_stmts = result['soln_stmts']
        
        soln_stmt =  f"""
        The total voltage is sum of voltages across each inductances in series.
        """
        soln_stmt = soln_stmt.replace("\n", "")
        
        soln_stmts.insert(0, soln_stmt.strip())
        
        soln_stmt =  f"""
        As the current through each of the inductance in parallel must be same:
        """
        soln_stmt = soln_stmt.replace("\n", "")
        soln_stmts.insert(4, soln_stmt.strip())
        
        
        soln_s = "\n\n".join(soln_stmts)
        
        problemTemplate.add_solution(soln_s.strip(), 'text/html')


        
        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

