
(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 -2e-27) (not (<= z 1.15e-141))) (+ (/ x z) (* y (- 1.0 (/ x z)))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-27) || !(z <= 1.15e-141)) {
tmp = (x / z) + (y * (1.0 - (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 <= (-2d-27)) .or. (.not. (z <= 1.15d-141))) then
tmp = (x / z) + (y * (1.0d0 - (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 <= -2e-27) || !(z <= 1.15e-141)) {
tmp = (x / z) + (y * (1.0 - (x / z)));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e-27) or not (z <= 1.15e-141): tmp = (x / z) + (y * (1.0 - (x / z))) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e-27) || !(z <= 1.15e-141)) tmp = Float64(Float64(x / z) + Float64(y * Float64(1.0 - 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 <= -2e-27) || ~((z <= 1.15e-141))) tmp = (x / z) + (y * (1.0 - (x / z))); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e-27], N[Not[LessEqual[z, 1.15e-141]], $MachinePrecision]], N[(N[(x / z), $MachinePrecision] + N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $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 -2 \cdot 10^{-27} \lor \neg \left(z \leq 1.15 \cdot 10^{-141}\right):\\
\;\;\;\;\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if z < -2.0000000000000001e-27 or 1.14999999999999997e-141 < z Initial program 79.0%
Taylor expanded in y around 0 100.0%
if -2.0000000000000001e-27 < z < 1.14999999999999997e-141Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -380000000.0) (not (<= y 12.0))) (* y (- 1.0 (/ x z))) (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -380000000.0) || !(y <= 12.0)) {
tmp = y * (1.0 - (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 ((y <= (-380000000.0d0)) .or. (.not. (y <= 12.0d0))) then
tmp = y * (1.0d0 - (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 ((y <= -380000000.0) || !(y <= 12.0)) {
tmp = y * (1.0 - (x / z));
} else {
tmp = (x + (y * (z - x))) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -380000000.0) or not (y <= 12.0): tmp = y * (1.0 - (x / z)) else: tmp = (x + (y * (z - x))) / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -380000000.0) || !(y <= 12.0)) tmp = Float64(y * Float64(1.0 - 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 ((y <= -380000000.0) || ~((y <= 12.0))) tmp = y * (1.0 - (x / z)); else tmp = (x + (y * (z - x))) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -380000000.0], N[Not[LessEqual[y, 12.0]], $MachinePrecision]], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -380000000 \lor \neg \left(y \leq 12\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\end{array}
\end{array}
if y < -3.8e8 or 12 < y Initial program 72.9%
Taylor expanded in y around 0 95.3%
Taylor expanded in y around inf 99.4%
if -3.8e8 < y < 12Initial program 99.9%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- 1.0 (/ x z))) (+ y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): 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 <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;y + \frac{x}{z}\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 73.3%
Taylor expanded in y around 0 95.3%
Taylor expanded in y around inf 98.5%
if -1 < y < 1Initial program 99.9%
Taylor expanded in y around 0 92.1%
Taylor expanded in x around 0 99.0%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e-45) y (if (<= y 0.00034) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-45) {
tmp = y;
} else if (y <= 0.00034) {
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 <= (-5.2d-45)) then
tmp = y
else if (y <= 0.00034d0) 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 <= -5.2e-45) {
tmp = y;
} else if (y <= 0.00034) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e-45: tmp = y elif y <= 0.00034: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-45) tmp = y; elseif (y <= 0.00034) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e-45) tmp = y; elseif (y <= 0.00034) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-45], y, If[LessEqual[y, 0.00034], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-45}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 0.00034:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.19999999999999973e-45 or 3.4e-4 < y Initial program 74.4%
Taylor expanded in x around 0 56.3%
if -5.19999999999999973e-45 < y < 3.4e-4Initial program 99.9%
Taylor expanded in y around 0 82.7%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (<= x 1.9e+269) (+ y (/ x z)) (* y (/ (- x) z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.9e+269) {
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 (x <= 1.9d+269) 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 (x <= 1.9e+269) {
tmp = y + (x / z);
} else {
tmp = y * (-x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.9e+269: tmp = y + (x / z) else: tmp = y * (-x / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.9e+269) 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 (x <= 1.9e+269) tmp = y + (x / z); else tmp = y * (-x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.9e+269], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y * N[((-x) / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9 \cdot 10^{+269}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{-x}{z}\\
\end{array}
\end{array}
if x < 1.89999999999999991e269Initial program 86.5%
Taylor expanded in y around 0 94.2%
Taylor expanded in x around 0 83.2%
if 1.89999999999999991e269 < x Initial program 84.5%
Taylor expanded in y around 0 83.3%
Taylor expanded in y around inf 87.2%
Taylor expanded in x around inf 68.2%
associate-*r/68.2%
associate-*r*68.2%
neg-mul-168.2%
associate-*l/87.2%
*-commutative87.2%
Simplified87.2%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (<= x 1.95e+269) (+ y (/ x z)) (/ y (/ (- z) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.95e+269) {
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 (x <= 1.95d+269) 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 (x <= 1.95e+269) {
tmp = y + (x / z);
} else {
tmp = y / (-z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.95e+269: tmp = y + (x / z) else: tmp = y / (-z / x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.95e+269) 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 (x <= 1.95e+269) tmp = y + (x / z); else tmp = y / (-z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.95e+269], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / N[((-z) / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.95 \cdot 10^{+269}:\\
\;\;\;\;y + \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{-z}{x}}\\
\end{array}
\end{array}
if x < 1.9499999999999999e269Initial program 86.5%
Taylor expanded in y around 0 94.2%
Taylor expanded in x around 0 83.2%
if 1.9499999999999999e269 < x Initial program 84.5%
Taylor expanded in y around inf 68.2%
associate-*l/79.3%
Simplified79.3%
associate-*l/68.2%
associate-/l*87.3%
Applied egg-rr87.3%
Taylor expanded in z around 0 87.3%
associate-*r/87.3%
neg-mul-187.3%
Simplified87.3%
Final simplification83.4%
(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.4%
Taylor expanded in y around 0 93.7%
Taylor expanded in x around 0 81.0%
Final simplification81.0%
(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.4%
Taylor expanded in x around 0 38.6%
Final simplification38.6%
(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 2024018
(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))