
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+130) (/ (* x (- y z)) y) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+130) {
tmp = (x * (y - z)) / y;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.4d+130)) then
tmp = (x * (y - z)) / y
else
tmp = x - (x / (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+130) {
tmp = (x * (y - z)) / y;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+130: tmp = (x * (y - z)) / y else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+130) tmp = Float64(Float64(x * Float64(y - z)) / y); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+130) tmp = (x * (y - z)) / y; else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+130], N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+130}:\\
\;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -1.3999999999999999e130Initial program 97.0%
if -1.3999999999999999e130 < z Initial program 87.2%
--rgt-identity87.2%
associate-*l/83.3%
sub-neg83.3%
distribute-rgt-in76.3%
*-commutative76.3%
distribute-lft-neg-out76.3%
unsub-neg76.3%
associate--r+76.3%
associate-*l/83.0%
associate-/l*94.0%
*-inverses94.0%
/-rgt-identity94.0%
+-rgt-identity94.0%
*-commutative94.0%
associate-/r/97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (x y z) :precision binary64 (if (<= y -27000000000000.0) x (if (<= y 7e+23) (* x (/ (- z) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -27000000000000.0) {
tmp = x;
} else if (y <= 7e+23) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-27000000000000.0d0)) then
tmp = x
else if (y <= 7d+23) then
tmp = x * (-z / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -27000000000000.0) {
tmp = x;
} else if (y <= 7e+23) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -27000000000000.0: tmp = x elif y <= 7e+23: tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -27000000000000.0) tmp = x; elseif (y <= 7e+23) tmp = Float64(x * Float64(Float64(-z) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -27000000000000.0) tmp = x; elseif (y <= 7e+23) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -27000000000000.0], x, If[LessEqual[y, 7e+23], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -27000000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+23}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.7e13 or 7.0000000000000004e23 < y Initial program 81.1%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around inf 85.8%
if -2.7e13 < y < 7.0000000000000004e23Initial program 94.4%
associate-*r/91.3%
Simplified91.3%
Taylor expanded in y around 0 65.9%
neg-mul-165.9%
distribute-neg-frac65.9%
Simplified65.9%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= y -13600000000.0) x (if (<= y 1.7e+24) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -13600000000.0) {
tmp = x;
} else if (y <= 1.7e+24) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-13600000000.0d0)) then
tmp = x
else if (y <= 1.7d+24) then
tmp = z * (-x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -13600000000.0) {
tmp = x;
} else if (y <= 1.7e+24) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -13600000000.0: tmp = x elif y <= 1.7e+24: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -13600000000.0) tmp = x; elseif (y <= 1.7e+24) tmp = Float64(z * Float64(Float64(-x) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -13600000000.0) tmp = x; elseif (y <= 1.7e+24) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -13600000000.0], x, If[LessEqual[y, 1.7e+24], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -13600000000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+24}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.36e10 or 1.7e24 < y Initial program 81.1%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around inf 85.8%
if -1.36e10 < y < 1.7e24Initial program 94.4%
associate-*r/91.3%
Simplified91.3%
Taylor expanded in y around 0 71.7%
mul-1-neg71.7%
associate-*l/72.4%
distribute-lft-neg-in72.4%
*-commutative72.4%
distribute-neg-frac72.4%
Simplified72.4%
Final simplification78.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e+180) (* (- y z) (/ x y)) (* x (/ (- y z) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+180) {
tmp = (y - z) * (x / y);
} else {
tmp = x * ((y - z) / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.05d+180)) then
tmp = (y - z) * (x / y)
else
tmp = x * ((y - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+180) {
tmp = (y - z) * (x / y);
} else {
tmp = x * ((y - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e+180: tmp = (y - z) * (x / y) else: tmp = x * ((y - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e+180) tmp = Float64(Float64(y - z) * Float64(x / y)); else tmp = Float64(x * Float64(Float64(y - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.05e+180) tmp = (y - z) * (x / y); else tmp = x * ((y - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e+180], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+180}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y - z}{y}\\
\end{array}
\end{array}
if z < -1.05e180Initial program 96.0%
*-commutative96.0%
associate-*r/95.5%
Simplified95.5%
if -1.05e180 < z Initial program 87.7%
associate-*r/97.1%
Simplified97.1%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.5e+181) (* (- y z) (/ x y)) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+181) {
tmp = (y - z) * (x / y);
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.5d+181)) then
tmp = (y - z) * (x / y)
else
tmp = x - (x / (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+181) {
tmp = (y - z) * (x / y);
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5e+181: tmp = (y - z) * (x / y) else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5e+181) tmp = Float64(Float64(y - z) * Float64(x / y)); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.5e+181) tmp = (y - z) * (x / y); else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5e+181], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+181}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -1.50000000000000006e181Initial program 96.0%
*-commutative96.0%
associate-*r/95.5%
Simplified95.5%
if -1.50000000000000006e181 < z Initial program 87.7%
--rgt-identity87.7%
associate-*l/82.7%
sub-neg82.7%
distribute-rgt-in76.0%
*-commutative76.0%
distribute-lft-neg-out76.0%
unsub-neg76.0%
associate--r+76.0%
associate-*l/83.3%
associate-/l*93.8%
*-inverses93.8%
/-rgt-identity93.8%
+-rgt-identity93.8%
*-commutative93.8%
associate-/r/97.1%
Simplified97.1%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (* x (/ (- y z) y)))
double code(double x, double y, double z) {
return x * ((y - z) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * ((y - z) / y)
end function
public static double code(double x, double y, double z) {
return x * ((y - z) / y);
}
def code(x, y, z): return x * ((y - z) / y)
function code(x, y, z) return Float64(x * Float64(Float64(y - z) / y)) end
function tmp = code(x, y, z) tmp = x * ((y - z) / y); end
code[x_, y_, z_] := N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y - z}{y}
\end{array}
Initial program 88.4%
associate-*r/95.2%
Simplified95.2%
Final simplification95.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 88.4%
associate-*r/95.2%
Simplified95.2%
Taylor expanded in y around inf 53.8%
Final simplification53.8%
(FPCore (x y z) :precision binary64 (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z < (-2.060202331921739d+104)) then
tmp = x - ((z * x) / y)
else if (z < 1.6939766013828526d+213) then
tmp = x / (y / (y - z))
else
tmp = (y - z) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z < -2.060202331921739e+104: tmp = x - ((z * x) / y) elif z < 1.6939766013828526e+213: tmp = x / (y / (y - z)) else: tmp = (y - z) * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z < -2.060202331921739e+104) tmp = Float64(x - Float64(Float64(z * x) / y)); elseif (z < 1.6939766013828526e+213) tmp = Float64(x / Float64(y / Float64(y - z))); else tmp = Float64(Float64(y - z) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z < -2.060202331921739e+104) tmp = x - ((z * x) / y); elseif (z < 1.6939766013828526e+213) tmp = x / (y / (y - z)); else tmp = (y - z) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[z, -2.060202331921739e+104], N[(x - N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[Less[z, 1.6939766013828526e+213], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\
\;\;\;\;x - \frac{z \cdot x}{y}\\
\mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\end{array}
\end{array}
herbie shell --seed 2023275
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))