module ReducedFormTests

include(joinpath(dirname(@__FILE__), "..", "src", "AndersonMoore.jl"))
# test reducedForm
using .AndersonMoore

#tweaked= True
# test reducedForm firmvalue example
function firmvalueTrue()::Bool


neq=4::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64

    bb = [0.0  0.2285714285714295      0.0  2.2131318746159373e-15
          0.0  0.40000000000000024     0.0  0.0                   
          0.0  1.5314075638926047e-16  0.0  0.0                   
          0.0  1.531407563892605e-16   0.0  1.0]

    qFull = [0.0   0.17457431218879393   0.0   0.4364357804719848    5.551115123125783e-16   -0.4364357804719848  0.0                 -0.4364357804719848 
             0.0   0.2309401076758503    0.0   0.2113248654051871   -1.1102230246251565e-16  -0.5773502691896257  1.3660254037844386  -0.2113248654051871 
             0.0   0.2309401076758503    0.0  -0.7886751345948129   -1.1102230246251565e-16  -0.5773502691896257  0.3660254037844386   0.7886751345948129 
             0.0  -0.042021536303409414  0.0  -0.10505384075852343  -0.8089145738406297       0.5672907400960278  0.0                  0.10505384075852522]


nonsing=true::Bool

qRows=4::Int64

qCols=8::Int64

bCols=4::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm firmvalue3Leads2Lags example
function firmvalue3Leads2LagsTrue()::Bool


neq=4::Int64;nlag=2::Int64;nlead=3::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64

    bb = [0.0   0.03748035941322163    0.0  0.0  0.0  0.31178973986873604     0.0   1.4078100382803878e-15
          0.0   0.4                    0.0  0.0  0.0  1.8429478256727236e-18  0.0  -2.1575528188428242e-17
          0.0   5.948141085865766e-18  0.0  0.0  0.0  2.378039643817009e-17   0.0  -1.0787764094214123e-17
          0.0  -2.373363479909904e-19  0.0  0.0  0.0  1.4390293975577504e-18  0.0   0.9999999999999999]

    qFull = [0.0  -0.3674571928024606    0.0  0.0  0.0   0.0                   0.0   0.08135701799384851    0.0                      0.9186429820061515    -1.0  -0.08135701799384851    0.0                      5.551115123125783e-17    0.0   0.0                     0.0                     0.0                     0.0                  0.0                 
             0.0   0.0325428071975394    0.0  0.0  0.0   0.0                   0.0   0.08135701799384851   -1.1102230246251565e-16  -0.08135701799384851    1.0  -0.08135701799384851    0.0                      2.7755575615628914e-17   0.0   0.0                     0.0                     0.0                     0.0                  0.0                 
             0.0   0.0325428071975394    0.0  0.0  0.0   0.0                   0.0  -0.9186429820061515     0.0                     -0.08135701799384851    0.0   0.9186429820061515     0.0                      0.0                      0.0   0.0                     0.0                     0.0                     0.0                  0.0                 
             0.0   0.0                   0.0  0.0  0.0  -0.3674571928024606    0.0   0.0                    0.0                      0.0                    0.0   0.08135701799384851    0.0                      0.9186429820061515      -1.0  -0.08135701799384851     0.0                     5.551115123125783e-17   0.0                  0.0                 
             0.0   0.0                   0.0  0.0  0.0   0.0325428071975394    0.0   0.0                    0.0                      0.0                    0.0   0.08135701799384851   -1.1102230246251565e-16  -0.08135701799384851      1.0  -0.08135701799384851     0.0                     2.7755575615628914e-17  0.0                  0.0                 
             0.0   0.0                   0.0  0.0  0.0   0.0325428071975394    0.0   0.0                    0.0                      0.0                    0.0  -0.9186429820061515     0.0                     -0.08135701799384851      0.0   0.9186429820061515      0.0                     0.0                     0.0                  0.0                 
             0.0   0.0                   0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                      0.3141101189565458     0.0   0.0                    0.0                      0.0                      0.0  -0.10915189360855129     4.965068306494546e-17  -0.7852752973913645      0.4472135954999578   0.10915189360855129 
             0.0   0.0                   0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                      0.19343902401445667    0.0   0.0                    0.0                      0.0                      0.0   0.03638396453618376    -9.930136612989092e-17  -0.4835975600361417      1.3416407864998738  -0.03638396453618376 
             0.0   0.0                   0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                      0.0325428071975394     0.0   0.0                    0.0                      0.0                      0.0  -0.9186429820061515      0.0                    -0.08135701799384851     0.0                  0.9186429820061515  
             0.0   0.01872715567480699   0.0  0.0  0.0   0.01702468697709727   0.0   0.04681788918701744    0.4362022735554419      -0.031340901026019906   0.0  -0.004256171744274398   0.3965475214140374      -0.5321265586946402       0.0  -0.0038692470402495885   0.36049774674003404    -0.483751416995128       0.0                 -0.03869247040249525 
             0.0  -0.024055173657485922  0.0  0.0  0.0   0.029872707553247335  0.0  -0.060137934143714704  -0.5603051324169901       0.05286123608496593    0.0   0.13481970302683288    0.6958100406840118       0.3497097030263232       0.0  -0.0928735140299901     -0.1694924895334065     -0.3770399993461673      0.0                  0.018191745146872003
             0.0  -0.024055173657485922  0.0  0.0  0.0  -0.008004367864623767  0.0  -0.06013793414371476   -0.5603051324169901       0.08729494101030333    0.0   0.04012701448215549   -0.18644173848674683      0.27700012807861196      0.0   0.08790343682803019     0.6325545824400094      0.14941583884672993     0.0                 -0.06789251716647093]

    
 

nonsing=true::Bool

qRows=12::Int64

qCols=20::Int64

bCols=8::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm example7 example
function example7True()::Bool


neq=4::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.0  0.0  0.0  -0.6551413498221798
 0.0  0.0  0.0  -0.2945196982393082
 0.0  0.0  0.0  -0.663971668063239 
 0.0  0.0  0.0   0.3360283319367609]

    qFull = [0.0  0.0  0.0   0.9714485500374334     0.0                   0.09237233811418602   0.9160251471689218    -0.9999999999999999
 0.0  0.0  0.0  -0.6885514499625665     0.0                  -1.007627661885814    -0.08397485283107814    1.0               
 0.0  0.0  0.0   0.020704809034346315  -0.12636048681123602   0.6391791991927751    0.06089649715984197    0.3725746100511591
 0.0  0.0  0.0   0.004472451929227917  -0.6787380506530568    0.6391791991927751    0.013154270380082114  -0.7504036503198326]


nonsing=true::Bool

qRows=4::Int64

qCols=8::Int64

bCols=4::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm oneEquationNoLead example
function oneEquationNoLeadTrue()::Bool


neq=1::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [-0.6666666666666666]

    qFull = [2.0  3.0]

    
  
nonsing=true::Bool

qRows=1::Int64

qCols=2::Int64

bCols=1::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm reliablePaperExmpl example
function reliablePaperExmplTrue()::Bool


neq=5::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.0  0.0  0.0  1.1828179593111052e-16  0.0
          0.0  0.0  0.0  1.3794162794530762e-16  0.0
          0.0  0.0  0.0  0.21410138764106415     0.0
          0.0  0.0  0.0  0.3612359521871584      0.0
          0.0  0.0  0.0  0.5307470047448346      0.0]

    qFull = [0.0  0.0  0.0   0.3969847178042136    0.0  -0.1850509058906912    0.6089185297177356      -0.5557786049258994    0.39698471780421407  -0.7939694356084274 
             0.0  0.0  0.0   0.17185720889240513   0.0   0.9076903413717948    0.251404759156605       -0.24060009244936742   0.17185720889240524  -0.3437144177848103 
             0.0  0.0  0.0   0.17185720889240513   0.0  -0.09230965862820517   1.251404759156605       -0.24060009244936742   0.17185720889240524  -0.3437144177848103 
             0.0  0.0  0.0  -0.05631323026787628   0.0  -0.4286629858284091   -3.6703258090922634e-16   0.6201279637550784    0.4662994218464173   -0.46142727279236506
             0.0  0.0  0.0  -0.013375768528939336  0.0  -0.5746503523310461    3.09255399040231e-16     0.6201279637550784   -0.5168413473817807    0.12681595303106827]
    
nonsing=true::Bool

qRows=5::Int64

qCols=10::Int64

bCols=5::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm athan example
function athanTrue()::Bool


neq=9::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64


    bb = [0.8285973383130347       0.29644852356208445     -0.11369033691582552      0.2123317657422606      0.0  0.0  0.0  0.0   2.1935483080274293e-16
          0.293                    0.764                   -0.293                   -1.646036600311629e-16   0.0  0.0  0.0  0.0  -2.339515921254561e-32 
          1.9501946766260694       1.3568970471241695      -0.5203806738316512      -0.4863364685154788      0.0  0.0  0.0  0.0   4.3870966160548577e-16
          -8.786979196790518e-17   -1.0192232643901078e-16   5.148028650420445e-17    0.9109999999999998      0.0  0.0  0.0  0.0   0.0                   
          -1.593244282256827e-17   -1.236660659626695e-17    1.0534664365541054e-17  -7.220004517462003e-17   0.0  0.0  0.0  0.0   0.0                   
          -4.6504144201620185e-17  -4.8878343919176405e-17   2.5345529016143423e-17  -9.103476345289971e-17   0.0  0.0  0.0  0.0   0.0                   
          -6.617826770686551e-17   -7.45388658530095e-17     3.518654070019197e-17   -9.103476345289971e-17   0.0  0.0  0.0  0.0   0.0                   
          -8.932183816406436e-17   -1.0019938778684248e-16   4.502755238424049e-17   -1.098694817311794e-16   0.0  0.0  0.0  0.0   0.0                   
          -1.1246540862126324e-16  -1.2585990972067555e-16   5.4868564068289023e-17  -1.1680837563508664e-16  0.0  0.0  0.0  0.0   1.0 ]

    qFull = [-0.2775204536090702    -0.7236369507076094     0.27752045360907       0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259362   1.0                     -0.05283121635129678  -0.10566243270259355  -0.052831216351296846  -1.0  -0.15849364905389032   0.0  -0.05283121635129678
             0.015479546390929903   0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678  -1.894337567297406    -1.0000000000000007       0.9471687836487033    0.8943375672974065   -0.0528312163512969     0.0   1.8415063509461098    0.0  -0.05283121635129678
             0.015479546390929876   0.040363049292390735  -0.015479546390929955  -0.8628707619039687   0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259362  -2.7755575615628914e-17  -0.05283121635129678   0.8943375672974065   -0.05283121635129696    0.0  -0.15849364905389032  -1.0  -0.05283121635129678
             0.015479546390929848   0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259368  -2.7755575615628914e-17  -0.05283121635129678  -0.10566243270259355   0.9471687836487028     0.0  -0.15849364905389032   0.0  -0.05283121635129678
             0.01547954639092982    0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259373  -1.3877787807814457e-17  -0.05283121635129678  -0.10566243270259355  -0.05283121635129701    1.0  -0.15849364905389032   0.0  -0.05283121635129678
             0.015479546390929792   0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259379   0.0                     -0.05283121635129678  -0.10566243270259355  -0.05283121635129707    0.0   0.8415063509461097    0.0  -0.05283121635129678
             0.015479546390929768   0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0   0.05283121635129678   0.10566243270259384   1.3877787807814457e-17  -0.05283121635129678  -0.10566243270259355  -0.052831216351297124   0.0  -0.15849364905389032   1.0  -0.05283121635129678
             0.015479546390929744   0.040363049292390735  -0.015479546390929955   0.04812923809603137  0.0  0.0  0.0  0.0  -0.9471687836487033    0.1056624327025939    2.7755575615628914e-17  -0.05283121635129678  -0.10566243270259355  -0.05283121635129717    0.0  -0.15849364905389032   0.0   0.9471687836487033 
             0.4269446548162846     0.05183310285708586   -0.01987840201194522    0.06180622605079214  0.0  0.0  0.0  0.0   0.06784437546738986  -0.3411497410831621    0.2672180406453587      -0.11412387489577791  -0.04925565470274879   0.746288130141289      0.0  -0.20353312640216958   0.0  -0.06784437546738974]



    
nonsing=true::Bool

qRows=9::Int64

qCols=18::Int64

bCols=9::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= True
# test reducedForm habitmod example
function habitmodTrue()::Bool


neq=12::Int64;nlag=4::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64


    bb = [0.027529882898026693   0.0   0.02046753085696043      0.0038416784150548254   0.05104660732621768     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.15012534765256844     0.0   0.08029132274149581     -0.05696336920642234      0.033222660667064294    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007627389623834766    0.0   0.13200357610529176     -0.0009755753382329734    0.14090688019772518     0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.4095923144666124       0.531564284055886       0.28174310568613087     -0.3703087678432382      -0.00715737500057539    0.0   0.0005945790003020514   0.0  0.0  0.0  0.0   0.024731911160965715  
          8.224528448630537e-17  0.0   9.520816557054137e-18    7.453817121205115e-18  -3.9765241670148345e-17  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.7127202427610209e-16  0.0  -6.705341025742166e-17   -2.165807104666132e-17   -2.7226459401225715e-17  0.0  0.0  0.0  0.0  0.0  0.0  0.0   4.2135460933816195e-17  0.0  -1.131435862862643e-16    5.961351354153149e-17   -9.388398707293645e-17   0.0  0.0  0.0  0.0  0.0  0.0  0.0    3.340781174952024e-15    0.8887899999999991     -3.0716001200390894e-16   2.283869547545813e-16    1.103016775544864e-16  0.0   4.998384155649486e-18   0.0  0.0  0.0  0.0  -1.111288237475915e-16 
          -0.5280200000000002     0.0  -0.11279000000000003     -0.03183300000000002    -0.02473400000000001     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.7152600000000002      0.0  -0.04207600000000003      0.22829000000000008      0.012266999999999962    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.22214999999999996     0.0   0.14171999999999998     -0.26679                  0.11958999999999993     0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.4230800000000047       7.206741264480954e-16   0.6107600000000001       0.1094600000000002      -0.17172000000000018    0.0   6.539875250553231e-18   0.0  0.0  0.0  0.0   0.00011277000000013762
          -0.46435999999999983    0.0  -0.1613099999999999      -0.027439999999999975   -0.17086999999999988     0.0  0.0  0.0  0.0  0.0  0.0  0.0   1.3424999999999991      0.0  -0.16793999999999984      0.3581799999999998       0.09837000000000012     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.0638200000000002      0.0   0.022550000000000243    -0.51594                 -0.08948999999999971     0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.46672000000000413     -3.76129926589772e-16    0.11369000000000035      1.1065699999999994       0.26021000000000016    0.0   6.294142887653318e-18   0.0  0.0  0.0  0.0   0.0014099999999998367 
          0.23292000000000046    0.0  -0.0851199999999999       0.04213000000000004    -0.14148999999999984     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.03313000000000081     0.0  -0.15222999999999973     -0.015720000000000314     0.34762000000000015     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.7055200000000003      0.0   0.24697000000000036     -0.21887999999999994      0.07805000000000041     0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.5631600000000008      -8.231197482577451e-16   0.08268000000000053      0.16053999999999874      0.6863700000000003     0.0   1.4708699678887274e-18  0.0  0.0  0.0  0.0   0.003479999999999741  
          -0.048656191278170544   0.0  -0.01435815694973597     -0.003615028856506455   -0.01636808149650229     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.09639330877304267     0.0  -0.026205246565411726     0.03374738431217089     -0.009078892369143693    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.01783229151983523     0.0  -0.02764317939480294     -0.019296742740289106    -0.03208820659304275     0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.041041558161043004     0.10522232527120402    -0.0348984919572105       0.11516795458962072     -0.01250204425957194    0.0   1.566282461372474e-5    0.0  0.0  0.0  0.0   0.02657693886125512   
          -7.629376414069034e-17  0.0   6.265999690868285e-18   -8.465576914002562e-18   2.2912723786601622e-17  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -5.656105025592255e-17   0.0   1.3536683430391465e-17   1.4327911872437436e-18  -5.597968562970933e-17   0.0  0.0  0.0  0.0  0.0  0.0  0.0   2.028332630419578e-16   0.0  -2.4246695492316914e-17   5.942764221637348e-17   -4.2740351316057305e-17  0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.9985300000000052       8.77668866870839e-16    9.032203701225228e-18   -1.4805427544813066e-17  -2.051300958601099e-16  0.0   0.0014700000000000073   0.0  0.0  0.0  0.0   1.5572124179398154e-16
          0.026551670931544202   0.0   0.019758049108149295     0.0037021774397815537   0.04925739354393666     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.1450040846266795      0.0   0.07745120156686947     -0.05496735589389049      0.032027423331009594    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007611617911208028    0.0   0.1273227241038996      -0.0008541124837934361    0.13588475634843994     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -25.513272789070186        0.5127561856452838      0.2717898547614637      -0.3572798542104463      -0.006907594033121081   0.0  -0.037567719944178936    0.0  0.0  0.0  0.0   0.023860003900923955  
          0.5215165039074411     0.0   0.11430026751210659      0.030927610354491354    0.02828261679995843     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.7248779895191634      0.0   0.04678007238494015     -0.22915333931303963     -0.01557639803173959     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.23264594754634338     0.0  -0.14007181332786584      0.27137534987473005     -0.12210781290947532     0.0  0.0  0.0  0.0  0.0  0.0  0.0   -0.421115826526967        0.017299234728078962   -0.603894349464411       -0.11568142124178452      0.15391702208709276    0.0   2.2277488330357095e-6   0.0  0.0  0.0  0.0   0.005045517422619975  
          0.02357958772568908    0.0  -0.08180944759569314      0.010805320556173021   -0.15250184879724152     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.43627139419543065     0.0  -0.2464562057075977       0.12726448730905981      0.028486524782904855    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.2487621375603254      0.0  -0.22105757972209314     -0.1108151304310498      -0.0970433656332047      0.0  0.0  0.0  0.0  0.0  0.0  0.0   25.52323581956464        -0.9479881849820687     -0.4163263367597136       0.6148597813080481       0.4201378467424025     0.0   0.037509284219326006    0.0  0.0  0.0  0.0  -0.15216162534260927   
          -0.0020115574773975882  0.0   0.0024809211673566733   -0.0005814485947749562   0.004125106371835417    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.011636485827103507    0.0   0.006753093019362888    -0.0028851347666588954   -0.00242816735607223     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.009653364628498565    0.0   0.0037311171009103737    0.004470914458811475    -0.0015781360250507145   0.0  0.0  0.0  0.0  0.0  0.0  0.0   -0.9989961535612075       0.01733774213772672     0.005740454170478411    -0.010251714541460004    -0.01654283689191306    0.0  -0.0014677581599157874   0.0  0.0  0.0  0.0   0.005132605940544283  
          -5.787423759131271e-22  0.0   1.7401960564532257e-17   1.199678066996682e-18   2.7753510180459757e-17  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.2896717623199186e-17  0.0   5.923851136294227e-17   -2.0724932197447792e-17   4.220403074944324e-17   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.4246172978026056e-16  0.0   1.0568971144504532e-16  -5.0765872225745494e-17   8.29393390184753e-17    0.0  0.0  0.0  0.0  0.0  0.0  0.0    1.2559316701838371e-15   2.681100716338447e-16   1.9738138486174657e-16  -1.3335444394480052e-16   3.001946037943091e-17  0.0   1.831226612735988e-18   0.0  0.0  0.0  0.0   1.0]






    qFull = [0.048224301849328854   0.0  -0.005649146396284293     0.005226518012203298   -0.02215476160154963     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.015308948646934087   0.0  -0.020587808201071183    -0.0012231602348608053   0.03455574961918122     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.11508886468270901    0.0   0.003849805355026825    -0.025663325721305353   -0.016092763906927973   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.11058349377473162     0.08577477266636502    -0.061557028897325894     0.08871511230103518    0.0984214691068183     0.0   0.00011902473873962929  0.0  0.0  0.0  0.0   0.0809692100269587      0.9432665948914909      -1.0397739505843913      -0.8164459899560503     -0.08096921002695806    -0.08096921002695859     3.2582176786916612      -0.08096921002906798   -8.071321389024888e-14   -0.6991303348016144       0.0019668724624858913    0.46608352191604363     -0.1889689039025684   
             0.12184229367564271    0.0   0.01315643886009809      0.011776395875306685    0.0023242757310194748   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.22059129119164317    0.0   0.0008029917295495695   -0.06129178127680296     0.04146298156278527     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.045053126560429105   0.0   0.031417064154452355     0.04730419872232132     0.020927007510204494   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.16967163509717323     0.7513241564441493     -0.02453854989239201     -0.1345796614826893     0.0795128651273466     0.0   0.0002359986956209491   0.0  0.0  0.0  0.0   0.1605433303543872     -0.009553094281929408    -0.8357806250940358       0.045144309325711895    0.1413895852400555     -0.16054333035438648    -0.03299815857374        -0.16054333035395985    1.6431300764452317e-14   0.007080562419868097    -1.9919838332327355e-5   -0.004720340837070042    -0.15909036196827112  
             0.49066964504998173    0.0   0.09954535982417251      0.03022429851128815     0.01414185846355575     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.6322622701252367     0.0   0.03051560021834706     -0.204489715485048      -0.00036338481301305056  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.15680105798698918    0.0  -0.12857418730353962      0.23014883764676913    -0.11536314620234255    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.3509238693062533      0.05588670990545325    -0.5752655919239991      -0.06006928783796028    0.18817837065877402    0.0   3.2590484883454946e-5   0.0  0.0  0.0  0.0   0.022170397879901303   -0.19933472888674186      0.13645518489380126      1.1510412890898465     -0.036640498627503154   -0.022170397879901615   -0.6885391056498145      -0.022170397878949033   3.6963487826113806e-14   0.14774291435624862     -0.00041564706222766215  -0.09849456450897717      0.0007546546080738729
             -0.1509586455410639     0.0   0.10232601434026455     -0.03481834638965288     0.15969870625813026     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.18599969898555688    0.0   0.16812232476852762     -0.04156942535375936    -0.33475383010380316     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.8310927439878807     0.0  -0.22268395045033668      0.2830795846279476     -0.048811981161980406   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.4803091015169949      0.2147997620409701     -0.0675544455608285      -0.3474368554746763    -0.6825772800634178     0.0   0.0001474001947718218   0.0  0.0  0.0  0.0   0.04819962300129733    -2.493144579673867e-14   -0.24167661881993496     -0.04753534405872386     0.18637755529090044     0.9119238998199345      1.021405182655144e-14   -0.10027224134072954    2.4855117963795692e-14  -6.245004513516506e-17   -3.469446951953614e-17   -1.1796119636642288e-16  -0.05163054996488135  
             -0.03898570051968027    0.0  -0.01418689239097786     -0.0016569485305627536  -0.011804941061041139    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.08990058842161651    0.0  -0.01275032969693673      0.025579556628944945    0.01305049771901661     0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.0725132447801352     0.0   0.013500321924465132    -0.03969311179902771     0.0036665672541703422  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.8749975344470555      0.261761701981455       0.03547480534954783      0.056047435316729656   0.01937879065353837    0.0  -0.0013663767846879649   0.0  0.0  0.0  0.0  -0.03689967572960394    -2.598615767013257e-14   -0.29451467948722987     -0.04693496623507955    -0.04254741414177614    -0.023846031180842154   -4.884981308350689e-15    0.9295080167952067     2.631228568361621e-14    9.71445146547012e-17     2.7755575615628914e-16   1.8041124150158794e-16   0.0370479446281955   
             -0.47360918256095863    0.0  -0.12531586189663457     -0.03500540155108815    -0.12266496414159372     0.0  0.0  0.0  0.0  0.0  0.0  0.0   1.2331447673460467     0.0  -0.11679785807542903      0.3296614679484056      0.004648976784879369    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.8052962088950498     0.0  -0.04432176261119575     -0.41668642626540536    -0.10569955396538423    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.27299934180555274     0.05264877170439268     0.06781077687905307      0.9832847944523508     0.07585481312963546    0.0  -1.216412233445487e-5    0.0  0.0  0.0  0.0   0.025205407433645053    1.2705114738054135e-14  -0.059236458223419226     0.028013880720362257   -0.9273473043277112      0.24805975279627446    -3.3306690738754696e-15   0.008274913152365726  -1.2552459072168176e-14   1.0755285551056204e-16   1.0755285551056204e-16   1.9081958235744878e-16  -0.024764254799602863 
             -0.03907555039316141    0.0  -0.020259089736222164    -0.0007650944702003904  -0.020964584905621333    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.11981378735802013    0.0  -0.021956266348871697     0.03290267049808291     0.026695298956530496    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.12323522603228682    0.0   0.02023625538916286     -0.05854921534781744     0.0020779438347818535  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.229780587961909       0.2047410640889027      0.03419820667815982      0.09225981389673804    0.050567880635814015   0.0   0.00022122212856097207  0.0  0.0  0.0  0.0  -0.9446881295234946     -1.942890293094024e-14   -0.23035932457487446     -0.03513701932849023    -0.07188888962892004    -0.055211331533372834    0.0                     -0.1504912439185233     1.9539925233402755e-14  -1.1102230246251565e-16   1.1102230246251565e-16   0.0                      0.9449855906932771   
             -0.0004112545407827572  0.0  -0.00019452091767833003  -9.283091397359757e-6   -0.00018253948617520996  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0010878828139805662  0.0  -0.00019733266140110496   0.0003084228372763876   0.0002484723180920137   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.001068273564831057   0.0   0.00022281921277781332  -0.0005391189322632817   5.709424981224569e-5   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0013277438621019668   0.0004812879194471024   0.00043787950864254525   0.000742736937090406   0.0004208910287716447  0.0   7.960184538364911e-7    0.0  0.0  0.0  0.0   0.0005415091522697216   0.036519389115350916     4.8533698996223395e-5    4.8786410222974706e-5  -0.0005360186767149638  -0.0005471444607045387  -0.0020638482545803746   -0.9985865404987156    -0.038465417033911195     0.00044200742490729594  -1.2435052364175794e-6   -0.0002946694873028131   -0.0004703202703287104
             -0.0008219456605379962  0.0  -0.00038877534060981407  -1.8553464907509283e-5  -0.00036482889223182416  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.05134698239100019    0.0   0.010844861708001708     0.0048221655677330895   0.012520159255426233    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.09200018304651823    0.0   0.02123890812800464     -0.032358430807675455    0.016255504651777306   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.00344808290467279     0.0009619164717453317   0.0321487710403647       0.01440147100693539    0.03214200920744539    0.0   1.590946357932515e-6    0.0  0.0  0.0  0.0   0.0010822764339676585  -0.025820019246998577    -0.09617301352461954     -0.12754424515906868    -0.12692831449922223     0.024942086393363306    0.9440926660754702       0.10876780622394171    0.0005115657303894922   -0.16190157315159914      0.0004554798011377679    0.10793360216540732     -0.02510824030314538  
             0.0012963657647829749  0.0   0.0006131731888681185    2.926236840032464e-5    0.000575405052414153    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0002753826367995046  0.0   0.001417974540763322    -0.0007192854306701087  -0.00040979038513098585  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0006156946984741206  0.0   0.0005238786055672411    5.691571632816621e-5    0.0002778625350991357  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.004141688997507744   -0.0015171265478920778  -0.0005609697276626316   -0.001792180953701343  -0.0010808598097709363  0.0  -2.509227180101973e-6    0.0  0.0  0.0  0.0  -0.0017069572653753613   0.0017069572654062255    2.6540062553319025e-14   0.5543802390475164     -0.0007706325566487458   0.0028287884071704727   0.005896146826955699    -0.4376687273959885     0.0046365858575683925    0.5551797938933185       0.00462054998751237     -0.4390441408659592       0.0014814770471078987
             -0.0019453384902116924  0.0  -0.0009201333742932887   -4.391138142503959e-5   -0.0008634581584376666   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007890789348399664   0.0  -0.00034824954346529617   0.0016467763790267288   0.0014437822550687621   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.007118978829893302   0.0   0.0019419656250573884   -0.003763663038454512    0.0006122557466490817  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.006310529388178856    0.00227661416885948     0.0026594964111798336    0.003930215017752639   0.002160054578552229   0.0   3.7653695791140037e-6   0.0  0.0  0.0  0.0   0.0025614759041618857  -0.00256147590420059      5.5703307755532746e-14   0.40185543248639555    -0.004357414610844483   -0.0017482904648955862  -0.008847812611864053    -0.5814864751997458    -0.007064011980828997     0.405250605732331       -0.007039499124940514    -0.5794185355643707      -0.0022694334155999012
             0.0020978526998442363  0.0   0.0009922716757191404    4.7354026326086806e-5   0.0009311531324949725   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.0026201588475657693  0.0   0.0009343989393719629   -0.0012940204852223325  -0.0021908789300395413   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007913577808070466   0.0  -0.002033110041372515     0.0026123910570644325   0.0002877157089658252  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.009013040320041424   -0.0024551003358994046  -0.003154896041872389    -0.004639310717627976  -0.002427894612094447   0.0  -4.060573919363521e-6    0.0  0.0  0.0  0.0  -0.0027622951832284135   0.0025986809011005023   -0.001261855975828161     0.586802581520069       0.006222154819559864    0.007065074273563971   -0.018085447640851134    -0.3916403805172171    -0.0016703701825073246    0.5893025979309264      -0.0016578926623558748   -0.39286555974452136      0.0019098222280376582]
    

nonsing=true::Bool

qRows=12::Int64

qCols=60::Int64

bCols=48::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm firmvalue example
function firmvalueFalse()::Bool


neq=4::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.0  0.22857142857142856  0.0  0.0
          0.0  0.4                  0.0  0.0
          0.0  0.0                  0.0  0.0
          0.0  0.0                  0.0  1.0]

    qFull = [0.0  -0.4  0.0   0.0  0.0                  1.0                 -1.0  0.0
             0.0   0.0  0.0   0.0  0.0                  0.0                  1.0  0.0
             0.0   0.0  0.0  -1.0  0.0                  0.0                  0.0  1.0
             0.0   0.0  0.0   0.0  0.8682431421244592  -0.4961389383568338   0.0  0.0]
    
    
    
nonsing=true::Bool

qRows=4::Int64

qCols=8::Int64

bCols=4::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm firmvalue3Leads2Lags example
function firmvalue3Leads2LagsFalse()::Bool


neq=4::Int64;nlag=2::Int64;nlead=3::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64


    bb = [0.0  0.03748035941322162  0.0  0.0  0.0  0.31178973986873654  0.0  0.0
          0.0  0.4                  0.0  0.0  0.0  0.0                  0.0  0.0
          0.0  0.0                  0.0  0.0  0.0  0.0                  0.0  0.0
          0.0  0.0                  0.0  0.0  0.0  0.0                  0.0  1.0]

    qFull = [0.0  -0.4  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   1.0  -1.0   0.0   0.0                  0.0                   0.0   0.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   0.0   1.0   0.0   0.0                  0.0                   0.0   0.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0  -1.0  0.0                   0.0   0.0   1.0   0.0                  0.0                   0.0   0.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0  -0.4  0.0   0.0  0.0                   0.0   0.0   0.0   0.0                  1.0                  -1.0   0.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   0.0   0.0   0.0   0.0                  0.0                   1.0   0.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   0.0   0.0  -1.0   0.0                  0.0                   0.0   1.0   0.0                   0.0                   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                  -0.4   0.0   0.0   0.0                  0.0                   0.0   0.0   0.0                   1.0                  -1.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   0.0   0.0   0.0   0.0                  0.0                   0.0   0.0   0.0                   0.0                   1.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.0                   0.0   0.0   0.0   0.0                  0.0                   0.0  -1.0   0.0                   0.0                   0.0  1.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.45595531516699267   0.0   0.0   0.0   0.4145048319699937  -0.5117343604567817    0.0   0.0   0.37682257451817575  -0.4652130549607117    0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.5568038981295276    0.0   0.0   0.0  -0.691462063428306   -0.42173953480091186   0.0   0.0   0.16843336499306558   0.39276202066712307   0.0  0.0
             0.0   0.0  0.0  0.0  0.0   0.0  0.0   0.0  0.5568038981295276    0.0   0.0   0.0   0.1852767014923728  -0.25538333444596095   0.0   0.0  -0.6286018758439149   -0.21595043972258265   0.0  0.0]

    


nonsing=true::Bool

qRows=12::Int64

qCols=20::Int64

bCols=8::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm example7 example
function example7False()::Bool


neq=4::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.0  0.0  0.0  -0.6551413498221794 
          0.0  0.0  0.0  -0.2945196982393073 
          0.0  0.0  0.0  -0.663971668063238  
          0.0  0.0  0.0   0.33602833193676196]

    qFull = [0.0  0.0  0.0   1.0    0.0                  0.0                 1.0  -1.0               
             0.0  0.0  0.0  -0.66   0.0                 -1.1                 0.0   1.0               
             0.0  0.0  0.0   0.0   -0.0975566814665525   0.6633063548617442  0.0   0.3911675266675514
             0.0  0.0  0.0   0.0   -0.6659334978845683   0.6633063548617442  0.0  -0.7169746129238466]

    
nonsing=true::Bool

qRows=4::Int64

qCols=8::Int64

bCols=4::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm oneEquationNoLead example
function oneEquationNoLeadFalse()::Bool


neq=1::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64

    bb = [-0.6666666666666666]
    qFull = [2.0  3.0]

    

nonsing=true::Bool

qRows=1::Int64

qCols=2::Int64

bCols=1::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm reliablePaperExmpl example
function reliablePaperExmplFalse()::Bool


neq=5::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.0  0.0  0.0   0.0                     0.0
          0.0  0.0  0.0  -6.7324540449693005e-18  0.0
          0.0  0.0  0.0   0.21410138764106365     0.0
          0.0  0.0  0.0   0.3612359521871581      0.0
          0.0  0.0  0.0   0.5307470047448345      0.0]

    qFull = [0.0  0.0  0.0  -0.5  0.0  0.0                 -1.0   0.7                 -0.5                  1.0                
             0.0  0.0  0.0   0.0  0.0  1.0                  0.0   0.0                  0.0                  0.0                
             0.0  0.0  0.0   0.0  0.0  0.0                  1.0   0.0                  0.0                  0.0                
             0.0  0.0  0.0   0.0  0.0  0.5485719295558827   0.0  -0.5485719295558827  -0.4750371695866738   0.5446107336163881 
             0.0  0.0  0.0   0.0  0.0  0.5485719295558821   0.0  -0.5485719295558827   0.5083873480804076  -0.12472567123898434]



nonsing=true::Bool

qRows=5::Int64

qCols=10::Int64

bCols=5::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm athan example
function athanFalse()::Bool


neq=9::Int64;nlag=1::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.8285973383130333  0.29644852356208407  -0.1136903369158254   0.2123317657422602  0.0  0.0  0.0  0.0  0.0
          0.293               0.764                -0.293                0.0                 0.0  0.0  0.0  0.0  0.0
          1.9501946766260663  1.3568970471241681   -0.5203806738316508  -0.4863364685154796  0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.911               0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.0                 0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.0                 0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.0                 0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.0                 0.0  0.0  0.0  0.0  0.0
          0.0                 0.0                   0.0                  0.0                 0.0  0.0  0.0  0.0  1.0]

    qFull = [-0.293               -0.764  0.293   0.0    0.0  0.0  0.0  0.0   0.0   0.0                   1.0                  0.0                    0.0                   0.0                -1.0  0.0   0.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0  -2.0                  -1.0                  1.0                    1.0                   0.0                 0.0  2.0   0.0  0.0
             0.0                  0.0    0.0    -0.911  0.0  0.0  0.0  0.0   0.0   0.0                   0.0                  0.0                    1.0                   0.0                 0.0  0.0  -1.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0   0.0                   0.0                  0.0                    0.0                   1.0                 0.0  0.0   0.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0   0.0                   0.0                  0.0                    0.0                   0.0                 1.0  0.0   0.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0   0.0                   0.0                  0.0                    0.0                   0.0                 0.0  1.0   0.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0   0.0                   0.0                  0.0                    0.0                   0.0                 0.0  0.0   1.0  0.0
             0.0                  0.0    0.0     0.0    0.0  0.0  0.0  0.0  -1.0   0.0                   0.0                  0.0                    0.0                   0.0                 0.0  0.0   0.0  1.0
             -0.3817706346518516   0.0    0.0     0.0    0.0  0.0  0.0  0.0   0.0   0.44720713758510167  -0.25061276945656796  0.043403632078137605  -0.08106203296417115  -0.763541269303705   0.0  0.0   0.0  0.0]
    

nonsing=true::Bool

qRows=9::Int64

qCols=18::Int64

bCols=9::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;

#tweaked= False
# test reducedForm habitmod example
function habitmodFalse()::Bool


neq=12::Int64;nlag=4::Int64;nlead=1::Int64
qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64



    bb = [0.027529882897901037   0.0   0.020467530857423755    0.0038416784149892594   0.051046607327035705   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.15012534765546548   0.0   0.08029132274276037   -0.056963369207146564    0.03322266066687063    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007627389625308317  0.0   0.1320035761063429     -0.0009755753374600662   0.14090688019805095   0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.4095923144682544    0.5315642840603882     0.2817431056881394    -0.3703087678463335    -0.007157375002846328  0.0   0.0005945790003054317  0.0  0.0  0.0  0.0   0.024731911161695656
          0.0                    0.0   0.0                     0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                     0.0                     0.0                   0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0                   0.88879                0.0                    0.0                    0.0                   0.0   0.0                    0.0  0.0  0.0  0.0   0.0                 
          -0.52802                0.0  -0.11279                -0.031833               -0.024734               0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.71526               0.0  -0.042076               0.22829                 0.012267               0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.22215               0.0   0.14172                -0.26679                 0.11959               0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.42308               0.0                    0.61076                0.10946               -0.17172               0.0   0.0                    0.0  0.0  0.0  0.0   0.00011277          
          -0.46436                0.0  -0.16131                -0.02744                -0.17087                0.0  0.0  0.0  0.0  0.0  0.0  0.0   1.3425                0.0  -0.16794                0.35818                 0.09837                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.06382               0.0   0.02255                -0.51594                -0.08949               0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.46672               0.0                    0.11369                1.10657                0.26021               0.0   0.0                    0.0  0.0  0.0  0.0   0.00141             
          0.23292                0.0  -0.08512                 0.04213                -0.14149                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.03313               0.0  -0.15223               -0.01572                 0.34762                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.70552               0.0   0.24697                -0.21888                 0.07805               0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.56316               0.0                    0.08268                0.16054                0.68637               0.0   0.0                    0.0  0.0  0.0  0.0   0.00348             
          -0.048656191278364076   0.0  -0.01435815694959172    -0.003615028856553198   -0.016368081496278854   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.09639330877255069   0.0  -0.026205246565025028   0.03374738431205661    -0.009078892369366393   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.01783229151921311   0.0  -0.027643179394700654   -0.019296742740011977   -0.0320882065933294    0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.04104155816098312   0.10522232527184341   -0.034898491957179305   0.11516795458939615   -0.01250204426078594   0.0   1.5662824613858076e-5  0.0  0.0  0.0  0.0   0.026576938861786678
          0.0                    0.0   0.0                     0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                     0.0                     0.0                   0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.99853               0.0                    0.0                    0.0                    0.0                   0.0   0.00147                0.0  0.0  0.0  0.0   0.0                 
          0.02655167093142119    0.0   0.0197580491085966      0.0037021774397180884   0.04925739354472667    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.14500408462947548   0.0   0.0774512015680859    -0.05496735589458942     0.0320274233308213     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.007611617912634973  0.0   0.1273227241049132     -0.0008541124830458252   0.13588475634875305   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -25.513272789068484     0.51275618564965       0.27178985476340195   -0.357279854213434     -0.006907594035317548  0.0  -0.0375677199441755     0.0  0.0  0.0  0.0   0.023860003901632107
          0.5215165039059954     0.0   0.11430026751385268     0.030927610354077855    0.028282616802858217   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.7248779895273255    0.0   0.046780072389684756  -0.22915333931505477    -0.015576398033474643   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.23264594755314852   0.0  -0.140071813325273       0.2713753498778849     -0.12210781291063869   0.0  0.0  0.0  0.0  0.0  0.0  0.0   -0.4211158265242967    0.01729923474036577   -0.6038943494604492    -0.11568142124889205    0.15391702207536825   0.0   2.227748839177592e-6   0.0  0.0  0.0  0.0   0.00504551742734064 
          0.02357958761338304    0.0  -0.08180944745427418     0.010805320523198469   -0.15250184855880328    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.436271393571471     0.0  -0.24645620531886603    0.12726448714723773     0.02848652465019152    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.24876213695812227   0.0  -0.22105757949745672    -0.1108151301732796     -0.09704336570703259   0.0  0.0  0.0  0.0  0.0  0.0  0.0   25.523235819797833    -0.9479881839508931    -0.4163263363976896     0.6148597806956546     0.4201378458108254    0.0   0.037509284219634904   0.0  0.0  0.0  0.0  -0.15216162500603309 
          -0.0020115574774817856  0.0   0.0024809211674339513  -0.0005814485947963202   0.0041251063719627695  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.011636485827417576  0.0   0.006753093019579219  -0.0028851347667365676  -0.0024281673561649332  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.009653364628833686  0.0   0.0037311171010123876   0.004470914458955043   -0.001578136025136179  0.0  0.0  0.0  0.0  0.0  0.0  0.0   -0.9989961535611305    0.017337742138220126   0.005740454170615235  -0.010251714541712925  -0.016542836892484758  0.0  -0.0014677581599157072  0.0  0.0  0.0  0.0   0.005132605941010024
          0.0                    0.0   0.0                     0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                    0.0                     0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                   0.0   0.0                     0.0                     0.0                   0.0  0.0  0.0  0.0  0.0  0.0  0.0    0.0                   0.0                    0.0                    0.0                    0.0                   0.0   0.0                    0.0  0.0  0.0  0.0   1.0]


    
    qFull = [0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                     0.0       0.0                     0.0                     0.0                     0.0   0.0      0.0  0.0  0.0  0.0   0.0   1.0                     -1.0                     -1.0                    0.0                     0.0                     3.454185377005518        0.0                   0.0                    -0.74118                0.0020851713324080146   0.49411642948057477    -0.1149               
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    -0.88879   0.0                     0.0                     0.0                     0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.0                      1.0                      0.0                    0.0                     0.0                     0.0                      0.0                   0.0                     0.0                    0.0                     0.0                     0.0                  
             0.52802  0.0  0.11279   0.031833  0.024734  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.71526                0.0   0.042076               -0.22829                 -0.012267                0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.22215                0.0  -0.14172                 0.26679                 -0.11959                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.42308                 0.0      -0.61076                -0.10946                 0.17172                 0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.0                      0.0                      1.0                    0.0                     0.0                     0.0                      0.0                   0.0                     0.0                    0.0                     0.0                    -0.00011277           
             0.46436  0.0  0.16131   0.02744   0.17087   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.3425                 0.0   0.16794                -0.35818                 -0.09837                 0.0  0.0  0.0  0.0  0.0  0.0  0.0   1.06382                0.0  -0.02255                 0.51594                  0.08949                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.46672                 0.0      -0.11369                -1.10657                -0.26021                 0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.0                      0.0                      0.0                    1.0                     0.0                     0.0                      0.0                   0.0                     0.0                    0.0                     0.0                    -0.00141              
             -0.23292  0.0  0.08512  -0.04213   0.14149   0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.03313                0.0   0.15223                 0.01572                 -0.34762                 0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.70552                0.0  -0.24697                 0.21888                 -0.07805                0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.56316                 0.0      -0.08268                -0.16054                -0.68637                 0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.0                      0.0                      0.0                    0.0                     1.0                     0.0                      0.0                   0.0                     0.0                    0.0                     0.0                    -0.00348              
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.99853                 0.0       0.0                     0.0                     0.0                     0.0  -0.00147  0.0  0.0  0.0  0.0   0.0   0.0                      0.0                      0.0                    0.0                     0.0                     0.0                      1.0                   0.0                     0.0                    0.0                     0.0                     0.0                  
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                     0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                    0.0   0.0                     0.0                      0.0                    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0                     0.0       0.0                     0.0                     0.0                     0.0   0.0      0.0  0.0  0.0  0.0  -1.0   0.0                      0.0                      0.0                    0.0                     0.0                     0.0                      0.0                   0.0                     0.0                    0.0                     0.0                     1.0                  
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   8.477325348273948e-6   0.0   1.1737551566453782e-6   6.438504491140261e-7    -3.2212814098871563e-7   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -1.0141837764993982e-5  0.0  -1.290569629952694e-7   -3.263768522769671e-6     1.4707395335235414e-6  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -2.397166450442443e-7    0.0      -8.116540081425253e-7    2.689733129477345e-6   -1.2979305662448641e-6   0.0   0.0      0.0  0.0  0.0  0.0   0.0  -0.03708042573632686     -4.855927150699948e-5    -4.881211588640728e-5  -5.493368498380228e-6    5.638277691209124e-6    0.0001934771491334187    0.9985709034657091    0.0384856845466372     -4.067309088056605e-5   1.144261354928439e-7    2.7115197984086615e-5  -6.263733239886542e-6 
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.04899705783402774    0.0  -0.01120063003324614    -0.0041908808538570355   -0.011985374512245739    0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.08955474739288391    0.0  -0.020726693191700216    0.031173432412953613    -0.016086348259092616   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.000792326481880088    0.0      -0.031174251114590296   -0.012869952348978147   -0.031202323408062196    0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.024657869055016407     0.09586248802299646      0.1271324275479889     0.12543970366338042    -0.02594033480294185    -0.9447706721679326      -0.10949539634129295  -0.0005099139759182568   0.1621783934696507    -0.0004562585833385613  -0.10811814771057904     0.02407773726347739  
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0032969809188035095  0.0   0.0007065518814006049   0.00022528093791596984   0.0003290802651319052   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.002459648796279586   0.0   0.0010831489569940011  -0.0014603914314449918    0.0004086346563548683  0.0  0.0  0.0  0.0  0.0  0.0  0.0   3.790579464096496e-5    0.0       0.000721688330498851    0.0004926600336232699   0.00021364639192133385  0.0   0.0      0.0  0.0  0.0  0.0   0.0  -3.073009005820629e-15   -2.3534288462992786e-14   0.4898458201841746    -0.0021891779921598105   0.0009912407709166623   1.9223723553953657e-12  -0.509098441610823    -0.0007414741467501591   0.4916701875272666    -0.0007383405240319134  -0.5090201801345099     -1.8388707037398475e-5
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.003643145263829      0.0   0.0007807358318102284   0.00024893416196507495   0.00036363183117568666  0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.0027178980047612962  0.0   0.0011968734697510796  -0.0016137242699783073    0.0004515389835914196  0.0  0.0  0.0  0.0  0.0  0.0  0.0   4.1885688268979986e-5   0.0       0.0007974615223329046   0.0005443865499711582   0.00023607805436863535  0.0   0.0      0.0  0.0  0.0  0.0   0.0   3.693669555075654e-15    2.7135130248811612e-14   0.541276860203469     -0.002419029296208815    0.0010953154446671119  -1.025245807949531e-12   -0.4535625006640263    0.0035433989458416113   0.5432927757972709     0.0035284238108551826  -0.453954433367246      -2.03194166257265e-5  
             0.0      0.0  0.0       0.0       0.0       0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.0029638430910210504  0.0   6.603929128961849e-5   -0.00028173972559416606   0.0009223540969435295   0.0  0.0  0.0  0.0  0.0  0.0  0.0  -0.0024054954219422026  0.0   0.0008945409686296616   0.00015390361311534015  -0.0005847564942789633  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0022347988133203534   0.0       0.0009226800534779761   0.0008343902524113385   0.00028666846109542244  0.0   0.0      0.0  0.0  0.0  0.0   0.0   0.00016313960259124535   0.0012581950656749652   -0.5851001427047119    -0.0034498218571154976  -0.0042902958192899306   0.027546775726307662     0.3932584298341381    0.0016655240839675194  -0.5896343241644627     0.0016588259119062225   0.39308670895798836     0.000519753808703009]
    
nonsing=true::Bool

qRows=12::Int64

qCols=60::Int64

bCols=48::Int64

anEpsi=0.0000000001::Float64

(nonsingJulia,bbJulia)=reducedForm(qFull,qRows,qCols,bCols,neq,anEpsi)
isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&&
nonsingJulia==nonsing
end;


end
