
(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 8 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 -1e+34) (not (<= y 2e+15))) (* y (- 1.0 (/ x z))) (+ y (/ (* x (- 1.0 y)) z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+34) || !(y <= 2e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + ((x * (1.0 - 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 ((y <= (-1d+34)) .or. (.not. (y <= 2d+15))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = y + ((x * (1.0d0 - y)) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+34) || !(y <= 2e+15)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + ((x * (1.0 - y)) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e+34) or not (y <= 2e+15): tmp = y * (1.0 - (x / z)) else: tmp = y + ((x * (1.0 - y)) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e+34) || !(y <= 2e+15)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(y + Float64(Float64(x * Float64(1.0 - y)) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1e+34) || ~((y <= 2e+15))) tmp = y * (1.0 - (x / z)); else tmp = y + ((x * (1.0 - y)) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e+34], N[Not[LessEqual[y, 2e+15]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+34} \lor \neg \left(y \leq 2 \cdot 10^{+15}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x \cdot \left(1 - y\right)}{z}\\
\end{array}
\end{array}
if y < -9.99999999999999946e33 or 2e15 < y Initial program 76.7%
Taylor expanded in y around inf 76.7%
associate-/l*99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
if -9.99999999999999946e33 < y < 2e15Initial program 99.9%
Taylor expanded in x around inf 99.7%
associate-+r+99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in z around inf 100.0%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.9e-115) (not (<= z 2.2e-109))) (+ y (/ x z)) (* x (/ (- 1.0 y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e-115) || !(z <= 2.2e-109)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - 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 <= (-2.9d-115)) .or. (.not. (z <= 2.2d-109))) then
tmp = y + (x / z)
else
tmp = x * ((1.0d0 - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e-115) || !(z <= 2.2e-109)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.9e-115) or not (z <= 2.2e-109): tmp = y + (x / z) else: tmp = x * ((1.0 - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.9e-115) || !(z <= 2.2e-109)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(x * Float64(Float64(1.0 - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.9e-115) || ~((z <= 2.2e-109))) tmp = y + (x / z); else tmp = x * ((1.0 - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.9e-115], N[Not[LessEqual[z, 2.2e-109]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-115} \lor \neg \left(z \leq 2.2 \cdot 10^{-109}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\end{array}
\end{array}
if z < -2.8999999999999998e-115 or 2.1999999999999999e-109 < z Initial program 82.9%
Taylor expanded in x around inf 88.6%
associate-+r+88.6%
+-commutative88.6%
mul-1-neg88.6%
unsub-neg88.6%
div-sub88.6%
Simplified88.6%
Taylor expanded in z around inf 93.3%
Taylor expanded in y around 0 89.5%
if -2.8999999999999998e-115 < z < 2.1999999999999999e-109Initial program 99.9%
Taylor expanded in x around inf 92.4%
associate-/l*89.4%
mul-1-neg89.4%
unsub-neg89.4%
Simplified89.4%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -8600000000.0) (not (<= y 0.0016))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8600000000.0) || !(y <= 0.0016)) {
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 <= (-8600000000.0d0)) .or. (.not. (y <= 0.0016d0))) 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 <= -8600000000.0) || !(y <= 0.0016)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8600000000.0) or not (y <= 0.0016): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8600000000.0) || !(y <= 0.0016)) 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 <= -8600000000.0) || ~((y <= 0.0016))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8600000000.0], N[Not[LessEqual[y, 0.0016]], $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 -8600000000 \lor \neg \left(y \leq 0.0016\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -8.6e9 or 0.00160000000000000008 < y Initial program 77.8%
Taylor expanded in y around inf 77.3%
associate-/l*99.3%
div-sub99.4%
*-inverses99.4%
Simplified99.4%
if -8.6e9 < y < 0.00160000000000000008Initial program 99.9%
Taylor expanded in x around inf 99.7%
associate-+r+99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 99.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= x -1e+51) (* x (+ (/ (- 1.0 y) z) (/ y x))) (+ y (/ (* x (- 1.0 y)) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e+51) {
tmp = x * (((1.0 - y) / z) + (y / x));
} else {
tmp = y + ((x * (1.0 - 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 (x <= (-1d+51)) then
tmp = x * (((1.0d0 - y) / z) + (y / x))
else
tmp = y + ((x * (1.0d0 - y)) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1e+51) {
tmp = x * (((1.0 - y) / z) + (y / x));
} else {
tmp = y + ((x * (1.0 - y)) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e+51: tmp = x * (((1.0 - y) / z) + (y / x)) else: tmp = y + ((x * (1.0 - y)) / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e+51) tmp = Float64(x * Float64(Float64(Float64(1.0 - y) / z) + Float64(y / x))); else tmp = Float64(y + Float64(Float64(x * Float64(1.0 - y)) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1e+51) tmp = x * (((1.0 - y) / z) + (y / x)); else tmp = y + ((x * (1.0 - y)) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e+51], N[(x * N[(N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision] + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+51}:\\
\;\;\;\;x \cdot \left(\frac{1 - y}{z} + \frac{y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x \cdot \left(1 - y\right)}{z}\\
\end{array}
\end{array}
if x < -1e51Initial program 88.4%
Taylor expanded in x around inf 99.8%
associate-+r+99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
div-sub99.8%
Simplified99.8%
if -1e51 < x Initial program 89.6%
Taylor expanded in x around inf 86.1%
associate-+r+86.1%
+-commutative86.1%
mul-1-neg86.1%
unsub-neg86.1%
div-sub86.1%
Simplified86.1%
Taylor expanded in z around inf 98.0%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (<= y -6.4e-9) y (if (<= y 1.48e-27) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.4e-9) {
tmp = y;
} else if (y <= 1.48e-27) {
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 <= (-6.4d-9)) then
tmp = y
else if (y <= 1.48d-27) 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 <= -6.4e-9) {
tmp = y;
} else if (y <= 1.48e-27) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.4e-9: tmp = y elif y <= 1.48e-27: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.4e-9) tmp = y; elseif (y <= 1.48e-27) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.4e-9) tmp = y; elseif (y <= 1.48e-27) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.4e-9], y, If[LessEqual[y, 1.48e-27], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-9}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.48 \cdot 10^{-27}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -6.40000000000000023e-9 or 1.48000000000000008e-27 < y Initial program 79.8%
Taylor expanded in x around 0 50.8%
if -6.40000000000000023e-9 < y < 1.48000000000000008e-27Initial program 99.9%
Taylor expanded in y around 0 81.6%
Final simplification65.3%
(FPCore (x y z) :precision binary64 (if (<= y 0.0016) (+ y (/ x z)) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 0.0016) {
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 (y <= 0.0016d0) 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 (y <= 0.0016) {
tmp = y + (x / z);
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 0.0016: tmp = y + (x / z) else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 0.0016) tmp = Float64(y + 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 <= 0.0016) tmp = y + (x / z); else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 0.0016], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0016:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 0.00160000000000000008Initial program 94.3%
Taylor expanded in x around inf 91.1%
associate-+r+91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
div-sub91.1%
Simplified91.1%
Taylor expanded in z around inf 97.5%
Taylor expanded in y around 0 87.9%
if 0.00160000000000000008 < y Initial program 72.3%
Taylor expanded in x around inf 82.1%
associate-+r+82.1%
+-commutative82.1%
mul-1-neg82.1%
unsub-neg82.1%
div-sub82.1%
Simplified82.1%
Taylor expanded in z around inf 90.0%
Taylor expanded in y around 0 46.9%
add-sqr-sqrt23.0%
sqrt-unprod55.8%
sqr-neg55.8%
sqrt-unprod32.8%
add-sqr-sqrt68.5%
distribute-frac-neg268.5%
sub-neg68.5%
Applied egg-rr68.5%
Final simplification83.5%
(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 89.3%
Taylor expanded in x around inf 89.1%
associate-+r+89.1%
+-commutative89.1%
mul-1-neg89.1%
unsub-neg89.1%
div-sub89.1%
Simplified89.1%
Taylor expanded in z around inf 95.8%
Taylor expanded in y around 0 78.6%
Final simplification78.6%
(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 89.3%
Taylor expanded in x around 0 36.8%
Final simplification36.8%
(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 2024079
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:alt
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))