
(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 (- 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}
Initial program 87.9%
Taylor expanded in x around -inf 97.0%
mul-1-neg97.0%
unsub-neg97.0%
associate-/l*97.4%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ z (/ z y))) (t_1 (/ y (/ (- z) x))))
(if (<= y -2.05e+192)
t_0
(if (<= y -7e+112)
t_1
(if (<= y 6.1e+50) (+ y (/ x z)) (if (<= y 2e+99) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z / (z / y);
double t_1 = y / (-z / x);
double tmp;
if (y <= -2.05e+192) {
tmp = t_0;
} else if (y <= -7e+112) {
tmp = t_1;
} else if (y <= 6.1e+50) {
tmp = y + (x / z);
} else if (y <= 2e+99) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = z / (z / y)
t_1 = y / (-z / x)
if (y <= (-2.05d+192)) then
tmp = t_0
else if (y <= (-7d+112)) then
tmp = t_1
else if (y <= 6.1d+50) then
tmp = y + (x / z)
else if (y <= 2d+99) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z / (z / y);
double t_1 = y / (-z / x);
double tmp;
if (y <= -2.05e+192) {
tmp = t_0;
} else if (y <= -7e+112) {
tmp = t_1;
} else if (y <= 6.1e+50) {
tmp = y + (x / z);
} else if (y <= 2e+99) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z / (z / y) t_1 = y / (-z / x) tmp = 0 if y <= -2.05e+192: tmp = t_0 elif y <= -7e+112: tmp = t_1 elif y <= 6.1e+50: tmp = y + (x / z) elif y <= 2e+99: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z / Float64(z / y)) t_1 = Float64(y / Float64(Float64(-z) / x)) tmp = 0.0 if (y <= -2.05e+192) tmp = t_0; elseif (y <= -7e+112) tmp = t_1; elseif (y <= 6.1e+50) tmp = Float64(y + Float64(x / z)); elseif (y <= 2e+99) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z / (z / y); t_1 = y / (-z / x); tmp = 0.0; if (y <= -2.05e+192) tmp = t_0; elseif (y <= -7e+112) tmp = t_1; elseif (y <= 6.1e+50) tmp = y + (x / z); elseif (y <= 2e+99) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z / N[(z / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[((-z) / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.05e+192], t$95$0, If[LessEqual[y, -7e+112], t$95$1, If[LessEqual[y, 6.1e+50], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e+99], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{z}{\frac{z}{y}}\\
t_1 := \frac{y}{\frac{-z}{x}}\\
\mathbf{if}\;y \leq -2.05 \cdot 10^{+192}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -7 \cdot 10^{+112}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 6.1 \cdot 10^{+50}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+99}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.05000000000000001e192 or 1.9999999999999999e99 < y Initial program 66.0%
Taylor expanded in x around 0 24.2%
associate-/l*56.6%
associate-/r/64.4%
Applied egg-rr64.4%
*-commutative64.4%
clear-num64.3%
un-div-inv65.6%
Applied egg-rr65.6%
if -2.05000000000000001e192 < y < -6.99999999999999994e112 or 6.10000000000000026e50 < y < 1.9999999999999999e99Initial program 84.1%
Taylor expanded in y around inf 84.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 78.4%
associate-*r/78.4%
neg-mul-178.4%
Simplified78.4%
if -6.99999999999999994e112 < y < 6.10000000000000026e50Initial program 95.9%
Taylor expanded in x around -inf 98.8%
mul-1-neg98.8%
unsub-neg98.8%
associate-/l*100.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 94.9%
mul-1-neg94.9%
distribute-frac-neg94.9%
Simplified94.9%
Taylor expanded in y around 0 94.9%
+-commutative94.9%
Simplified94.9%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -410000.0) (not (<= y 1.0))) (- y (/ x (/ z y))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -410000.0) || !(y <= 1.0)) {
tmp = y - (x / (z / 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 ((y <= (-410000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y - (x / (z / 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 ((y <= -410000.0) || !(y <= 1.0)) {
tmp = y - (x / (z / y));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -410000.0) or not (y <= 1.0): tmp = y - (x / (z / y)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -410000.0) || !(y <= 1.0)) tmp = Float64(y - Float64(x / Float64(z / y))); else tmp = Float64(y + Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -410000.0) || ~((y <= 1.0))) tmp = y - (x / (z / y)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -410000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y - N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -410000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y - \frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.1e5 or 1 < y Initial program 73.9%
Taylor expanded in x around -inf 93.5%
mul-1-neg93.5%
unsub-neg93.5%
associate-/l*94.3%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 93.1%
associate-/l*94.0%
Simplified94.0%
if -4.1e5 < y < 1Initial program 99.9%
Taylor expanded in x around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
associate-/l*100.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
mul-1-neg99.4%
distribute-frac-neg99.4%
Simplified99.4%
Taylor expanded in y around 0 99.4%
+-commutative99.4%
Simplified99.4%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -410000.0) (not (<= y 1.0))) (/ y (/ z (- z x))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -410000.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 <= (-410000.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 <= -410000.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 <= -410000.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 <= -410000.0) || !(y <= 1.0)) tmp = Float64(y / Float64(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 <= -410000.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, -410000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -410000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.1e5 or 1 < y Initial program 73.9%
Taylor expanded in y around inf 73.5%
associate-/l*99.6%
Simplified99.6%
if -4.1e5 < y < 1Initial program 99.9%
Taylor expanded in x around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
associate-/l*100.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
mul-1-neg99.4%
distribute-frac-neg99.4%
Simplified99.4%
Taylor expanded in y around 0 99.4%
+-commutative99.4%
Simplified99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.6e-11) (not (<= y 1.12e-51))) (* z (/ y z)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e-11) || !(y <= 1.12e-51)) {
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 <= (-6.6d-11)) .or. (.not. (y <= 1.12d-51))) 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 <= -6.6e-11) || !(y <= 1.12e-51)) {
tmp = z * (y / z);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.6e-11) or not (y <= 1.12e-51): tmp = z * (y / z) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.6e-11) || !(y <= 1.12e-51)) 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 <= -6.6e-11) || ~((y <= 1.12e-51))) tmp = z * (y / z); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.6e-11], N[Not[LessEqual[y, 1.12e-51]], $MachinePrecision]], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{-11} \lor \neg \left(y \leq 1.12 \cdot 10^{-51}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -6.6000000000000005e-11 or 1.11999999999999998e-51 < y Initial program 76.8%
Taylor expanded in x around 0 34.5%
associate-/l*53.5%
associate-/r/58.3%
Applied egg-rr58.3%
if -6.6000000000000005e-11 < y < 1.11999999999999998e-51Initial program 99.9%
Taylor expanded in y around 0 75.9%
Final simplification66.7%
(FPCore (x y z) :precision binary64 (if (<= y -2.8e-15) y (if (<= y 4.8e-49) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e-15) {
tmp = y;
} else if (y <= 4.8e-49) {
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 <= (-2.8d-15)) then
tmp = y
else if (y <= 4.8d-49) 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 <= -2.8e-15) {
tmp = y;
} else if (y <= 4.8e-49) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.8e-15: tmp = y elif y <= 4.8e-49: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.8e-15) tmp = y; elseif (y <= 4.8e-49) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.8e-15) tmp = y; elseif (y <= 4.8e-49) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.8e-15], y, If[LessEqual[y, 4.8e-49], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-15}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-49}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.80000000000000014e-15 or 4.79999999999999985e-49 < y Initial program 77.1%
Taylor expanded in x around 0 53.5%
if -2.80000000000000014e-15 < y < 4.79999999999999985e-49Initial program 99.9%
Taylor expanded in y around 0 76.4%
Final simplification64.3%
(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 -inf 97.0%
mul-1-neg97.0%
unsub-neg97.0%
associate-/l*97.4%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 79.2%
mul-1-neg79.2%
distribute-frac-neg79.2%
Simplified79.2%
Taylor expanded in y around 0 79.2%
+-commutative79.2%
Simplified79.2%
Final simplification79.2%
(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 40.1%
Final simplification40.1%
(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 2023310
(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))