LoadError: MethodError: no method matching abs2(::Expression)

I am new to Julia. My collaborators sent me some code that do run for them but I cannot run it myself. We cannot figure out what is wrong since the code does run for them. I tried two different computers, and versions 1.6 and 1.7 of Julia. The code is a bit intricate so I am not sure how to make a minimal example. But it seems that the culprit line is

if rank(A₀) == r

The error is the following. Any help with this would be greatly appreciated.

LoadError: MethodError: no method matching abs2(::Expression)
Closest candidates are:
abs2(!Matched::Complex) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/complex.jl:278
abs2(!Matched::Static.StaticBool) at ~/.julia/packages/Static/pkxBE/src/bool.jl:69
abs2(!Matched::ForwardDiff.Dual{T}) where T at ~/.julia/packages/ForwardDiff/PBzup/src/dual.jl:206

It’s difficult to help you debug without a full example. Can you post the full stack trace, and the offending line?

What is the type of A₀ in your example (try printing the type so you’re sure)

Thanks for the fast response.

A₀ is a big matrix. I am not sure how to print it all, below are the outputs of A₀, print(A₀), I am not sure how to print the type but in Atom it displays 10x36 Matrix{Expression}

The error appears when I try rank(A₀)

A₀
10×36 Matrix{Expression}:
(-0.0227219578001591 - 0.422480016844678*im)1.0 … (0.158404212254316 - 0.470760064446835im)1.0
(-0.363230448627778 + 0.277625110054317
im)1.0 (-0.177775524911789 + 0.186951062950722im)1.0
(-0.483238575498125 - 0.00607155350001037
im)1.0 (-0.687096897759273 - 0.322417209262124im)1.0
⋮ ⋱ ⋮
(-0.83688965473742 - 0.499633148239493
im)1.0 (-0.362096353058375 - 0.252304962789763im)1.0
(1.00305591603545 - 0.434262337115269
im)1.0 (0.700077748231447 + 0.135574684601314im)1.0
(-0.648212889465812 - 0.343300997789296
im)1.0 (-0.634113264140921 - 0.0286188119942764im)*1.0

print(A₀)
Expression[(-0.0227219578001591 - 0.422480016844678*im)1.0 (-0.176805162919808 - 1.36909745038936im)1.0 0 (-0.113759291416685 - 0.419212807603875im)1.0 (0.43502278525862 - 0.972608834668064im)1.0 0 (-0.0552282999978272 - 0.345988213733287im)1.0 (1.9079232146038 - 2.15604362519947im)1.0 (0.191806822356972 - 0.479683035131056im)1.0 (-0.372059920873352 - 0.50799199183766im)1.0 (0.059353612201793 - 0.552056938517865im)1.0 (-0.225445831384135 - 0.704313668488489im)1.0 0 (-1.45419103991986 - 0.364794070923291im)1.0 (0.0491805414991188 - 0.335697205685168im)1.0 0 (-0.480623923478617 - 0.623347374504752im)1.0 (0.120764995264585 - 0.450116256876092im)1.0 (0.05478935500661 - 0.512616575822483im)1.0 (-0.283250301669295 - 0.76478481257285im)1.0 (0.121285074429568 - 0.439463772987406im)1.0 (-0.510082157601875 - 0.612230472052037im)1.0 (-0.0515544660577659 - 0.439248258414057im)1.0 (0.0630546052799014 - 1.19731114157226im)1.0 (-0.958374493302907 - 1.34970982591049im)1.0 (0.0193954201002144 - 0.385719823540889im)1.0 (-0.0501534501086554 - 0.62481471412048im)1.0 (-0.0414027295937509 - 0.66932500547456im)1.0 (-0.00141027557620835 + 0.203232408443796im)1.0 (-0.00289881943057545 - 0.124951281180294im)1.0 (0.0443031446640856 - 0.432314307581997im)1.0 (-0.547562267104361 - 0.951564265587703im)1.0 (0.0125107037079468 - 0.153032174070393im)1.0 (-0.0614612149875904 + 0.279516114714835im)1.0 (-0.407943598452084 - 0.554032299152744im)1.0 (0.158404212254316 - 0.470760064446835im)1.0; (-0.363230448627778 + 0.277625110054317im)1.0 (-0.196131692470743 + 0.215007249185882im)1.0 (-0.539396306718809 + 0.149042438800767im)1.0 (-0.532716331581455 - 0.87078917518302im)1.0 (0.0159082913956884 - 0.488251700063881im)1.0 (-1.89692347660684 + 0.0601664615957525im)1.0 0 0 (-0.67333394367882 - 0.161924820640921im)1.0 (-0.602128263475503 + 0.591549731234874im)1.0 (-0.349727836027945 + 0.146585625436794im)1.0 (-0.260777721686002 - 0.422313080228475im)1.0 (-0.765817206446699 + 0.303487275380457im)1.0 (0.588579497035629 - 1.69387364233536im)1.0 (-0.189340090409066 + 0.35098695902929im)1.0 (-0.890995450439766 + 0.0360954609247952im)1.0 0 0 (-0.690594705678048 + 0.026192080054246im)1.0 (-0.959914227492311 + 0.523267404502669im)1.0 (-0.417431602422484 + 0.127517177541302im)1.0 (-0.168761328517023 + 0.026014897356257im)1.0 (-0.127532931029805 + 0.0164121465168957im)1.0 (0.348291659755459 + 0.0144498769749484im)1.0 (-1.67501919359279 - 5.10971799920805im)1.0 (0.279013891834672 - 0.0315048811029559im)1.0 (0.181486119463051 - 0.0166064338381099im)1.0 (-0.194454704563452 + 0.0142066881980082im)1.0 (-0.97513170535743 + 0.257474473191995im)1.0 (-0.594634011064192 + 0.176335527037355im)1.0 (-0.280148510172573 + 0.237783109752657im)1.0 (0.0761338064058803 - 0.417842247373308im)1.0 (-0.749150288939058 + 0.139046735360928im)1.0 (-1.41853517718152 + 0.0690638398793559im)1.0 (-0.106301840789336 - 0.773783772150101im)1.0 (-0.177775524911789 + 0.186951062950722im)1.0; (-0.483238575498125 - 0.00607155350001037im)1.0 (-0.870705103640899 - 0.0153853523348779im)1.0 (-0.450209432849268 + 0.0721933071223274im)1.0 (-0.31443662475958 - 0.0256120418181518im)1.0 (0.207479298366818 + 1.0585885954966im)1.0 (-0.772840277677019 + 0.566305822659641im)1.0 (-0.429835586961747 - 0.0548318502242555im)1.0 (-2.47695260366038 + 1.0515251970777im)1.0 (-0.403563932948304 - 0.437224172331395im)1.0 (-0.479048906385449 - 0.278310909727679im)1.0 (-0.304264216818393 - 0.490144996292566im)1.0 (-0.330451224401307 - 0.266220540074427im)1.0 (-0.200611662867065 - 0.452856003368121im)1.0 (0.112011744640171 - 0.789676553441911im)1.0 (-0.200150736035772 - 0.152471368759965im)1.0 (-0.236321648067595 - 0.233479370697983im)1.0 (-0.358161549234799 - 0.622721003771431im)1.0 (-0.27289696478187 - 0.169856766462714im)1.0 (-0.531616186157721 - 0.0760534300924227im)1.0 (-0.599195628691938 - 0.249354305813306im)1.0 0 0 (-0.373334663052908 - 0.166701499520814im)1.0 (-0.921396827594605 - 0.616134836732861im)1.0 0 0 (-0.52009600687523 - 0.255542960392836im)1.0 (-0.551320316282984 - 0.283537680853818im)1.0 (-0.634221213252168 - 0.285532827913444im)1.0 (-0.395140778908615 - 0.163762968493797im)1.0 (-0.43803176520977 - 0.229722176751196im)1.0 (-0.503995034724413 - 0.400691650571469im)1.0 (-0.461726506675507 - 0.25084139819757im)1.0 (-0.789945084701347 - 0.57902670967131im)1.0 (-0.518738581942027 - 0.156182216719862im)1.0 (-0.687096897759273 - 0.322417209262124im)1.0; (0.38025580802419 - 0.189174483029972im)1.0 (0.103781860970975 - 0.106932455329827im)1.0 (0.402125431671682 - 0.184550002923462im)1.0 (0.602712918436325 - 0.295574682996897im)1.0 (1.58802382720431 + 0.0869806596724265im)1.0 (0.723975809821448 + 0.543676287258382im)1.0 (0.471029751486134 - 0.224213649227989im)1.0 (-0.523857318788077 + 1.17325182290365im)1.0 (0.475484354647435 - 0.435746537303151im)1.0 (0.30352441858943 - 0.518182162676153im)1.0 (0.0918770024490262 - 0.33424314956995im)1.0 (0.0125561722575714 - 0.477830691853875im)1.0 (0.0428276132273132 - 0.286816392757618im)1.0 (-0.218097162618519 + 0.137478022169395im)1.0 (-0.21065578526602 - 0.499995742465076im)1.0 (-0.17911381444463 - 0.488478868726357im)1.0 (0.114899460815826 - 0.232379435478212im)1.0 (-0.0887228147810352 - 0.504309860838753im)1.0 (0.0844934466944798 - 0.575944118114513im)1.0 (0.272602031525106 - 0.648525612506717im)1.0 (0.257952080421829 - 0.309632225437752im)1.0 (0.187760213957171 - 0.310647831087605im)1.0 (0.0507937089614992 - 0.0816034478904605im)1.0 (-0.173036508106581 + 0.194835457300964im)1.0 (-0.213420515092932 - 2.54943361417697im)1.0 (-0.262733613072223 - 1.12816042913539im)1.0 (-0.0761898882726032 + 0.112935190416854im)1.0 (0.083710837726795 - 0.119309656571405im)1.0 (-0.105981229381246 + 0.173912069303639im)1.0 (0.0619232918619241 - 0.108865930363868im)1.0 0 0 (0.0896409307097483 - 0.125052204582129im)1.0 (-0.19690883884007 + 0.208506049014298im)1.0 0 0; (-0.351949947296285 - 0.107555414548146im)1.0 (-0.315957135484378 - 0.531991241355158im)1.0 (-0.413593670058635 - 0.0537584330450224im)1.0 (-0.396633329374363 + 0.14823215140143im)1.0 (-1.78309209712731 + 0.93980156179096im)1.0 (-1.32021486492912 - 0.507714283249063im)1.0 (-0.348431277569605 - 0.0336107358877534im)1.0 (-1.60489593980881 - 2.38702353914249im)1.0 0 0 (-0.590950798394968 + 0.0719969526771932im)1.0 (-0.393236064079331 - 0.110888516923497im)1.0 (-0.613800542099261 - 0.0132204218302443im)1.0 (-1.43483651358437 + 0.213526475923232im)1.0 (-0.556080464208513 - 0.310880725038406im)1.0 (-0.622379932923152 - 0.233095196624344im)1.0 (-0.723596629968965 + 0.307959137712595im)1.0 (-0.404854261690117 - 0.229968680076858im)1.0 0 0 (-0.368707952215968 - 0.159678246935475im)1.0 (-0.349942605050107 - 0.0922512572354645im)1.0 (-0.530021543859149 - 0.0862575382628993im)1.0 (-0.906820234032756 - 0.251346178291924im)1.0 (-2.37862810243194 + 0.921004969878754im)1.0 (-1.00525558541992 + 0.568535985663966im)1.0 (-0.487306665584091 - 0.0675160323112341im)1.0 (-0.795257014393794 - 0.174819223287971im)1.0 (-0.548085023422577 - 0.0529306748759582im)1.0 (-0.580976900239383 - 0.0796222171731583im)1.0 (-0.523806995729453 - 0.106547756391308im)1.0 (-0.643747872404467 - 0.26413944499858im)1.0 (-0.699582054970163 - 0.171916227746426im)1.0 (-0.739422407768445 - 0.233418277368678im)1.0 (-0.585432229630618 - 0.00591967035458046im)1.0 (-0.810225269660619 - 0.12776769740131im)1.0; (-0.00578723604121578 - 0.770660887020148im)1.0 (-0.147123523400188 - 0.232091926626601im)1.0 (0.629553232702459 - 0.564464034877414im)1.0 (0.144284406795747 - 0.593617906526961im)1.0 (-0.325758589799237 - 1.04219854641231im)1.0 (0.373136828929618 - 1.08509975725085im)1.0 (0.0975149533341126 - 0.651275770206538im)1.0 (-0.826925326712697 - 1.5324678881409im)1.0 (0.105480125092731 - 1.11225306351278im)1.0 (0.337628552740896 - 0.188825579142035im)1.0 (-0.0974680658140036 - 0.839549249208011im)1.0 (0.120580486794932 - 0.438775735177061im)1.0 (0.409335278222222 - 0.595774274213158im)1.0 (0.521488544789936 - 0.176339310932662im)1.0 (0.0468371402586581 - 0.784817666453215im)1.0 (0.720722874812555 - 0.697247168164526im)1.0 (-0.085169123694325 - 0.394731311676561im)1.0 (0.0863291626253356 - 0.718364099596952im)1.0 (0.00379891727536225 - 0.974905087620351im)1.0 (0.114426574103693 - 0.145765195529625im)1.0 (0.0280797149324635 - 0.942064939864198im)1.0 (0.304472339765961 - 0.245028290990872im)1.0 (0.103734847458608 - 0.648958331136163im)1.0 (-0.447778848454443 - 0.707927859720303im)1.0 (-0.941104010684521 - 0.488664527398975im)1.0 (0.140615820317465 - 0.545963651569782im)1.0 (-0.0832393405324301 - 0.663069902695747im)1.0 (-0.0067616218884253 - 0.627756395440215im)1.0 (0.782974820237016 - 0.619614831137278im)1.0 (0.464009131118425 - 0.645282055424706im)1.0 (-0.00733233641266801 - 0.806478856448749im)1.0 (0.110785625065651 - 0.260860567081973im)1.0 (0.377491657705761 - 0.722605559307529im)1.0 (0.755411383059504 - 0.681016653904908im)1.0 (0.215956612890826 - 0.450851492353751im)1.0 (-0.0391927876360799 - 0.882306929654434im)1.0; (-0.842995435479778 + 0.389046956291242im)1.0 (-0.535905934072564 + 0.478624294225907im)1.0 (-0.7867208489144 + 0.190622118539558im)1.0 (-0.396023058951855 + 0.220439289699431im)1.0 (-0.130334171121971 + 0.218650160327511im)1.0 (-1.04852941718705 + 0.12077608397688im)1.0 (-0.45902918769747 + 0.772350212158491im)1.0 (-1.72537523932431 + 0.962386022787318im)1.0 (-0.422038702582466 + 0.0856168813633908im)1.0 (-1.02028331155754 + 0.691517152984832im)1.0 (-0.726807709967263 + 0.30167548039858im)1.0 (-0.443988745590679 + 0.39342024059772im)1.0 (-0.742481025063555 + 0.243937805903586im)1.0 (-0.0564512830168631 + 0.123128216158211im)1.0 (-0.830699131176358 + 0.550768638407872im)1.0 (-0.93614154659471 + 0.0885875837821994im)1.0 (-0.298842701195772 + 0.988750948339857im)1.0 (-0.584460575040784 + 0.738184179164018im)1.0 (-0.643702417170025 + 0.0843958386623094im)1.0 (-1.06731967352911 + 0.473822221035824im)1.0 (-0.655101928590945 + 0.309301766425231im)1.0 (-0.669427808654997 + 0.581827569147233im)1.0 (-0.556329631365823 + 0.738805512346202im)1.0 (-0.577880042117797 + 1.29665132367376im)1.0 (0.623481935079591 - 2.22772718312489im)1.0 (-0.580614815175612 + 0.848375262908039im)1.0 (-0.463447302287473 + 0.984236327966687im)1.0 (-0.62723307363924 + 0.78580578555863im)1.0 (-0.927609326779589 - 0.0286015911340772im)1.0 (-0.796607025870268 + 0.332121601955425im)1.0 (-0.774938830678151 + 0.427487844582649im)1.0 (-0.370279915628444 + 0.397729116636276im)1.0 (-0.801067658616166 + 0.3518942915411im)1.0 (-0.884600375725949 - 0.167695884763073im)1.0 (-0.331332640471838 + 0.329867411203293im)1.0 (-0.676079301678596 + 0.452717063447447im)1.0; (-0.83688965473742 - 0.499633148239493im)1.0 (-0.481397895540783 - 0.954465330537127im)1.0 (-0.942911665197185 - 0.616846210949681im)1.0 (-0.741049584602312 - 0.246964768634441im)1.0 (-1.65238850283442 - 0.596478789150877im)1.0 (-0.906718404363047 - 0.504096733688797im)1.0 (-0.740589466100642 - 0.30528128091987im)1.0 (-0.0924953421164174 - 3.29695235594858im)1.0 (-0.264814177483739 + 0.245158479611443im)1.0 (-0.3956168274802 - 0.478337444968717im)1.0 (-0.573754499019334 + 0.18271035952956im)1.0 (-0.76099925288273 - 0.0212435833117494im)1.0 (-0.787763589194024 + 0.255623350184603im)1.0 (-0.510886926784256 + 0.253604755605753im)1.0 (-0.780853944116609 - 0.153019621746965im)1.0 (-0.59542175794334 - 0.128856725921246im)1.0 (-0.377692887225522 + 0.0386603980221824im)1.0 (-0.86166225250306 - 0.104224267082307im)1.0 (-1.01758574186589 - 0.474603468510879im)1.0 (-0.665251443344886 - 0.00421246387531535im)1.0 (-1.99495221669322 - 0.163045845481702im)1.0 (-1.75693645795026 - 0.369086771341557im)1.0 (-0.957333168630812 - 0.232394244124588im)1.0 (0.609106747132226 - 0.173599798383007im)1.0 (-7.61752231034886 + 4.28865929439053im)1.0 (-4.13695235457901 + 1.19888996852788im)1.0 (-0.232903982993585 - 0.131672435691186im)1.0 (-0.856091918183136 - 0.421665755141786im)1.0 (0.0583476238614425 - 0.380334486905303im)1.0 (-1.00686878295424 - 0.383691356570701im)1.0 (-0.647599221456664 - 0.284740718367556im)1.0 (-0.458697696664716 - 0.268463823990342im)1.0 (-0.988835571462378 - 0.218432445545676im)1.0 (0.451249774110475 + 0.242646135339715im)1.0 (-0.595332520567108 - 0.245420719350711im)1.0 (-0.362096353058375 - 0.252304962789763im)1.0; (1.00305591603545 - 0.434262337115269im)1.0 (0.947661245610732 + 0.059704677922895im)1.0 (1.03266160775883 - 0.487584564193621im)1.0 (1.0396514355483 - 0.841899558511967im)1.0 (2.52715908709537 - 2.11906508488485im)1.0 (2.45696557648356 - 0.255454610958536im)1.0 (1.02719038978158 - 0.576304072794103im)1.0 (2.59809260684281 + 2.05991741605648im)1.0 (0.698700215938205 - 0.678053612598662im)1.0 (0.468506849766372 - 0.587186864917879im)1.0 (0.518403045575024 - 0.0323050598505458im)1.0 (0.21292933291674 - 0.0217800445061797im)1.0 (0.532072451198478 + 0.0796101119948767im)1.0 (1.13283917513391 + 0.761740838267612im)1.0 (0.0518120552591372 + 0.313720812456223im)1.0 (0.117749538353265 + 0.278724670608714im)1.0 (0.737263379518326 - 0.0289079260190905im)1.0 (0.0986695593994307 + 0.114026386075809im)1.0 (0.066337634649392 - 0.279148043289872im)1.0 (0.0916506894994693 - 0.542964430158825im)1.0 (0.563180463706355 - 0.400051753051042im)1.0 (0.431071528973186 - 0.263635717896964im)1.0 (0.646507120716445 + 0.0361889021542344im)1.0 (0.763643440747021 + 0.508428514867535im)1.0 (-1.79640366795467 - 1.81131605125665im)1.0 (-0.584545065877049 - 0.271617081922138im)1.0 (0.761419167988125 + 0.310781844647633im)1.0 (0.624208269213959 - 0.00485844052652275im)1.0 (0.779181319950815 + 0.42995568830108im)1.0 (0.610769066489246 + 0.0321205799220127im)1.0 (0.688849897595191 + 0.173926625299447im)1.0 (0.681811409903218 + 0.186940185966081im)1.0 (0.644541473787808 - 0.0500977601397517im)1.0 (0.809211270297669 + 0.48602001850433im)1.0 (0.694235397176898 + 0.133312385633983im)1.0 (0.700077748231447 + 0.135574684601314im)1.0; (-0.648212889465812 - 0.343300997789296im)1.0 (-1.33422088376575 - 1.04079811198443im)1.0 (-0.874720175403869 - 0.298648104924469im)1.0 (0.0696157544662989 - 0.475808484953935im)1.0 (0.278114965703694 + 0.713160614500387im)1.0 (0.00391937001801501 + 0.6679422894214im)1.0 (-0.173630817044423 - 0.385211270806204im)1.0 (-4.74881348696113 - 1.66177625051926im)1.0 (0.959271346206106 - 0.8650010781708im)1.0 (-0.441926667281789 - 1.38174438540598im)1.0 (-0.466284582891861 - 0.320964899729501im)1.0 (-0.515334209753872 - 0.601892710560427im)1.0 (-0.396552084849541 - 0.482743358716792im)1.0 (-0.324494587499992 + 1.62569448352786im)1.0 (-0.911894375481396 - 0.0500390967234768im)1.0 (-1.01231155644419 + 0.168887411293215im)1.0 (-0.129890450869534 + 0.317294185973317im)1.0 (-0.613709944782404 - 0.512767366566953im)1.0 (0.371522769395378 - 0.996404729628755im)1.0 (-0.365946796898746 - 1.50631375865645im)1.0 (-0.125079040772664 - 0.488215376262077im)1.0 (-0.642332917504649 - 0.682582569758359im)1.0 (-0.474823293508034 - 0.191350107445728im)1.0 (-1.10236518023717 + 0.00424227914330495im)1.0 (1.73176414915417 + 3.08049299720689im)1.0 (-0.674349131945734 + 1.69662943384386im)1.0 (-0.403655616827857 - 0.213490842417331im)1.0 (-0.887596275825092 - 0.0203144755565987im)1.0 (-0.747939302713471 - 0.157087879838644im)1.0 (-0.705755478428669 - 0.139943613001569im)1.0 (-0.635604226342135 - 0.176176717913435im)1.0 (-0.944149264294452 - 0.202839010154674im)1.0 (-0.554882710600282 - 0.082188140666782im)1.0 (-0.494649781505576 - 0.0314243752434464im)1.0 (-0.369734831213806 - 0.147408548289349im)1.0 (-0.634113264140921 - 0.0286188119942764im)*1.0]

Why is your matrix of type Expression? It looks like it only contains complex numbers.

You can try converting it, but I don’t know where the Expression type is from.
This command should show the module where the Expression type is defined:

@which Expression

You can print the type by typeof(A₀) or eltype(A₀).

Here are the outputs

@which Expression
HomotopyContinuation.ModelKit

typeof(A₀)
Matrix{Expression} (alias for Array{Expression, 2})

eltype(A₀)
Expression

Going back to the original issue, it’s likely that you’re missing a package that has the right abs2 defined, that they have. Did they also send a Project.toml, and did you instantiate it? Can you check Pkg.status on their environment and yours, and see what differs?

2 Likes

It looks like there is a to_number function HomotopyContinuation.ModelKit.to_number . But if the code works for others, that means something is missing here, and this would likely be just a band-aid solution. You can still try it (rank(to_number.(A₀))) and see how that changes things.

@digital_carver: this worked!

Actually, it kind of did not. I can compute the rank when I go line by line, but in the original code this is inside some for loops and it breaks again

No toml file, but I will ask about Pkg.status

I used the same patch in other instances where rank appeared and now the computation is going. Thanks a lot.

Still, best would be to also have their .toml file. That should make it possible to have a reproducible environment (same packages).