
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+285) (* x z) (if (or (<= x -3e-39) (not (<= x 5.4e-66))) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+285) {
tmp = x * z;
} else if ((x <= -3e-39) || !(x <= 5.4e-66)) {
tmp = x * y;
} else {
tmp = -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 <= (-4.2d+285)) then
tmp = x * z
else if ((x <= (-3d-39)) .or. (.not. (x <= 5.4d-66))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+285) {
tmp = x * z;
} else if ((x <= -3e-39) || !(x <= 5.4e-66)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.2e+285: tmp = x * z elif (x <= -3e-39) or not (x <= 5.4e-66): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+285) tmp = Float64(x * z); elseif ((x <= -3e-39) || !(x <= 5.4e-66)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.2e+285) tmp = x * z; elseif ((x <= -3e-39) || ~((x <= 5.4e-66))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+285], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -3e-39], N[Not[LessEqual[x, 5.4e-66]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+285}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3 \cdot 10^{-39} \lor \neg \left(x \leq 5.4 \cdot 10^{-66}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.2e285Initial program 71.2%
*-commutative71.2%
sub-neg71.2%
distribute-rgt-in71.2%
metadata-eval71.2%
neg-mul-171.2%
associate-+r+71.2%
unsub-neg71.2%
+-commutative71.2%
distribute-lft-out99.8%
Simplified99.8%
Taylor expanded in y around 0 80.4%
Taylor expanded in x around inf 80.4%
*-commutative80.4%
Simplified80.4%
if -4.2e285 < x < -3.00000000000000028e-39 or 5.39999999999999992e-66 < x Initial program 97.9%
Taylor expanded in y around inf 63.6%
if -3.00000000000000028e-39 < x < 5.39999999999999992e-66Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e-53) (not (<= x 5.3e-23))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-53) || !(x <= 5.3e-23)) {
tmp = x * (z + y);
} else {
tmp = -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 <= (-6.8d-53)) .or. (.not. (x <= 5.3d-23))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-53) || !(x <= 5.3e-23)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e-53) or not (x <= 5.3e-23): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e-53) || !(x <= 5.3e-23)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e-53) || ~((x <= 5.3e-23))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e-53], N[Not[LessEqual[x, 5.3e-23]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-53} \lor \neg \left(x \leq 5.3 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.8e-53 or 5.30000000000000042e-23 < x Initial program 96.5%
Taylor expanded in x around inf 93.5%
+-commutative93.5%
Simplified93.5%
if -6.8e-53 < x < 5.30000000000000042e-23Initial program 100.0%
Taylor expanded in x around 0 75.4%
neg-mul-175.4%
Simplified75.4%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e-5) (not (<= x 1.1e-12))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-5) || !(x <= 1.1e-12)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-1.5d-5)) .or. (.not. (x <= 1.1d-12))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e-5) || !(x <= 1.1e-12)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e-5) or not (x <= 1.1e-12): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e-5) || !(x <= 1.1e-12)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e-5) || ~((x <= 1.1e-12))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e-5], N[Not[LessEqual[x, 1.1e-12]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-5} \lor \neg \left(x \leq 1.1 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -1.50000000000000004e-5 or 1.09999999999999996e-12 < x Initial program 96.1%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -1.50000000000000004e-5 < x < 1.09999999999999996e-12Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0036) (not (<= x 2.8e-9))) (* x (+ z y)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0036) || !(x <= 2.8e-9)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - 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 <= (-0.0036d0)) .or. (.not. (x <= 2.8d-9))) then
tmp = x * (z + y)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0036) || !(x <= 2.8e-9)) {
tmp = x * (z + y);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0036) or not (x <= 2.8e-9): tmp = x * (z + y) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0036) || !(x <= 2.8e-9)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.0036) || ~((x <= 2.8e-9))) tmp = x * (z + y); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0036], N[Not[LessEqual[x, 2.8e-9]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0036 \lor \neg \left(x \leq 2.8 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if x < -0.0035999999999999999 or 2.79999999999999984e-9 < x Initial program 96.1%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -0.0035999999999999999 < x < 2.79999999999999984e-9Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 72.9%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -26000.0) (not (<= x 0.00046))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -26000.0) || !(x <= 0.00046)) {
tmp = x * (z + y);
} 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) :: tmp
if ((x <= (-26000.0d0)) .or. (.not. (x <= 0.00046d0))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -26000.0) || !(x <= 0.00046)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -26000.0) or not (x <= 0.00046): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -26000.0) || !(x <= 0.00046)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -26000.0) || ~((x <= 0.00046))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -26000.0], N[Not[LessEqual[x, 0.00046]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -26000 \lor \neg \left(x \leq 0.00046\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -26000 or 4.6000000000000001e-4 < x Initial program 96.0%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -26000 < x < 4.6000000000000001e-4Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 94.8%
associate-/l*88.9%
Simplified88.9%
Taylor expanded in z around 0 98.9%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-39) (not (<= x 2.3e-63))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-39) || !(x <= 2.3e-63)) {
tmp = x * y;
} else {
tmp = -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 <= (-4.8d-39)) .or. (.not. (x <= 2.3d-63))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-39) || !(x <= 2.3e-63)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-39) or not (x <= 2.3e-63): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-39) || !(x <= 2.3e-63)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e-39) || ~((x <= 2.3e-63))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-39], N[Not[LessEqual[x, 2.3e-63]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-39} \lor \neg \left(x \leq 2.3 \cdot 10^{-63}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.80000000000000031e-39 or 2.3e-63 < x Initial program 96.6%
Taylor expanded in y around inf 61.4%
if -4.80000000000000031e-39 < x < 2.3e-63Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification37.4%
herbie shell --seed 2024053
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))