Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

f(leftVarlist)== f(rigthVarList)=solve(sysEqu,leftVarList,rigthVarList)

I will find it convenient that SageMath would have a solve function like this:

sysEqu=[] # system of equations ; leftVarList=[] # left variables list ; rightVarList=[] # right variables list

solve(sysEqu,leftVarList,rigthVarList) It will return f(leftVarlist)== f(rigthVarList) if possible and return [] if not.

Maybe it is too hard to write this kind of function ? (I know simplification is difficult subject in math soft), or maybe the solve function is already able to do this, and I just need to set it up correctly ? (Sorry if it is the case!)

To illustrate my proposal I started to write a draft of this kind of function, (badly written, and which does not work correctly!) :

varL=[]
# all red segments
varL.append(var("A",latex_name=r"\color{red}{A}"))
varL.append(var("Ap",latex_name=r"\color{red}{A'}"))
varL.append(var("App",latex_name=r"\color{red}{A''}"))
# all green segments
varL.append(var("AppX",latex_name=r"\color{green}{\overline{A''X}}"))
varL.append(var("AU",latex_name=r"\color{green}{\overline{AU}}"))
varL.append(var("ApY",latex_name=r"\color{green}{\overline{A'Y}}"))
# all pink segments
varL.append(var("AX",latex_name=r"\color{pink}{\overline{AX}}"))
varL.append(var("ApW",latex_name=r"\color{pink}{\overline{A'W}}"))

# all blue segments
varL.append(var("X",latex_name=r"\color{blue}{X}"))
varL.append(var("U",latex_name=r"\color{blue}{U}"))
varL.append(var("W",latex_name=r"\color{blue}{W}"))
varL.append(var("Y",latex_name=r"\color{blue}{Y}"))

varL.append(var("Z",latex_name=r"\color{orange}{Z}"))


for v in varL :
    assume(v,'real')
    assume(v!=0)

eqL=[
 AppX/X == AU/U,
 AppX/X == ApY/Y,
 App/X == A/U,
 App/X == Ap/Y,
 AppX/App == AU/A,
 AppX/App == ApY/Ap,
 A/X == Ap/W,
 A/X == -(A - Ap)/(W - X),
 A/AX == Ap/ApW,
 X/AX == W/ApW,
 AU/AX == ApY/ApW,
 AU/(U - X) == -ApY/(W - Y),
 AX/(U - X) == -ApW/(W - Y),
    ]

show(varL)

index=0
latexL=[]
for eq in eqL :
    show(" equ # : ",index," \t : ",eq," \t valid =",eq.is_exact())
    latexL.append(r"\text{equ #} "+str(index)+" : "+latex(eq))
    index+=1




def isTheSame(t0,t1):
    #test if tuple or list have same elements notwithstanding order
    t0l=len(t0) ;t1l=len(t1)
    if t0l!=t1l :
        return False
    for tt in t0:
        if tt not in t1 :
            return False
    return True

# I have to tinker !!
# Do It YourSelf function which does not work correctly.


def solvit(eq0L,vare,mainVariables) :
    advanticeVariablesL=[]
    for eq in eq0L :
        vart=eq.variables()
        for v in vart :
            if v not in mainVariables :
                if v not in advanticeVariablesL :
                    advanticeVariablesL.append(v)
    mainVariables=tuple(mainVariables)
    advanticeVariables= tuple(advanticeVariablesL)   
    show("advantice Variables : ",advanticeVariables)
    #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              show("main :",mainVariables)   

    #stopLoop=False
    #solution=0==0
    for indexAdv in range(0,len(advanticeVariables)-1):
        #if stopLoop:
        #    break    
        v=advanticeVariables[indexAdv]
        #show("var to remove : ",v," : ",indexAdv)
        equLength=len(eq0L)-1
        indexEq=0
        while indexEq < equLength :
            #if stopLoop:
            #    break
            #show("indexEq : ",indexEq)
            if v  in (eq0L[indexEq]).variables(): # look for unwanted variables
                sol=solve(eq0L[indexEq],v)
                eq0L.remove(eq0L[indexEq])
                equLength-=1
                #show("eq0L length : ",equLength)
                for indexEq in range(0,equLength-1):# replace v in all other equ
                    eqt=eq0L[indexEq].subs(sol).simplify_full()
                    eq0L[indexEq]=eqt
                    soleqt=solve(eqt,vare)
                    if len(soleqt)>0 :
                        #show("soleqt : ",soleqt)
                        if isTheSame(soleqt[0].variables(),mainVariables) :
                            solution=soleqt[0]
                            #show("solution : ",solution)
                            return [solution,eq0L,indexAdv,advanticeVariables[indexAdv]]
                            #stopLoop=True
                            #break
            indexEq+=1
    return [0==1,eq0L,indexAdv,advanticeVariables[indexAdv]]
solution,remainingEquationsL,indexAdv,Adv=solvit(copy(eqL),W,[U,X,Y,W])

show("solution : ",solution," \t len remainingEquationsL : ",len(remainingEquationsL),
     " \t step :",len(eqL)-len(remainingEquationsL),"\t index Adv :",indexAdv,"\t Adv : ",Adv)

# attempt with solve only

show("With solve only W  ",solve(eqL,W))
show("With solve [U,W,X,Y] ",solve(eqL,[U,W,X,Y]))
show("With solve only only W sol dict",solve(eqL,W,solution_dict=True))
show("With solve [U,W,X,Y] and sol dict",solve(eqL,[U,W,X,Y],solution_dict=True))

complete code on SageCell