
(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 (/ x (/ y (- y z))))
double code(double x, double y, double z) {
return x / (y / (y - z));
}
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 / (y - z))
end function
public static double code(double x, double y, double z) {
return x / (y / (y - z));
}
def code(x, y, z): return x / (y / (y - z))
function code(x, y, z) return Float64(x / Float64(y / Float64(y - z))) end
function tmp = code(x, y, z) tmp = x / (y / (y - z)); end
code[x_, y_, z_] := N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{y - z}}
\end{array}
Initial program 85.1%
associate-/l*98.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.000135) (not (<= z 1.25e-23))) (* x (/ (- z) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000135) || !(z <= 1.25e-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 ((z <= (-0.000135d0)) .or. (.not. (z <= 1.25d-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 ((z <= -0.000135) || !(z <= 1.25e-23)) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.000135) or not (z <= 1.25e-23): tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.000135) || !(z <= 1.25e-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 ((z <= -0.000135) || ~((z <= 1.25e-23))) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.000135], N[Not[LessEqual[z, 1.25e-23]], $MachinePrecision]], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000135 \lor \neg \left(z \leq 1.25 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35000000000000002e-4 or 1.2500000000000001e-23 < z Initial program 86.7%
*-commutative86.7%
associate-*l/94.9%
*-commutative94.9%
Simplified94.9%
Taylor expanded in y around 0 67.9%
neg-mul-167.9%
distribute-neg-frac67.9%
Simplified67.9%
if -1.35000000000000002e-4 < z < 1.2500000000000001e-23Initial program 83.3%
*-commutative83.3%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 82.0%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.000135) (not (<= z 1.28e-23))) (* z (/ (- x) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000135) || !(z <= 1.28e-23)) {
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 ((z <= (-0.000135d0)) .or. (.not. (z <= 1.28d-23))) 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 ((z <= -0.000135) || !(z <= 1.28e-23)) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.000135) or not (z <= 1.28e-23): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.000135) || !(z <= 1.28e-23)) 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 ((z <= -0.000135) || ~((z <= 1.28e-23))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.000135], N[Not[LessEqual[z, 1.28e-23]], $MachinePrecision]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000135 \lor \neg \left(z \leq 1.28 \cdot 10^{-23}\right):\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35000000000000002e-4 or 1.28000000000000005e-23 < z Initial program 86.7%
*-commutative86.7%
associate-*l/94.9%
*-commutative94.9%
Simplified94.9%
Taylor expanded in y around 0 68.9%
associate-*r/68.9%
mul-1-neg68.9%
distribute-rgt-neg-out68.9%
associate-*l/69.5%
Simplified69.5%
if -1.35000000000000002e-4 < z < 1.28000000000000005e-23Initial program 83.3%
*-commutative83.3%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 82.0%
Final simplification75.4%
(FPCore (x y z) :precision binary64 (if (<= z -5.9e-5) (/ x (/ (- y) z)) (if (<= z 7.2e-24) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.9e-5) {
tmp = x / (-y / z);
} else if (z <= 7.2e-24) {
tmp = x;
} else {
tmp = 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 <= (-5.9d-5)) then
tmp = x / (-y / z)
else if (z <= 7.2d-24) then
tmp = x
else
tmp = z * (-x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.9e-5) {
tmp = x / (-y / z);
} else if (z <= 7.2e-24) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.9e-5: tmp = x / (-y / z) elif z <= 7.2e-24: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.9e-5) tmp = Float64(x / Float64(Float64(-y) / z)); elseif (z <= 7.2e-24) tmp = x; else tmp = Float64(z * Float64(Float64(-x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.9e-5) tmp = x / (-y / z); elseif (z <= 7.2e-24) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.9e-5], N[(x / N[((-y) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 7.2e-24], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{\frac{-y}{z}}\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -5.8999999999999998e-5Initial program 83.0%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in y around 0 71.1%
associate-*r/71.1%
neg-mul-171.1%
Simplified71.1%
if -5.8999999999999998e-5 < z < 7.2000000000000002e-24Initial program 83.3%
*-commutative83.3%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 82.0%
if 7.2000000000000002e-24 < z Initial program 90.3%
*-commutative90.3%
associate-*l/91.6%
*-commutative91.6%
Simplified91.6%
Taylor expanded in y around 0 71.7%
associate-*r/71.7%
mul-1-neg71.7%
distribute-rgt-neg-out71.7%
associate-*l/69.0%
Simplified69.0%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (<= z -6.2e-5) (/ x (/ (- y) z)) (if (<= z 1.8e-24) x (/ (* x (- z)) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.2e-5) {
tmp = x / (-y / z);
} else if (z <= 1.8e-24) {
tmp = x;
} else {
tmp = (x * -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 <= (-6.2d-5)) then
tmp = x / (-y / z)
else if (z <= 1.8d-24) then
tmp = x
else
tmp = (x * -z) / y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.2e-5) {
tmp = x / (-y / z);
} else if (z <= 1.8e-24) {
tmp = x;
} else {
tmp = (x * -z) / y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.2e-5: tmp = x / (-y / z) elif z <= 1.8e-24: tmp = x else: tmp = (x * -z) / y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.2e-5) tmp = Float64(x / Float64(Float64(-y) / z)); elseif (z <= 1.8e-24) tmp = x; else tmp = Float64(Float64(x * Float64(-z)) / y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.2e-5) tmp = x / (-y / z); elseif (z <= 1.8e-24) tmp = x; else tmp = (x * -z) / y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.2e-5], N[(x / N[((-y) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.8e-24], x, N[(N[(x * (-z)), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{\frac{-y}{z}}\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\
\end{array}
\end{array}
if z < -6.20000000000000027e-5Initial program 83.0%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in y around 0 71.1%
associate-*r/71.1%
neg-mul-171.1%
Simplified71.1%
if -6.20000000000000027e-5 < z < 1.8e-24Initial program 83.3%
*-commutative83.3%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 82.0%
if 1.8e-24 < z Initial program 90.3%
Taylor expanded in y around 0 71.7%
mul-1-neg71.7%
distribute-rgt-neg-out71.7%
Simplified71.7%
Final simplification76.4%
(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 85.1%
*-commutative85.1%
associate-*l/97.3%
*-commutative97.3%
Simplified97.3%
Final simplification97.3%
(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 85.1%
*-commutative85.1%
associate-*l/97.3%
*-commutative97.3%
Simplified97.3%
Taylor expanded in y around inf 53.0%
Final simplification53.0%
(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 2024034
(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))