
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / 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 * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / 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 * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -9.8e+39) (not (<= y 1.12e+15))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.8e+39) || !(y <= 1.12e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / 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 ((y <= (-9.8d+39)) .or. (.not. (y <= 1.12d+15))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = (x + (y * (z - x))) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.8e+39) || !(y <= 1.12e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.8e+39) or not (y <= 1.12e+15): tmp = y * (1.0 - (x / z)) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.8e+39) || !(y <= 1.12e+15)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.8e+39) || ~((y <= 1.12e+15))) tmp = y * (1.0 - (x / z)); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.8e+39], N[Not[LessEqual[y, 1.12e+15]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{+39} \lor \neg \left(y \leq 1.12 \cdot 10^{+15}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -9.79999999999999974e39 or 1.12e15 < y Initial program 73.1%
Taylor expanded in y around inf 73.1%
associate-/l*100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
if -9.79999999999999974e39 < y < 1.12e15Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e+26) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e+26) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / 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 ((y <= (-1.35d+26)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e+26) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e+26) or not (y <= 1.0): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e+26) || !(y <= 1.0)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e+26) || ~((y <= 1.0))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e+26], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{+26} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.35e26 or 1 < y Initial program 74.2%
Taylor expanded in y around inf 73.7%
associate-/l*99.4%
div-sub99.4%
*-inverses99.4%
Simplified99.4%
if -1.35e26 < y < 1Initial program 99.9%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around 0 98.5%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e-119) (not (<= z 6.5e-200))) (+ y (/ x z)) (* y (/ x (- z)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-119) || !(z <= 6.5e-200)) {
tmp = y + (x / z);
} else {
tmp = y * (x / -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 <= (-3.1d-119)) .or. (.not. (z <= 6.5d-200))) then
tmp = y + (x / z)
else
tmp = y * (x / -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-119) || !(z <= 6.5e-200)) {
tmp = y + (x / z);
} else {
tmp = y * (x / -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e-119) or not (z <= 6.5e-200): tmp = y + (x / z) else: tmp = y * (x / -z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e-119) || !(z <= 6.5e-200)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(x / Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e-119) || ~((z <= 6.5e-200))) tmp = y + (x / z); else tmp = y * (x / -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e-119], N[Not[LessEqual[z, 6.5e-200]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-119} \lor \neg \left(z \leq 6.5 \cdot 10^{-200}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{-z}\\
\end{array}
\end{array}
if z < -3.09999999999999978e-119 or 6.5000000000000002e-200 < z Initial program 84.7%
Taylor expanded in x around 0 97.0%
Taylor expanded in y around 0 86.6%
if -3.09999999999999978e-119 < z < 6.5000000000000002e-200Initial program 99.9%
Taylor expanded in x around inf 97.6%
mul-1-neg97.6%
unsub-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 63.2%
mul-1-neg63.2%
distribute-rgt-neg-out63.2%
Simplified63.2%
frac-2neg63.2%
distribute-frac-neg263.2%
distribute-rgt-neg-out63.2%
remove-double-neg63.2%
*-commutative63.2%
associate-*r/71.8%
Applied egg-rr71.8%
Final simplification83.5%
(FPCore (x y z) :precision binary64 (if (<= y -1e+52) (* y (- 1.0 (/ x z))) (+ y (* x (/ 1.0 (/ z (- 1.0 y)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e+52) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x * (1.0 / (z / (1.0 - 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 (y <= (-1d+52)) then
tmp = y * (1.0d0 - (x / z))
else
tmp = y + (x * (1.0d0 / (z / (1.0d0 - y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1e+52) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x * (1.0 / (z / (1.0 - y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e+52: tmp = y * (1.0 - (x / z)) else: tmp = y + (x * (1.0 / (z / (1.0 - y)))) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e+52) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(y + Float64(x * Float64(1.0 / Float64(z / Float64(1.0 - y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1e+52) tmp = y * (1.0 - (x / z)); else tmp = y + (x * (1.0 / (z / (1.0 - y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e+52], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * N[(1.0 / N[(z / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+52}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot \frac{1}{\frac{z}{1 - y}}\\
\end{array}
\end{array}
if y < -9.9999999999999999e51Initial program 71.0%
Taylor expanded in y around inf 71.0%
associate-/l*100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
if -9.9999999999999999e51 < y Initial program 92.2%
Taylor expanded in x around 0 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
div-sub98.3%
clear-num98.4%
Applied egg-rr98.4%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -20000000000.0) y (if (<= y 9.6e-35) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -20000000000.0) {
tmp = y;
} else if (y <= 9.6e-35) {
tmp = x / z;
} else {
tmp = 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 (y <= (-20000000000.0d0)) then
tmp = y
else if (y <= 9.6d-35) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -20000000000.0) {
tmp = y;
} else if (y <= 9.6e-35) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -20000000000.0: tmp = y elif y <= 9.6e-35: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -20000000000.0) tmp = y; elseif (y <= 9.6e-35) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -20000000000.0) tmp = y; elseif (y <= 9.6e-35) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -20000000000.0], y, If[LessEqual[y, 9.6e-35], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -20000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-35}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2e10 or 9.6000000000000005e-35 < y Initial program 76.5%
Taylor expanded in x around 0 53.2%
if -2e10 < y < 9.6000000000000005e-35Initial program 99.9%
Taylor expanded in y around 0 69.0%
Final simplification60.8%
(FPCore (x y z) :precision binary64 (+ y (/ x z)))
double code(double x, double y, double z) {
return y + (x / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + (x / z)
end function
public static double code(double x, double y, double z) {
return y + (x / z);
}
def code(x, y, z): return y + (x / z)
function code(x, y, z) return Float64(y + Float64(x / z)) end
function tmp = code(x, y, z) tmp = y + (x / z); end
code[x_, y_, z_] := N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \frac{x}{z}
\end{array}
Initial program 87.9%
Taylor expanded in x around 0 95.4%
Taylor expanded in y around 0 79.3%
Final simplification79.3%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 87.9%
Taylor expanded in x around 0 42.3%
Final simplification42.3%
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z): return (y + (x / z)) - (y / (z / x))
function code(x, y, z) return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (y + (x / z)) - (y / (z / x)); end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}
herbie shell --seed 2024039
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:herbie-target
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))