Skip to main content
Improved formatting
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

I have this function.

SetAttributes[zf,HoldAllComplete];
zf[x_] :=If[Denominator[Unevaluated[x]]==0= 
  If[Denominator[Unevaluated[x]] == 0,
     Numerator[Unevaluated[x]],
     Numerator[Unevaluated[x]]];

It is supposed to just return the numerator anytime the denominator is 0.

In[1]:= zf[1/0]
Out[1]= 1
In[2]:= 

1

Cos[-(3*Pi)/2]
Out[2]= 0
In[3]:= 

0

zf[1/Cos[-(3*Pi)/2]]
Out[3]= ComplexInfinity

ComplexInfinity

It works fine when the denominator is literally 0, but it fails when there are functions/variables, such as when Cos[x]==0Cos[x] == 0.

How would I go about evaluating the denominator separately, then if that equals 0zero, drop the denominator, and evaluate the numerator only without evaluating the entire fraction?

Basically my question is how do I make zf[1/Cos[-(3*Pi)/2]] output 1?

I have this function.

SetAttributes[zf,HoldAllComplete];
zf[x_]:=If[Denominator[Unevaluated[x]]==0,Numerator[Unevaluated[x]],Numerator[Unevaluated[x]]];

It is supposed to just return the numerator anytime the denominator is 0.

In[1]:= zf[1/0]
Out[1]= 1
In[2]:= Cos[-(3*Pi)/2]
Out[2]= 0
In[3]:= zf[1/Cos[-(3*Pi)/2]]
Out[3]= ComplexInfinity

It works fine when the denominator is literally 0, but it fails when there are functions/variables, such as when Cos[x]==0.

How would I go about evaluating the denominator separately, then if that equals 0, drop the denominator, and evaluate the numerator only without evaluating the entire fraction?

Basically my question is how do I make zf[1/Cos[-(3*Pi)/2]] output 1?

I have this function.

SetAttributes[zf,HoldAllComplete];
zf[x_] := 
  If[Denominator[Unevaluated[x]] == 0,
     Numerator[Unevaluated[x]],
     Numerator[Unevaluated[x]]];

It is supposed to just return the numerator anytime the denominator is 0.

zf[1/0]

1

Cos[-(3*Pi)/2]

0

zf[1/Cos[-(3*Pi)/2]]

ComplexInfinity

It works fine when the denominator is literally 0, but it fails when there are functions/variables, such as when Cos[x] == 0.

How would I go about evaluating the denominator separately, then if that equals zero, drop the denominator, and evaluate the numerator only without evaluating the entire fraction?

Basically my question is how do I make zf[1/Cos[-(3*Pi)/2]] output 1?

Source Link

Evaluate Numerator and Denominator Separately

I have this function.

SetAttributes[zf,HoldAllComplete];
zf[x_]:=If[Denominator[Unevaluated[x]]==0,Numerator[Unevaluated[x]],Numerator[Unevaluated[x]]];

It is supposed to just return the numerator anytime the denominator is 0.

In[1]:= zf[1/0]
Out[1]= 1
In[2]:= Cos[-(3*Pi)/2]
Out[2]= 0
In[3]:= zf[1/Cos[-(3*Pi)/2]]
Out[3]= ComplexInfinity

It works fine when the denominator is literally 0, but it fails when there are functions/variables, such as when Cos[x]==0.

How would I go about evaluating the denominator separately, then if that equals 0, drop the denominator, and evaluate the numerator only without evaluating the entire fraction?

Basically my question is how do I make zf[1/Cos[-(3*Pi)/2]] output 1?