
(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 (if (or (<= z -4.2e+78) (not (<= z 1.12e-9))) (+ y (/ x z)) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+78) || !(z <= 1.12e-9)) {
tmp = y + (x / z);
} else {
tmp = (x + (y * (z - 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 ((z <= (-4.2d+78)) .or. (.not. (z <= 1.12d-9))) then
tmp = y + (x / z)
else
tmp = (x + (y * (z - x))) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e+78) || !(z <= 1.12e-9)) {
tmp = y + (x / z);
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e+78) or not (z <= 1.12e-9): tmp = y + (x / z) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e+78) || !(z <= 1.12e-9)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.2e+78) || ~((z <= 1.12e-9))) tmp = y + (x / z); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e+78], N[Not[LessEqual[z, 1.12e-9]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+78} \lor \neg \left(z \leq 1.12 \cdot 10^{-9}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -4.2000000000000002e78 or 1.12000000000000006e-9 < z Initial program 70.4%
Taylor expanded in z around inf 68.7%
Taylor expanded in x around 0 95.1%
if -4.2000000000000002e78 < z < 1.12000000000000006e-9Initial program 99.3%
Final simplification97.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* y (- z x)) z)))
(if (<= y -14500000000.0)
t_0
(if (<= y 1.0) (+ y (/ x z)) (if (<= y 2.8e+117) t_0 (- y (/ x z)))))))
double code(double x, double y, double z) {
double t_0 = (y * (z - x)) / z;
double tmp;
if (y <= -14500000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = y + (x / z);
} else if (y <= 2.8e+117) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (y * (z - x)) / z
if (y <= (-14500000000.0d0)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = y + (x / z)
else if (y <= 2.8d+117) then
tmp = t_0
else
tmp = y - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * (z - x)) / z;
double tmp;
if (y <= -14500000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = y + (x / z);
} else if (y <= 2.8e+117) {
tmp = t_0;
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): t_0 = (y * (z - x)) / z tmp = 0 if y <= -14500000000.0: tmp = t_0 elif y <= 1.0: tmp = y + (x / z) elif y <= 2.8e+117: tmp = t_0 else: tmp = y - (x / z) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * Float64(z - x)) / z) tmp = 0.0 if (y <= -14500000000.0) tmp = t_0; elseif (y <= 1.0) tmp = Float64(y + Float64(x / z)); elseif (y <= 2.8e+117) tmp = t_0; else tmp = Float64(y - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * (z - x)) / z; tmp = 0.0; if (y <= -14500000000.0) tmp = t_0; elseif (y <= 1.0) tmp = y + (x / z); elseif (y <= 2.8e+117) tmp = t_0; else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -14500000000.0], t$95$0, If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e+117], t$95$0, N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y \cdot \left(z - x\right)}{z}\\
\mathbf{if}\;y \leq -14500000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.45e10 or 1 < y < 2.79999999999999997e117Initial program 78.2%
Taylor expanded in y around inf 78.2%
if -1.45e10 < y < 1Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 100.0%
if 2.79999999999999997e117 < y Initial program 55.9%
Taylor expanded in z around inf 30.2%
Taylor expanded in x around 0 72.0%
add-sqr-sqrt45.3%
sqrt-unprod71.8%
sqr-neg71.8%
sqrt-unprod32.1%
add-sqr-sqrt85.5%
distribute-frac-neg85.5%
sub-neg85.5%
Applied egg-rr85.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-5) (not (<= z 8e-10))) (+ y (/ x z)) (* x (/ (- 1.0 y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-5) || !(z <= 8e-10)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - 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) :: tmp
if ((z <= (-8.5d-5)) .or. (.not. (z <= 8d-10))) then
tmp = y + (x / z)
else
tmp = x * ((1.0d0 - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-5) || !(z <= 8e-10)) {
tmp = y + (x / z);
} else {
tmp = x * ((1.0 - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-5) or not (z <= 8e-10): tmp = y + (x / z) else: tmp = x * ((1.0 - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-5) || !(z <= 8e-10)) tmp = Float64(y + Float64(x / z)); else tmp = Float64(x * Float64(Float64(1.0 - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-5) || ~((z <= 8e-10))) tmp = y + (x / z); else tmp = x * ((1.0 - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-5], N[Not[LessEqual[z, 8e-10]], $MachinePrecision]], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-5} \lor \neg \left(z \leq 8 \cdot 10^{-10}\right):\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1 - y}{z}\\
\end{array}
\end{array}
if z < -8.500000000000001e-5 or 8.00000000000000029e-10 < z Initial program 72.6%
Taylor expanded in z around inf 68.9%
Taylor expanded in x around 0 92.7%
if -8.500000000000001e-5 < z < 8.00000000000000029e-10Initial program 99.9%
Taylor expanded in x around inf 87.0%
associate-/l*84.8%
mul-1-neg84.8%
unsub-neg84.8%
Simplified84.8%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (<= y -2.75e-38) (* z (/ y z)) (if (<= y 7.8e-42) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.75e-38) {
tmp = z * (y / z);
} else if (y <= 7.8e-42) {
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.75d-38)) then
tmp = z * (y / z)
else if (y <= 7.8d-42) 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.75e-38) {
tmp = z * (y / z);
} else if (y <= 7.8e-42) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.75e-38: tmp = z * (y / z) elif y <= 7.8e-42: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.75e-38) tmp = Float64(z * Float64(y / z)); elseif (y <= 7.8e-42) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.75e-38) tmp = z * (y / z); elseif (y <= 7.8e-42) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.75e-38], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.8e-42], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.75 \cdot 10^{-38}:\\
\;\;\;\;z \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-42}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.75000000000000003e-38Initial program 77.4%
Taylor expanded in z around inf 51.2%
Taylor expanded in x around 0 37.4%
*-commutative37.4%
associate-/l*57.2%
Applied egg-rr57.2%
if -2.75000000000000003e-38 < y < 7.8000000000000003e-42Initial program 99.9%
Taylor expanded in y around 0 78.0%
if 7.8000000000000003e-42 < y Initial program 71.6%
Taylor expanded in x around 0 57.8%
(FPCore (x y z) :precision binary64 (if (<= y -2.6e-38) y (if (<= y 1.65e-42) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e-38) {
tmp = y;
} else if (y <= 1.65e-42) {
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.6d-38)) then
tmp = y
else if (y <= 1.65d-42) 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.6e-38) {
tmp = y;
} else if (y <= 1.65e-42) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.6e-38: tmp = y elif y <= 1.65e-42: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.6e-38) tmp = y; elseif (y <= 1.65e-42) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.6e-38) tmp = y; elseif (y <= 1.65e-42) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.6e-38], y, If[LessEqual[y, 1.65e-42], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-38}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-42}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.60000000000000011e-38 or 1.6500000000000001e-42 < y Initial program 75.0%
Taylor expanded in x around 0 56.4%
if -2.60000000000000011e-38 < y < 1.6500000000000001e-42Initial program 99.9%
Taylor expanded in y around 0 78.0%
(FPCore (x y z) :precision binary64 (if (<= y 2.75e-11) (+ y (/ x z)) (- y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.75e-11) {
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 <= 2.75d-11) 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 <= 2.75e-11) {
tmp = y + (x / z);
} else {
tmp = y - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.75e-11: tmp = y + (x / z) else: tmp = y - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.75e-11) tmp = Float64(y + 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 <= 2.75e-11) tmp = y + (x / z); else tmp = y - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.75e-11], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.75 \cdot 10^{-11}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z}\\
\end{array}
\end{array}
if y < 2.74999999999999987e-11Initial program 90.6%
Taylor expanded in z around inf 79.8%
Taylor expanded in x around 0 87.3%
if 2.74999999999999987e-11 < y Initial program 69.5%
Taylor expanded in z around inf 28.8%
Taylor expanded in x around 0 57.7%
add-sqr-sqrt35.6%
sqrt-unprod63.0%
sqr-neg63.0%
sqrt-unprod29.8%
add-sqr-sqrt78.6%
distribute-frac-neg78.6%
sub-neg78.6%
Applied egg-rr78.6%
(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 86.1%
Taylor expanded in z around inf 68.8%
Taylor expanded in x around 0 80.9%
(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 86.1%
Taylor expanded in x around 0 41.9%
(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 2024146
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))
(/ (+ x (* y (- z x))) z))