
(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 10 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 (- y (* (/ x z) (+ y -1.0))))
double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
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 + (-1.0d0)))
end function
public static double code(double x, double y, double z) {
return y - ((x / z) * (y + -1.0));
}
def code(x, y, z): return y - ((x / z) * (y + -1.0))
function code(x, y, z) return Float64(y - Float64(Float64(x / z) * Float64(y + -1.0))) end
function tmp = code(x, y, z) tmp = y - ((x / z) * (y + -1.0)); end
code[x_, y_, z_] := N[(y - N[(N[(x / z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - \frac{x}{z} \cdot \left(y + -1\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= y 1.8e+17)
(+ y (/ x z))
(if (<= y 6.8e+190)
(* y (/ (- x) z))
(if (<= y 2.9e+220) y (* x (/ (- y) z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.8e+17) {
tmp = y + (x / z);
} else if (y <= 6.8e+190) {
tmp = y * (-x / z);
} else if (y <= 2.9e+220) {
tmp = y;
} else {
tmp = 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 (y <= 1.8d+17) then
tmp = y + (x / z)
else if (y <= 6.8d+190) then
tmp = y * (-x / z)
else if (y <= 2.9d+220) then
tmp = y
else
tmp = x * (-y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.8e+17) {
tmp = y + (x / z);
} else if (y <= 6.8e+190) {
tmp = y * (-x / z);
} else if (y <= 2.9e+220) {
tmp = y;
} else {
tmp = x * (-y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.8e+17: tmp = y + (x / z) elif y <= 6.8e+190: tmp = y * (-x / z) elif y <= 2.9e+220: tmp = y else: tmp = x * (-y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.8e+17) tmp = Float64(y + Float64(x / z)); elseif (y <= 6.8e+190) tmp = Float64(y * Float64(Float64(-x) / z)); elseif (y <= 2.9e+220) tmp = y; else tmp = Float64(x * Float64(Float64(-y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.8e+17) tmp = y + (x / z); elseif (y <= 6.8e+190) tmp = y * (-x / z); elseif (y <= 2.9e+220) tmp = y; else tmp = x * (-y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.8e+17], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.8e+190], N[(y * N[((-x) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.9e+220], y, N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.8 \cdot 10^{+17}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+190}:\\
\;\;\;\;y \cdot \frac{-x}{z}\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+220}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= y 2.1e+15)
(+ y (/ x z))
(if (<= y 3.5e+190)
(/ y (/ (- z) x))
(if (<= y 7e+221) y (* x (/ (- y) z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.1e+15) {
tmp = y + (x / z);
} else if (y <= 3.5e+190) {
tmp = y / (-z / x);
} else if (y <= 7e+221) {
tmp = y;
} else {
tmp = 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 (y <= 2.1d+15) then
tmp = y + (x / z)
else if (y <= 3.5d+190) then
tmp = y / (-z / x)
else if (y <= 7d+221) then
tmp = y
else
tmp = x * (-y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.1e+15) {
tmp = y + (x / z);
} else if (y <= 3.5e+190) {
tmp = y / (-z / x);
} else if (y <= 7e+221) {
tmp = y;
} else {
tmp = x * (-y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.1e+15: tmp = y + (x / z) elif y <= 3.5e+190: tmp = y / (-z / x) elif y <= 7e+221: tmp = y else: tmp = x * (-y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.1e+15) tmp = Float64(y + Float64(x / z)); elseif (y <= 3.5e+190) tmp = Float64(y / Float64(Float64(-z) / x)); elseif (y <= 7e+221) tmp = y; else tmp = Float64(x * Float64(Float64(-y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.1e+15) tmp = y + (x / z); elseif (y <= 3.5e+190) tmp = y / (-z / x); elseif (y <= 7e+221) tmp = y; else tmp = x * (-y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.1e+15], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.5e+190], N[(y / N[((-z) / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7e+221], y, N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{+15}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+190}:\\
\;\;\;\;\frac{y}{\frac{-z}{x}}\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+221}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -13000000.0) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -13000000.0) || !(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 <= (-13000000.0d0)) .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 <= -13000000.0) || !(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 <= -13000000.0) 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 <= -13000000.0) || !(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 <= -13000000.0) || ~((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, -13000000.0], 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 -13000000 \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}
(FPCore (x y z) :precision binary64 (if (or (<= y -13000000.0) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (/ (+ x (* y z)) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -13000000.0) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * z)) / 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 <= (-13000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (1.0d0 - (x / z))
else
tmp = (x + (y * z)) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -13000000.0) || !(y <= 1.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * z)) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -13000000.0) or not (y <= 1.0): tmp = y * (1.0 - (x / z)) else: tmp = (x + (y * z)) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -13000000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(1.0 - Float64(x / z))); else tmp = Float64(Float64(x + Float64(y * z)) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -13000000.0) || ~((y <= 1.0))) tmp = y * (1.0 - (x / z)); else tmp = (x + (y * z)) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -13000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -13000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot z}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1.32e-33) (not (<= y 0.03))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.32e-33) || !(y <= 0.03)) {
tmp = z * (y / z);
} else {
tmp = 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.32d-33)) .or. (.not. (y <= 0.03d0))) then
tmp = z * (y / z)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.32e-33) || !(y <= 0.03)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.32e-33) or not (y <= 0.03): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.32e-33) || !(y <= 0.03)) tmp = Float64(z * Float64(y / z)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.32e-33) || ~((y <= 0.03))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.32e-33], N[Not[LessEqual[y, 0.03]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.32 \cdot 10^{-33} \lor \neg \left(y \leq 0.03\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y 1.7e+219) (+ y (/ x z)) (* x (/ (- y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.7e+219) {
tmp = y + (x / z);
} else {
tmp = 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 (y <= 1.7d+219) then
tmp = y + (x / z)
else
tmp = x * (-y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.7e+219) {
tmp = y + (x / z);
} else {
tmp = x * (-y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.7e+219: tmp = y + (x / z) else: tmp = x * (-y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.7e+219) tmp = Float64(y + Float64(x / z)); else tmp = Float64(x * Float64(Float64(-y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.7e+219) tmp = y + (x / z); else tmp = x * (-y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.7e+219], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{+219}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -1.1e-33) y (if (<= y 2.55e-48) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e-33) {
tmp = y;
} else if (y <= 2.55e-48) {
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 <= (-1.1d-33)) then
tmp = y
else if (y <= 2.55d-48) 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 <= -1.1e-33) {
tmp = y;
} else if (y <= 2.55e-48) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e-33: tmp = y elif y <= 2.55e-48: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e-33) tmp = y; elseif (y <= 2.55e-48) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e-33) tmp = y; elseif (y <= 2.55e-48) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e-33], y, If[LessEqual[y, 2.55e-48], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-33}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-48}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y 7700.0) (+ y (/ x z)) (* z (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 7700.0) {
tmp = y + (x / z);
} else {
tmp = z * (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 <= 7700.0d0) then
tmp = y + (x / z)
else
tmp = z * (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 7700.0) {
tmp = y + (x / z);
} else {
tmp = z * (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 7700.0: tmp = y + (x / z) else: tmp = z * (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 7700.0) tmp = Float64(y + Float64(x / z)); else tmp = Float64(z * Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 7700.0) tmp = y + (x / z); else tmp = z * (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 7700.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7700:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\end{array}
\end{array}
(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}
(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 2023347
(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))