
(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 6 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 88.3%
Taylor expanded in x around -inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
associate-/l*94.5%
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 (/ y z))))
(if (<= y -0.19)
t_0
(if (<= y 1.7e-118)
(/ x z)
(if (<= y 3.8e-96) y (if (<= y 1.7e-22) (/ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * (y / z);
double tmp;
if (y <= -0.19) {
tmp = t_0;
} else if (y <= 1.7e-118) {
tmp = x / z;
} else if (y <= 3.8e-96) {
tmp = y;
} else if (y <= 1.7e-22) {
tmp = x / z;
} 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) :: tmp
t_0 = z * (y / z)
if (y <= (-0.19d0)) then
tmp = t_0
else if (y <= 1.7d-118) then
tmp = x / z
else if (y <= 3.8d-96) then
tmp = y
else if (y <= 1.7d-22) then
tmp = x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y / z);
double tmp;
if (y <= -0.19) {
tmp = t_0;
} else if (y <= 1.7e-118) {
tmp = x / z;
} else if (y <= 3.8e-96) {
tmp = y;
} else if (y <= 1.7e-22) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y / z) tmp = 0 if y <= -0.19: tmp = t_0 elif y <= 1.7e-118: tmp = x / z elif y <= 3.8e-96: tmp = y elif y <= 1.7e-22: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y / z)) tmp = 0.0 if (y <= -0.19) tmp = t_0; elseif (y <= 1.7e-118) tmp = Float64(x / z); elseif (y <= 3.8e-96) tmp = y; elseif (y <= 1.7e-22) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y / z); tmp = 0.0; if (y <= -0.19) tmp = t_0; elseif (y <= 1.7e-118) tmp = x / z; elseif (y <= 3.8e-96) tmp = y; elseif (y <= 1.7e-22) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.19], t$95$0, If[LessEqual[y, 1.7e-118], N[(x / z), $MachinePrecision], If[LessEqual[y, 3.8e-96], y, If[LessEqual[y, 1.7e-22], N[(x / z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -0.19:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-118}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-96}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-22}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -0.19 or 1.6999999999999999e-22 < y Initial program 77.5%
Taylor expanded in x around 0 32.0%
associate-/l*50.6%
associate-/r/56.6%
Applied egg-rr56.6%
if -0.19 < y < 1.69999999999999995e-118 or 3.8000000000000001e-96 < y < 1.6999999999999999e-22Initial program 99.9%
Taylor expanded in y around 0 81.0%
if 1.69999999999999995e-118 < y < 3.8000000000000001e-96Initial program 99.6%
Taylor expanded in x around 0 77.3%
Final simplification68.2%
(FPCore (x y z)
:precision binary64
(if (<= y -8.2e-48)
y
(if (or (<= y 1.7e-118) (and (not (<= y 3.65e-96)) (<= y 2.2e-22)))
(/ x z)
y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.2e-48) {
tmp = y;
} else if ((y <= 1.7e-118) || (!(y <= 3.65e-96) && (y <= 2.2e-22))) {
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 <= (-8.2d-48)) then
tmp = y
else if ((y <= 1.7d-118) .or. (.not. (y <= 3.65d-96)) .and. (y <= 2.2d-22)) 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 <= -8.2e-48) {
tmp = y;
} else if ((y <= 1.7e-118) || (!(y <= 3.65e-96) && (y <= 2.2e-22))) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.2e-48: tmp = y elif (y <= 1.7e-118) or (not (y <= 3.65e-96) and (y <= 2.2e-22)): tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.2e-48) tmp = y; elseif ((y <= 1.7e-118) || (!(y <= 3.65e-96) && (y <= 2.2e-22))) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.2e-48) tmp = y; elseif ((y <= 1.7e-118) || (~((y <= 3.65e-96)) && (y <= 2.2e-22))) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.2e-48], y, If[Or[LessEqual[y, 1.7e-118], And[N[Not[LessEqual[y, 3.65e-96]], $MachinePrecision], LessEqual[y, 2.2e-22]]], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{-48}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-118} \lor \neg \left(y \leq 3.65 \cdot 10^{-96}\right) \land y \leq 2.2 \cdot 10^{-22}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -8.20000000000000028e-48 or 1.69999999999999995e-118 < y < 3.64999999999999997e-96 or 2.2000000000000001e-22 < y Initial program 80.9%
Taylor expanded in x around 0 52.4%
if -8.20000000000000028e-48 < y < 1.69999999999999995e-118 or 3.64999999999999997e-96 < y < 2.2000000000000001e-22Initial program 100.0%
Taylor expanded in y around 0 87.0%
Final simplification65.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e+24) (not (<= y 3.2e-6))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e+24) || !(y <= 3.2e-6)) {
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.35d+24)) .or. (.not. (y <= 3.2d-6))) 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.35e+24) || !(y <= 3.2e-6)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = y + (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e+24) or not (y <= 3.2e-6): tmp = y * (1.0 - (x / z)) else: tmp = y + (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e+24) || !(y <= 3.2e-6)) 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.35e+24) || ~((y <= 3.2e-6))) 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.35e+24], N[Not[LessEqual[y, 3.2e-6]], $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.35 \cdot 10^{+24} \lor \neg \left(y \leq 3.2 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.35e24 or 3.1999999999999999e-6 < y Initial program 76.3%
Taylor expanded in x around -inf 92.4%
mul-1-neg92.4%
unsub-neg92.4%
associate-/l*88.8%
associate-/r/99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around inf 99.9%
if -1.35e24 < y < 3.1999999999999999e-6Initial 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%
*-commutative100.0%
clear-num99.7%
un-div-inv99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 98.4%
associate-*r/98.4%
neg-mul-198.4%
Simplified98.4%
Taylor expanded in y around 0 98.4%
+-commutative98.4%
Simplified98.4%
Final simplification99.1%
(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.3%
Taylor expanded in x around -inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
associate-/l*94.5%
associate-/r/100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
*-commutative100.0%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 76.5%
associate-*r/76.5%
neg-mul-176.5%
Simplified76.5%
Taylor expanded in y around 0 76.5%
+-commutative76.5%
Simplified76.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 88.3%
Taylor expanded in x around 0 38.2%
Final simplification38.2%
(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 2024024
(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))