
(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 (- 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(x / Float64(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[(x / N[(z / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - \frac{x}{\frac{z}{y + -1}}
\end{array}
Initial program 88.6%
div-inv88.3%
+-commutative88.3%
fma-def88.3%
Applied egg-rr88.3%
Taylor expanded in x around -inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
associate-/l*96.9%
sub-neg96.9%
metadata-eval96.9%
Simplified96.9%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e+34) (not (<= x 8.5e+20))) (* (/ x z) (- 1.0 y)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e+34) || !(x <= 8.5e+20)) {
tmp = (x / z) * (1.0 - y);
} 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 ((x <= (-1.05d+34)) .or. (.not. (x <= 8.5d+20))) then
tmp = (x / z) * (1.0d0 - y)
else
tmp = y + (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e+34) || !(x <= 8.5e+20)) {
tmp = (x / z) * (1.0 - y);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e+34) or not (x <= 8.5e+20): tmp = (x / z) * (1.0 - y) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e+34) || !(x <= 8.5e+20)) tmp = Float64(Float64(x / z) * Float64(1.0 - y)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e+34) || ~((x <= 8.5e+20))) tmp = (x / z) * (1.0 - y); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e+34], N[Not[LessEqual[x, 8.5e+20]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+34} \lor \neg \left(x \leq 8.5 \cdot 10^{+20}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -1.05000000000000009e34 or 8.5e20 < x Initial program 90.2%
Taylor expanded in x around inf 87.3%
associate-*l/91.2%
mul-1-neg91.2%
unsub-neg91.2%
Simplified91.2%
if -1.05000000000000009e34 < x < 8.5e20Initial program 87.3%
div-inv87.0%
+-commutative87.0%
fma-def87.0%
Applied egg-rr87.0%
Taylor expanded in x around -inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
associate-/l*94.4%
sub-neg94.4%
metadata-eval94.4%
Simplified94.4%
Taylor expanded in y around 0 89.3%
neg-mul-189.3%
distribute-neg-frac89.3%
Simplified89.3%
Taylor expanded in y around 0 89.3%
+-commutative89.3%
Simplified89.3%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -260000.0) (not (<= y 1.0))) (* (/ y z) (- z x)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -260000.0) || !(y <= 1.0)) {
tmp = (y / z) * (z - x);
} 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 <= (-260000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = (y / z) * (z - x)
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 <= -260000.0) || !(y <= 1.0)) {
tmp = (y / z) * (z - x);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -260000.0) or not (y <= 1.0): tmp = (y / z) * (z - x) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -260000.0) || !(y <= 1.0)) tmp = Float64(Float64(y / z) * Float64(z - x)); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -260000.0) || ~((y <= 1.0))) tmp = (y / z) * (z - x); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -260000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(y / z), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -260000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{y}{z} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.6e5 or 1 < y Initial program 78.2%
Taylor expanded in y around inf 77.5%
associate-*l/92.8%
Simplified92.8%
if -2.6e5 < y < 1Initial program 99.9%
div-inv99.6%
+-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in x around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
associate-/l*100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification96.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-9) (not (<= y 1.35e-36))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-9) || !(y <= 1.35e-36)) {
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 <= (-5.8d-9)) .or. (.not. (y <= 1.35d-36))) 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 <= -5.8e-9) || !(y <= 1.35e-36)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-9) or not (y <= 1.35e-36): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-9) || !(y <= 1.35e-36)) 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 <= -5.8e-9) || ~((y <= 1.35e-36))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-9], N[Not[LessEqual[y, 1.35e-36]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-9} \lor \neg \left(y \leq 1.35 \cdot 10^{-36}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -5.79999999999999982e-9 or 1.35000000000000004e-36 < y Initial program 79.9%
Taylor expanded in y around inf 77.4%
Taylor expanded in z around inf 39.3%
associate-/l*55.0%
associate-/r/57.5%
Applied egg-rr57.5%
if -5.79999999999999982e-9 < y < 1.35000000000000004e-36Initial program 99.9%
Taylor expanded in y around 0 82.1%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.8e-9) y (if (<= y 1.25e-37) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.8e-9) {
tmp = y;
} else if (y <= 1.25e-37) {
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 <= (-5.8d-9)) then
tmp = y
else if (y <= 1.25d-37) 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 <= -5.8e-9) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.8e-9: tmp = y elif y <= 1.25e-37: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.8e-9) tmp = y; elseif (y <= 1.25e-37) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.8e-9) tmp = y; elseif (y <= 1.25e-37) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.8e-9], y, If[LessEqual[y, 1.25e-37], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-9}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.79999999999999982e-9 or 1.2499999999999999e-37 < y Initial program 80.0%
Taylor expanded in x around 0 55.2%
if -5.79999999999999982e-9 < y < 1.2499999999999999e-37Initial program 99.9%
Taylor expanded in y around 0 82.7%
Final simplification67.0%
(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 88.6%
div-inv88.3%
+-commutative88.3%
fma-def88.3%
Applied egg-rr88.3%
Taylor expanded in x around -inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
associate-/l*96.9%
sub-neg96.9%
metadata-eval96.9%
Simplified96.9%
Taylor expanded in y around 0 77.5%
neg-mul-177.5%
distribute-neg-frac77.5%
Simplified77.5%
Taylor expanded in y around 0 77.5%
+-commutative77.5%
Simplified77.5%
Final simplification77.5%
(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 88.6%
Taylor expanded in x around 0 39.4%
Final simplification39.4%
(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 2024040
(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))