
(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 89.0%
Taylor expanded in x around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
associate-/l*98.1%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.5e-10) (not (<= x 1.5e+124))) (* (/ x z) (- 1.0 y)) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.5e-10) || !(x <= 1.5e+124)) {
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 <= (-8.5d-10)) .or. (.not. (x <= 1.5d+124))) 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 <= -8.5e-10) || !(x <= 1.5e+124)) {
tmp = (x / z) * (1.0 - y);
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.5e-10) or not (x <= 1.5e+124): tmp = (x / z) * (1.0 - y) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.5e-10) || !(x <= 1.5e+124)) 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 <= -8.5e-10) || ~((x <= 1.5e+124))) tmp = (x / z) * (1.0 - y); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.5e-10], N[Not[LessEqual[x, 1.5e+124]], $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 -8.5 \cdot 10^{-10} \lor \neg \left(x \leq 1.5 \cdot 10^{+124}\right):\\
\;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if x < -8.4999999999999996e-10 or 1.5e124 < x Initial program 89.3%
Taylor expanded in x around inf 83.8%
associate-/l*89.5%
associate-/r/89.5%
mul-1-neg89.5%
unsub-neg89.5%
Simplified89.5%
if -8.4999999999999996e-10 < x < 1.5e124Initial program 88.7%
Taylor expanded in x around -inf 98.6%
mul-1-neg98.6%
unsub-neg98.6%
associate-/l*96.6%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 88.5%
mul-1-neg88.5%
distribute-frac-neg88.5%
Simplified88.5%
div-inv88.4%
cancel-sign-sub88.4%
div-inv88.5%
+-commutative88.5%
Applied egg-rr88.5%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (/ y (/ z (- z x))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.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 <= (-1.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 <= -1.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 <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \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 < -1 or 1 < y Initial program 78.7%
Taylor expanded in y around inf 78.2%
associate-/l*99.4%
Simplified99.4%
if -1 < 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 98.2%
mul-1-neg98.2%
distribute-frac-neg98.2%
Simplified98.2%
div-inv97.9%
cancel-sign-sub97.9%
div-inv98.2%
+-commutative98.2%
Applied egg-rr98.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y -116.0) y (if (<= y 2.6e-64) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -116.0) {
tmp = y;
} else if (y <= 2.6e-64) {
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 <= (-116.0d0)) then
tmp = y
else if (y <= 2.6d-64) 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 <= -116.0) {
tmp = y;
} else if (y <= 2.6e-64) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -116.0: tmp = y elif y <= 2.6e-64: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -116.0) tmp = y; elseif (y <= 2.6e-64) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -116.0) tmp = y; elseif (y <= 2.6e-64) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -116.0], y, If[LessEqual[y, 2.6e-64], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -116:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-64}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -116 or 2.6e-64 < y Initial program 79.9%
Taylor expanded in x around 0 52.4%
if -116 < y < 2.6e-64Initial program 99.9%
Taylor expanded in y around 0 79.3%
Final simplification64.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.9e+62) (+ y (/ x z)) (* y (- (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.9e+62) {
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 <= 1.9d+62) 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 <= 1.9e+62) {
tmp = y + (x / z);
} else {
tmp = y * -(x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.9e+62: tmp = y + (x / z) else: tmp = y * -(x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.9e+62) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(-Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.9e+62) tmp = y + (x / z); else tmp = y * -(x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.9e+62], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * (-N[(x / z), $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{+62}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-\frac{x}{z}\right)\\
\end{array}
\end{array}
if y < 1.89999999999999992e62Initial program 90.4%
Taylor expanded in x around -inf 96.8%
mul-1-neg96.8%
unsub-neg96.8%
associate-/l*98.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
mul-1-neg86.0%
distribute-frac-neg86.0%
Simplified86.0%
div-inv85.8%
cancel-sign-sub85.8%
div-inv86.0%
+-commutative86.0%
Applied egg-rr86.0%
if 1.89999999999999992e62 < y Initial program 82.9%
Taylor expanded in x around inf 60.1%
associate-/l*62.9%
associate-/r/64.0%
mul-1-neg64.0%
unsub-neg64.0%
Simplified64.0%
Taylor expanded in y around inf 60.1%
mul-1-neg60.1%
associate-*l/64.0%
distribute-rgt-neg-out64.0%
Simplified64.0%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (<= y 8.2e+62) (+ y (/ x z)) (/ y (/ (- z) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= 8.2e+62) {
tmp = y + (x / z);
} else {
tmp = y / (-z / x);
}
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 <= 8.2d+62) then
tmp = y + (x / z)
else
tmp = y / (-z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 8.2e+62) {
tmp = y + (x / z);
} else {
tmp = y / (-z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 8.2e+62: tmp = y + (x / z) else: tmp = y / (-z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 8.2e+62) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y / Float64(Float64(-z) / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 8.2e+62) tmp = y + (x / z); else tmp = y / (-z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 8.2e+62], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / N[((-z) / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.2 \cdot 10^{+62}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{-z}{x}}\\
\end{array}
\end{array}
if y < 8.19999999999999967e62Initial program 90.4%
Taylor expanded in x around -inf 96.8%
mul-1-neg96.8%
unsub-neg96.8%
associate-/l*98.0%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
mul-1-neg86.0%
distribute-frac-neg86.0%
Simplified86.0%
div-inv85.8%
cancel-sign-sub85.8%
div-inv86.0%
+-commutative86.0%
Applied egg-rr86.0%
if 8.19999999999999967e62 < y Initial program 82.9%
Taylor expanded in y around inf 82.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in z around 0 64.1%
associate-*r/64.1%
neg-mul-164.1%
Simplified64.1%
Final simplification81.8%
(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.0%
Taylor expanded in x around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
associate-/l*98.1%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 76.5%
mul-1-neg76.5%
distribute-frac-neg76.5%
Simplified76.5%
div-inv76.4%
cancel-sign-sub76.4%
div-inv76.5%
+-commutative76.5%
Applied egg-rr76.5%
Final simplification76.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 89.0%
Taylor expanded in x around 0 37.7%
Final simplification37.7%
(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 2024020
(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))