
(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 (<= z -1.7e+34) (not (<= z 1.55e-56))) (+ (/ x z) (* (- 1.0 (/ x z)) y)) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e+34) || !(z <= 1.55e-56)) {
tmp = (x / z) + ((1.0 - (x / z)) * y);
} 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 ((z <= (-1.7d+34)) .or. (.not. (z <= 1.55d-56))) then
tmp = (x / z) + ((1.0d0 - (x / z)) * y)
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 ((z <= -1.7e+34) || !(z <= 1.55e-56)) {
tmp = (x / z) + ((1.0 - (x / z)) * y);
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e+34) or not (z <= 1.55e-56): tmp = (x / z) + ((1.0 - (x / z)) * y) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e+34) || !(z <= 1.55e-56)) tmp = Float64(Float64(x / z) + Float64(Float64(1.0 - Float64(x / z)) * y)); 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 ((z <= -1.7e+34) || ~((z <= 1.55e-56))) tmp = (x / z) + ((1.0 - (x / z)) * y); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e+34], N[Not[LessEqual[z, 1.55e-56]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] + N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+34} \lor \neg \left(z \leq 1.55 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{x}{z} + \left(1 - \frac{x}{z}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -1.7e34 or 1.54999999999999994e-56 < z Initial program 77.2%
Taylor expanded in y around 0 99.9%
if -1.7e34 < z < 1.54999999999999994e-56Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e+20) (not (<= y 0.0035))) (- y (/ y (/ z x))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e+20) || !(y <= 0.0035)) {
tmp = y - (y / (z / x));
} 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 <= (-2.65d+20)) .or. (.not. (y <= 0.0035d0))) then
tmp = y - (y / (z / x))
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 <= -2.65e+20) || !(y <= 0.0035)) {
tmp = y - (y / (z / x));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e+20) or not (y <= 0.0035): tmp = y - (y / (z / x)) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e+20) || !(y <= 0.0035)) tmp = Float64(y - Float64(y / Float64(z / x))); 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 <= -2.65e+20) || ~((y <= 0.0035))) tmp = y - (y / (z / x)); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e+20], N[Not[LessEqual[y, 0.0035]], $MachinePrecision]], N[(y - N[(y / N[(z / x), $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 -2.65 \cdot 10^{+20} \lor \neg \left(y \leq 0.0035\right):\\
\;\;\;\;y - \frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -2.65e20 or 0.00350000000000000007 < y Initial program 74.6%
Taylor expanded in y around 0 93.5%
Taylor expanded in y around inf 99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
distribute-rgt1-in99.9%
*-commutative99.9%
associate-*r/86.9%
distribute-rgt-neg-out86.9%
distribute-frac-neg86.9%
unsub-neg86.9%
associate-/l*99.9%
Simplified99.9%
if -2.65e20 < y < 0.00350000000000000007Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e+81) (not (<= x 3.8e+90))) (* (/ x z) (- 1.0 y)) (+ (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+81) || !(x <= 3.8e+90)) {
tmp = (x / z) * (1.0 - y);
} 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 ((x <= (-7d+81)) .or. (.not. (x <= 3.8d+90))) then
tmp = (x / z) * (1.0d0 - y)
else
tmp = (x / z) + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+81) || !(x <= 3.8e+90)) {
tmp = (x / z) * (1.0 - y);
} else {
tmp = (x / z) + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e+81) or not (x <= 3.8e+90): tmp = (x / z) * (1.0 - y) else: tmp = (x / z) + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e+81) || !(x <= 3.8e+90)) tmp = Float64(Float64(x / z) * Float64(1.0 - y)); else tmp = Float64(Float64(x / z) + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e+81) || ~((x <= 3.8e+90))) tmp = (x / z) * (1.0 - y); else tmp = (x / z) + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e+81], N[Not[LessEqual[x, 3.8e+90]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+81} \lor \neg \left(x \leq 3.8 \cdot 10^{+90}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} + y\\
\end{array}
\end{array}
if x < -7.0000000000000001e81 or 3.8000000000000001e90 < x Initial program 83.1%
Taylor expanded in x around inf 81.3%
*-commutative81.3%
associate-/l*86.8%
mul-1-neg86.8%
unsub-neg86.8%
Simplified86.8%
associate-/r/86.7%
Applied egg-rr86.7%
if -7.0000000000000001e81 < x < 3.8000000000000001e90Initial program 90.0%
Taylor expanded in y around 0 98.7%
Taylor expanded in x around 0 88.2%
Taylor expanded in y around 0 88.2%
+-commutative88.2%
Simplified88.2%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -11200.0) (not (<= y 0.0035))) (- y (/ y (/ z x))) (+ (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -11200.0) || !(y <= 0.0035)) {
tmp = y - (y / (z / 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 ((y <= (-11200.0d0)) .or. (.not. (y <= 0.0035d0))) then
tmp = y - (y / (z / 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 ((y <= -11200.0) || !(y <= 0.0035)) {
tmp = y - (y / (z / x));
} else {
tmp = (x / z) + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -11200.0) or not (y <= 0.0035): tmp = y - (y / (z / x)) else: tmp = (x / z) + y return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -11200.0) || !(y <= 0.0035)) tmp = Float64(y - Float64(y / Float64(z / x))); else tmp = Float64(Float64(x / z) + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -11200.0) || ~((y <= 0.0035))) tmp = y - (y / (z / x)); else tmp = (x / z) + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -11200.0], N[Not[LessEqual[y, 0.0035]], $MachinePrecision]], N[(y - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -11200 \lor \neg \left(y \leq 0.0035\right):\\
\;\;\;\;y - \frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} + y\\
\end{array}
\end{array}
if y < -11200 or 0.00350000000000000007 < y Initial program 75.2%
Taylor expanded in y around 0 93.6%
Taylor expanded in y around inf 99.8%
sub-neg99.8%
distribute-frac-neg99.8%
+-commutative99.8%
distribute-rgt1-in99.8%
*-commutative99.8%
associate-*r/87.1%
distribute-rgt-neg-out87.1%
distribute-frac-neg87.1%
unsub-neg87.1%
associate-/l*99.9%
Simplified99.9%
if -11200 < y < 0.00350000000000000007Initial program 99.9%
Taylor expanded in y around 0 92.9%
Taylor expanded in x around 0 99.1%
Taylor expanded in y around 0 99.1%
+-commutative99.1%
Simplified99.1%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= z -8.6e+72) y (if (<= z 6.5e-127) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.6e+72) {
tmp = y;
} else if (z <= 6.5e-127) {
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 (z <= (-8.6d+72)) then
tmp = y
else if (z <= 6.5d-127) 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 (z <= -8.6e+72) {
tmp = y;
} else if (z <= 6.5e-127) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.6e+72: tmp = y elif z <= 6.5e-127: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.6e+72) tmp = y; elseif (z <= 6.5e-127) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.6e+72) tmp = y; elseif (z <= 6.5e-127) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.6e+72], y, If[LessEqual[z, 6.5e-127], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+72}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-127}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -8.6000000000000003e72 or 6.49999999999999998e-127 < z Initial program 79.1%
Taylor expanded in x around 0 65.9%
if -8.6000000000000003e72 < z < 6.49999999999999998e-127Initial program 99.0%
Taylor expanded in y around 0 53.1%
Final simplification60.6%
(FPCore (x y z) :precision binary64 (+ (/ x z) y))
double code(double x, double y, double z) {
return (x / 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 / z) + y
end function
public static double code(double x, double y, double z) {
return (x / z) + y;
}
def code(x, y, z): return (x / z) + y
function code(x, y, z) return Float64(Float64(x / z) + y) end
function tmp = code(x, y, z) tmp = (x / z) + y; end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z} + y
\end{array}
Initial program 87.4%
Taylor expanded in y around 0 93.3%
Taylor expanded in x around 0 76.9%
Taylor expanded in y around 0 76.9%
+-commutative76.9%
Simplified76.9%
Final simplification76.9%
(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.4%
Taylor expanded in x around 0 44.2%
Final simplification44.2%
(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 2023224
(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))