
(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*97.8%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e+188) (and (not (<= x -5.8e+139)) (<= x 5e+252))) (+ y (/ x z)) (/ (- x) (/ z y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+188) || (!(x <= -5.8e+139) && (x <= 5e+252))) {
tmp = y + (x / z);
} 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 <= (-1.65d+188)) .or. (.not. (x <= (-5.8d+139))) .and. (x <= 5d+252)) then
tmp = y + (x / z)
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 <= -1.65e+188) || (!(x <= -5.8e+139) && (x <= 5e+252))) {
tmp = y + (x / z);
} else {
tmp = -x / (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e+188) or (not (x <= -5.8e+139) and (x <= 5e+252)): tmp = y + (x / z) else: tmp = -x / (z / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e+188) || (!(x <= -5.8e+139) && (x <= 5e+252))) tmp = Float64(y + Float64(x / z)); else tmp = Float64(Float64(-x) / Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.65e+188) || (~((x <= -5.8e+139)) && (x <= 5e+252))) tmp = y + (x / z); else tmp = -x / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e+188], And[N[Not[LessEqual[x, -5.8e+139]], $MachinePrecision], LessEqual[x, 5e+252]]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[((-x) / N[(z / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+188} \lor \neg \left(x \leq -5.8 \cdot 10^{+139}\right) \land x \leq 5 \cdot 10^{+252}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{\frac{z}{y}}\\
\end{array}
\end{array}
if x < -1.64999999999999991e188 or -5.7999999999999998e139 < x < 4.9999999999999997e252Initial program 90.0%
Taylor expanded in x around -inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
associate-/l*97.5%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 81.7%
mul-1-neg81.7%
distribute-neg-frac81.7%
Simplified81.7%
Taylor expanded in y around 0 81.7%
+-commutative81.7%
Simplified81.7%
if -1.64999999999999991e188 < x < -5.7999999999999998e139 or 4.9999999999999997e252 < x Initial program 78.4%
Taylor expanded in y around inf 74.1%
associate-/l*95.7%
associate-/r/95.5%
Simplified95.5%
Taylor expanded in z around 0 74.0%
mul-1-neg74.0%
associate-/l*85.6%
Simplified85.6%
Final simplification82.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ y (/ x z))))
(if (<= x -1.25e+188)
t_0
(if (<= x -1.06e+140)
(/ (- x) (/ z y))
(if (<= x 5e+246) t_0 (* x (/ (- y) z)))))))
double code(double x, double y, double z) {
double t_0 = y + (x / z);
double tmp;
if (x <= -1.25e+188) {
tmp = t_0;
} else if (x <= -1.06e+140) {
tmp = -x / (z / y);
} else if (x <= 5e+246) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y + (x / z)
if (x <= (-1.25d+188)) then
tmp = t_0
else if (x <= (-1.06d+140)) then
tmp = -x / (z / y)
else if (x <= 5d+246) then
tmp = t_0
else
tmp = x * (-y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y + (x / z);
double tmp;
if (x <= -1.25e+188) {
tmp = t_0;
} else if (x <= -1.06e+140) {
tmp = -x / (z / y);
} else if (x <= 5e+246) {
tmp = t_0;
} else {
tmp = x * (-y / z);
}
return tmp;
}
def code(x, y, z): t_0 = y + (x / z) tmp = 0 if x <= -1.25e+188: tmp = t_0 elif x <= -1.06e+140: tmp = -x / (z / y) elif x <= 5e+246: tmp = t_0 else: tmp = x * (-y / z) return tmp
function code(x, y, z) t_0 = Float64(y + Float64(x / z)) tmp = 0.0 if (x <= -1.25e+188) tmp = t_0; elseif (x <= -1.06e+140) tmp = Float64(Float64(-x) / Float64(z / y)); elseif (x <= 5e+246) tmp = t_0; else tmp = Float64(x * Float64(Float64(-y) / z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y + (x / z); tmp = 0.0; if (x <= -1.25e+188) tmp = t_0; elseif (x <= -1.06e+140) tmp = -x / (z / y); elseif (x <= 5e+246) tmp = t_0; else tmp = x * (-y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.25e+188], t$95$0, If[LessEqual[x, -1.06e+140], N[((-x) / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5e+246], t$95$0, N[(x * N[((-y) / z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y + \frac{x}{z}\\
\mathbf{if}\;x \leq -1.25 \cdot 10^{+188}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.06 \cdot 10^{+140}:\\
\;\;\;\;\frac{-x}{\frac{z}{y}}\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+246}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\
\end{array}
\end{array}
if x < -1.25e188 or -1.0600000000000001e140 < x < 4.99999999999999976e246Initial program 90.0%
Taylor expanded in x around -inf 97.1%
mul-1-neg97.1%
unsub-neg97.1%
associate-/l*97.5%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 81.7%
mul-1-neg81.7%
distribute-neg-frac81.7%
Simplified81.7%
Taylor expanded in y around 0 81.7%
+-commutative81.7%
Simplified81.7%
if -1.25e188 < x < -1.0600000000000001e140Initial program 81.3%
Taylor expanded in y around inf 81.3%
associate-/l*100.0%
associate-/r/99.8%
Simplified99.8%
Taylor expanded in z around 0 81.6%
mul-1-neg81.6%
associate-/l*90.6%
Simplified90.6%
if 4.99999999999999976e246 < x Initial program 76.0%
Taylor expanded in y around inf 68.1%
associate-/l*92.0%
associate-/r/91.9%
Simplified91.9%
Taylor expanded in z around 0 67.8%
mul-1-neg67.8%
associate-*r/81.5%
distribute-rgt-neg-in81.5%
distribute-neg-frac81.5%
Simplified81.5%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.7e-8))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 2.7e-8)) {
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 <= (-1.0d0)) .or. (.not. (y <= 2.7d-8))) 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 <= -1.0) || !(y <= 2.7e-8)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 2.7e-8): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.7e-8)) 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 <= -1.0) || ~((y <= 2.7e-8))) tmp = y * (1.0 - (x / z)); else tmp = y + (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 2.7e-8]], $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 -1 \lor \neg \left(y \leq 2.7 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 2.70000000000000002e-8 < y Initial program 78.2%
Taylor expanded in x around -inf 91.8%
mul-1-neg91.8%
unsub-neg91.8%
associate-/l*95.6%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 99.1%
if -1 < y < 2.70000000000000002e-8Initial program 100.0%
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.8%
mul-1-neg99.8%
distribute-neg-frac99.8%
Simplified99.8%
Taylor expanded in y around 0 99.8%
+-commutative99.8%
Simplified99.8%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (/ y (/ z (- z x))) (if (<= y 2.7e-8) (+ y (/ x z)) (* y (- 1.0 (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y / (z / (z - x));
} else if (y <= 2.7e-8) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (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)) then
tmp = y / (z / (z - x))
else if (y <= 2.7d-8) then
tmp = y + (x / z)
else
tmp = y * (1.0d0 - (x / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y / (z / (z - x));
} else if (y <= 2.7e-8) {
tmp = y + (x / z);
} else {
tmp = y * (1.0 - (x / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = y / (z / (z - x)) elif y <= 2.7e-8: tmp = y + (x / z) else: tmp = y * (1.0 - (x / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(y / Float64(z / Float64(z - x))); elseif (y <= 2.7e-8) tmp = Float64(y + Float64(x / z)); else tmp = Float64(y * Float64(1.0 - Float64(x / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = y / (z / (z - x)); elseif (y <= 2.7e-8) tmp = y + (x / z); else tmp = y * (1.0 - (x / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.7e-8], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-8}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\end{array}
\end{array}
if y < -1Initial program 77.3%
Taylor expanded in y around inf 76.4%
associate-/l*98.9%
Simplified98.9%
if -1 < y < 2.70000000000000002e-8Initial program 100.0%
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.8%
mul-1-neg99.8%
distribute-neg-frac99.8%
Simplified99.8%
Taylor expanded in y around 0 99.8%
+-commutative99.8%
Simplified99.8%
if 2.70000000000000002e-8 < y Initial program 79.5%
Taylor expanded in x around -inf 90.6%
mul-1-neg90.6%
unsub-neg90.6%
associate-/l*96.3%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.6%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e-28) y (if (<= z 7.8e-63) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e-28) {
tmp = y;
} else if (z <= 7.8e-63) {
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 <= (-2.7d-28)) then
tmp = y
else if (z <= 7.8d-63) 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 <= -2.7e-28) {
tmp = y;
} else if (z <= 7.8e-63) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e-28: tmp = y elif z <= 7.8e-63: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e-28) tmp = y; elseif (z <= 7.8e-63) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e-28) tmp = y; elseif (z <= 7.8e-63) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e-28], y, If[LessEqual[z, 7.8e-63], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{-28}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{-63}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if z < -2.6999999999999999e-28 or 7.80000000000000044e-63 < z Initial program 81.6%
Taylor expanded in x around 0 61.8%
if -2.6999999999999999e-28 < z < 7.80000000000000044e-63Initial program 99.9%
Taylor expanded in y around 0 59.4%
Final simplification60.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*97.8%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 77.3%
mul-1-neg77.3%
distribute-neg-frac77.3%
Simplified77.3%
Taylor expanded in y around 0 77.3%
+-commutative77.3%
Simplified77.3%
Final simplification77.3%
(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 40.7%
Final simplification40.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 2024019
(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))